feat: implement a ustring from jstring for utils

This commit is contained in:
0x330a 2023-08-24 18:18:31 +10:00
parent eb30d17a3d
commit 9bf20a18c4
No known key found for this signature in database
GPG key ID: 267811D6E6A2698C
3 changed files with 15 additions and 3 deletions

View file

@ -1,14 +1,16 @@
#include <jni.h>
#include "group_info.h"
#include "session/config/groups/info.hpp"
extern "C"
JNIEXPORT jobject JNICALL
Java_network_loki_messenger_libsession_1util_GroupInfoConfig_newInstance__Ljava_lang_String_2(
JNIEnv *env, jobject thiz, jstring pub_key_hex) {
auto pub_key = env->GetStringUTFChars(pub_key_hex, nullptr);
env->ReleaseStringUTFChars(pub_key_hex, pub_key);
std::lock_guard guard{util::util_mutex_};
auto pub_key_string = util::ustring_from_jstring(env, pub_key_hex);
auto group_info = session::config::groups::Info(pub_key_string, std::nullopt, std::nullopt);
// TODO
}
extern "C"

View file

@ -23,6 +23,15 @@ namespace util {
return st;
}
session::ustring ustring_from_jstring(JNIEnv* env, jstring string) {
size_t len = env->GetStringUTFLength(string);
auto chars = env->GetStringUTFChars(string, nullptr);
session::ustring st{reinterpret_cast<const unsigned char *>(chars), len};
env->ReleaseStringUTFChars(string, chars);
return st;
}
jobject serialize_user_pic(JNIEnv *env, session::config::profile_pic pic) {
jclass returnObjectClass = env->FindClass("network/loki/messenger/libsession_util/util/UserPic");
jmethodID constructor = env->GetMethodID(returnObjectClass, "<init>", "(Ljava/lang/String;[B)V");

View file

@ -13,6 +13,7 @@ namespace util {
extern std::mutex util_mutex_;
jbyteArray bytes_from_ustring(JNIEnv* env, session::ustring_view from_str);
session::ustring ustring_from_bytes(JNIEnv* env, jbyteArray byteArray);
session::ustring ustring_from_jstring(JNIEnv* env, jstring string);
jobject serialize_user_pic(JNIEnv *env, session::config::profile_pic pic);
std::pair<jstring, jbyteArray> deserialize_user_pic(JNIEnv *env, jobject user_pic);
jobject serialize_base_community(JNIEnv *env, const session::config::community& base_community);