JNI returns one of the complex objects. jni returns

Source: Internet
Author: User

JNI returns one of the complex objects. jni returns
Requirements:

First of all, I need to take over a project recently. I want to parse binary data at the underlying layer. The data structure is quite responsible. Because the server is a c ++ server, and I didn't take mobile development into account at the beginning, so the protocol is a bit bullshit! In general, a data packet contains a vector in the map and is serialized into a binary value! Ios makes it better. object-citself supports c ++ and can be encapsulated in a simple way. android is a little troublesome. You need to convert the data into a java data format. The problem is that, the data interfaces of c ++ are generally as follows:

Std: map <std: string, std: vector <struct info> tmep;

Problem:

I want to convert it into a java data object. I searched the internet. Without such information, some of them are basically some simple objects that are not so complicated and I can't do it myself, my approach is as follows:

Declare an object class in java as follows:

public class ControlDictionaryValue {public String value;}

Public class LoginMsg extends BaseMsg {// dictionary list public HashMap <String, ArrayList <ControlDictionaryValue> controlDictionary ;}

Return this object through jni. The jni code is as follows:

JNIEXPORT jobject JNICALL annotation (JNIEnv * env, jclass tis) {jclass identifier = env-> FindClass ("hzcw/msgdata/LoginMsg"); jmethodID identifier = env-> GetMethodID (identifier, "<init>", "() V"); jobject identifier = env-> NewObject (m_login_msg, identifier); jfieldID m_fid_controlDictionary = env-> GetFieldID (m_login_msg, "controlDictionary ", "Ljava/util/HashMap;"); // a new hashmap object jclass class_hashmap = env-> FindClass ("java/util/HashMap "); jmethodID struct = env-> GetMethodID (class_hashmap, "<init>", "() V"); jobject obj_hashmap = env-> NewObject (class_hashmap, hashmap_construct_method ,""); jmethodID hashmap_put_method = env-> GetMethodID (class_hashmap, "put", "(Ljava/lang/Object;) Ljava/lang/Object ;"); // a new ArrayList object jclass class_arraylist = env-> FindClass ("java/util/ArrayList"); jmethodID arraylist_construct_method = env-> GetMethodID (class_arraylist, "<init> ", "() V"); jobject obj_arraylist = env-> NewObject (class_arraylist, rule, ""); jmethodID arraylist_add_method = env-> GetMethodID (class_arraylist, "add ", "(Ljava/lang/Object;) Z"); // new A ControlDictionaryValue Object jclass m_cls_ControlDictionaryValue = env-> FindClass ("hzcw/datastruct/ControlDictionaryValue "); jmethodID response = env-> GetMethodID (response, "<init>", "() V"); jobject response = env-> NewObject (m_cls_ControlDictionaryValue, m_mid_ControlDictionaryValue ,""); // get the value variable jfieldID struct = env-> GetFieldID (m_cls_ControlDictionaryValue, "value", "Ljava/lang/String;") of the ControlDictionaryValue object; env-> SetObjectField (struct, examples, env-> NewStringUTF (""); env-> CallBooleanMethod (obj_arraylist, arraylist_add_method, callback); env-> CallObjectMethod (obj_hashmap, hashmap_put_method, env-> NewStringUTF (char *) "Department"), obj_arraylist); env-> SetObjectField (m_login_msg_obj, m_fid_controlDictionary, obj_hashmap); env-> DeleteLocalRef (callback ); // Delete the partial reference env-> DeleteLocalRef (obj_arraylist); // Delete the partial reference env-> DeleteLocalRef (obj_hashmap); // Delete the partial reference return m_login_msg_obj ;}
The above is the fake data, the real data is filled by yourself, and you can understand it at a glance!


C # socket programming transmits complex objects, such as passing a form object

I want to know what is the purpose of uploading the entire form object by the landlord?

1. You can upload parameters of some form objects (such as the size, position, and background color of the form), and then recreate the form based on these parameters on the client,

2. If you have to upload the entire form, inherit the form, serialize it into a string, and then upload it,

How does jni pass an object pointer on the C side to the Java side?

When int or Long is used to pass the pointer value, it is not a pointer object.
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.