Common Socket Question - Migrating C ++ Structures from Java to C ++

I have a general socket programming question for you.

I have a C structure called Data:

struct data {
      double speed;
      double length; 
      char carName[32];
      struct Attribs;
}

struct Attribs {
      int color;
}

I would like to be able to create a similar structure in Java, create a socket, create a data packet with the above structure and send it to the C ++ socket listener.

What can you tell me about the presence of serialized data (basically 1 and 0, which are transmitted in a packet). How does C ++ read these packages and recreate the structure? How are such structures stored in a package?

As a rule, all you can tell me is give me ideas on how to solve such a question.

Thank!

+4
source share
2
  • , . Sun JVM - Big Endian, Intel x86, .
  • Java ByteBuffer . ByteBuffers NIO, , , , "DataInput/OutputStreams".
  • ! , .
  • ++, , - . , :

size_t amount_read = 0;
data my_data;
memcpy(buffer+amount_read, &my_data.speed, sizeof(my_data.speed))
amount_read += sizeof(my_data.speed)
memcpy(buffer+amount_read, &my_data.length, sizeof(my_data.length))
amount_read += sizeof(my_data.length)
+3

:

  • java java, XML
  • java XML- ++
  • ++ XML java
  • ++ XML-
0

Source: https://habr.com/ru/post/1758291/


All Articles