For example, in C and C ++, I pass a buffer, this buffer was built from a structure. And for example, I get this buffer over the network, impose a pointer to the structure and get the data structure.

struct i { int i; char s; }; struct i *i = &buf[0]; printf ( "%d\n", i->i ); 

What is the alternative in java? I looked a bit in the book and found that I could parlize an object, but I found only a file. The documentation did not find information about a function like this putObject () , which could buffer into a buffer for transmission over the network. And somewhere else I read that the serialization is wanted or removed already in new versions of java. In general, I do not understand how you can process data over the network in java, it's some kind of nightmare if there are no pointers. With pointers, I could do so.

 struct number { int n; }; struct ver { int n; int v; }; struct her { int n; short v; }; struct number *n = &buf[0]; switch ( n->n ) { case 0: struct ver *v = &buf[0]; printf ( "%d\n", v->v ); break; case 1: struct her *h = &buf[0]; printf ( "%d\n", h->v ); break; } 

}

  • there is always jni. There are pointers and cookies. - KoVadim
  • I will soon have a book on jni, but I don’t think that you can pass a class or structure through jni. Most likely through jni, you can pass either a string or a number, and this is not that. It is necessary to transfer the data set. - xverizex
  • @xverizex pass the serialized byte array. - Peter Samokhin

1 answer 1

Possible solutions:

  1. Declare two methods Serialize / Deserialize and manually do everything for each field
  2. Write a universal serializer / deserializer and process all fields through reflection
  3. Use one of the libraries for serialization / deserialization. For example gson
  4. Use one of the libraries to transfer objects over the network. For example apache thrift
  • Can I have some code examples, how is this done? - xverizex