feat: add dump functionality

This commit is contained in:
0x330a 2022-12-05 11:52:32 +11:00
parent 188e7b5ec0
commit 2daf231e59
No known key found for this signature in database
GPG Key ID: 267811D6E6A2698C
3 changed files with 23 additions and 0 deletions

View File

@ -89,7 +89,21 @@ class InstrumentedTests {
assertEquals(1, newSeqNo)
assertArrayEquals(expectedPush1, newToPush)
// We haven't dumped, so still need to dump:
assertTrue(userProfile.needsDump())
// We did call push but we haven't confirmed it as stored yet, so this will still return true:
assertTrue(userProfile.needsPush())
val dump = userProfile.dump()
// (in a real client we'd now store this to disk)
assertFalse(userProfile.needsDump())
val expectedDump = ("d" +
"1:!i2e" +
"1:$").encodeToByteArray() + expectedPush1.size.toString().encodeToByteArray() +
":".encodeToByteArray() + expectedPush1 +
"e".encodeToByteArray()
assertArrayEquals(expectedDump, dump)
userProfile.free()
}

View File

@ -137,4 +137,12 @@ Java_network_loki_messenger_libsession_1util_UserProfile_setPic(JNIEnv *env, job
auto* pic_string = new std::string(pic_chars);
profile->set_profile_pic(*pic_string, key_str);
}
extern "C"
JNIEXPORT jbyteArray JNICALL
Java_network_loki_messenger_libsession_1util_ConfigBase_dump(JNIEnv *env, jobject thiz) {
auto config = ptrToConfigBase(env, thiz);
std::string dumped = config->dump();
jbyteArray bytes = bytes_from_string(env, dumped);
return bytes;
}

View File

@ -13,6 +13,7 @@ sealed class ConfigBase(protected val /* yucky */ pointer: Long) {
external fun needsPush(): Boolean
external fun needsDump(): Boolean
external fun push(): ConfigWithSeqNo
external fun dump(): ByteArray
}
class UserProfile(pointer: Long): ConfigBase(pointer) {