[ENet-discuss] ENet Util?
Brian Hook
enet-discuss@cubik.org
Sun, 9 Mar 2003 12:18:16 -0800
Just a thought here, but it might be nice to have an ENet utility
library that is separate from (and even downloaded separately) from
ENet that provides stuff that is often considered application level
yet which is common enough that code can be reused.
Generic delta compression is an obvious candidate. Encryption is
less of a candidate because of the rather extensive design choices
necessary (asymmetric vs. symmetric, key exchange, key size, etc.).
I think big one though is serialization to byte streams which would
automatically handle endianess and alignment. This includes
serialization of 16-bit, 32-bit and float quantities, along with
strings. I think the API would be something like:
ENetuStream *enetu_stream_create( void *, size_t );
void enetu_stream_destroy( ENetuStream * );
void enetu_stream_rewind( ENetuStream * );
void * enetu_stream_get_raw( ENetuStream *, size_t );
float enetu_stream_get_float( ENetuStream * );
double enetu_stream_get_double( ENetuSTream * );
enet_uint8 enetu_stream_get8( ENetuStream * );
enet_uin16 enetu_stream_get16( ENetuStream * );
enet_uint32 enetu_stream_get32( ENetuStream * );
//Also assume serialization versions of the above
Then when you need to dump a bunch of stuff into a packet, you can
simply do:
ENetuStream *s = enetu_stream_create( NULL, 12 );
enetu_stream_write_float( s, 1.0f );
enetu_stream_write_float( s, 0.0f );
enetu_stream_write_float( s, 0.0f );
p = enet_packet_create( s->data, s->size, 0 );
And deserialization would work in reverse, where the stream is
created with the packet's data.
Brian