I want to transmit data over the network, but I don't want to use any foreign libraries (Standard C/C++ is ok).
for example:
unsigned int x = 123;
char y[3] = {'h', 'i', '\0'};
float z = 1.23f;
I want this in an
char xyz[11];
array.
Note: To transmit it over network, I need Network Byte order for the unsigned int (htonl function), then I need to somehow serialize the float to be in IEEE 754 form (theres many functions on the internet), and I know it.
How do I get them into the the xyz-Array, nicely lined up end to end, so I can use this as a buffer for my socket + send() function? Obviously I have reverse functions (ntohl, and a reverse IEEE 754) to get them out but I need a technique there too, preferably the same...
It would be something like this:
xyz in binary: 00000000 0000000 00000000 01111011 | 01101000 | 01101001 | 00000000 | 00111111 10011101 01110000 10100100 - big endian repr. of u. int 123 - | - 'h' - | - 'i' - | - '\0' - | - IEEE 754 repr of float 1.23 -
How can I accomplish this without external libraries and minimal use of standard library functions? This isn't so much for my program as for me to learn from.