It is, in fact, part of the ENet API:

ENET_API void * enet_range_coder_create (void);
ENET_API void   enet_range_coder_destroy (void *);
ENET_API size_t enet_range_coder_compress (void *, const ENetBuffer *, size_t, size_t, enet_uint8 *, size_t); ENET_API size_t enet_range_coder_decompress (void *, const enet_uint8 *, size_t, enet_uint8 *, size_t);

enet_host_compress_with_range_coder() is just a convenience function to make it simpler to set up. These functions can just be called directly for usage outside of ENet.

Otherwise, you would have to fill out an ENetCompressor structure and then supply that to enet_host_compress():

/** An ENet packet compressor for compressing UDP packets before socket sends or receives.
*/
typedef struct _ENetCompressor
{
  /**< Context data for the compressor. Must be non-NULL. */
  void * context;
/**< Compresses from inBuffers[0..inBufferCount-1], containing inLimit bytes, to outData, outputting at most outLimit bytes. Should return 0 on failure. */ size_t (ENET_CALLBACK * compress) (void * context, const ENetBuffer * inBuffers, size_t inBufferCount, size_t inLimit, enet_uint8 * outData, size_t outLimit); /**< Decompresses from inData, containing inLimit bytes, to outData, outputting at most outLimit bytes. Should return 0 on failure. */ size_t (ENET_CALLBACK * decompress) (void * context, const enet_uint8 * inData, size_t inLimit, enet_uint8 * outData, size_t outLimit); /**< Destroys the context when compression is disabled or the host is destroyed. May be NULL. */
  void (ENET_CALLBACK * destroy) (void * context);
} ENetCompressor;

You call enet_range_coder_create() to get a context, then you can use enet_range_coder_compress() and enet_range_coder_decompress() to compress stuff. Destroy should be obvious.

Lee

Adam D. Moss wrote:
Lee Salzman wrote:
So, I was playing around with packet compression for Sauerbraten using an adaptive range compressor. It turned out that did not work out so well on Sauerbraten's data, because I had already so tightly quantized it that the gains were small. But since the packet compressor was still good on other data besides Sauerbraten's and was of higher quality than other similar performing range compressors I could find, I decided to keep it in ENet.

I must say, this is one of the simpler and most straightforward (which
means trustworthy, to me!) range coders I've seen, and being part of
ENet I trust its quality and license.
On the other hand, it seems so useful that I'd love to use it not just
in the context of ENet - any chance of fleshing-out the docs/commentary
of compress.c a bit?  I'm not asking for it to be exposed as an official
ENet API, just some good clues on re-using the compressor.
Thanks a lot!

_______________________________________________
ENet-discuss mailing list
[email protected]
http://lists.cubik.org/mailman/listinfo/enet-discuss

Reply via email to