From: Ahmet Artu Yildirim Date: Sun, 23 Apr 2023 06:02:40 +0000 (-0700) Subject: Update README file X-Git-Url: https://artulab.com/gitweb/?a=commitdiff_plain;h=21bfb180b1d97929ac2343949cfd3818d3c76d51;p=libprogbuf Update README file --- diff --git a/ChangeLog b/ChangeLog index 509a4aa..41846f8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ +- (2023-04-22) Update README file - (2022-12-25) Generate pkg-config file - (2022-12-24) Add a script to generate a ChangeLog file - (2022-12-23) Add getter and setter to support nested message diff --git a/README b/README index e69de29..5b250d6 100644 --- a/README +++ b/README @@ -0,0 +1,58 @@ +C library to serialize versioned structured data, performing fast variable-length encoding for integers to reduce message size. + +Examples ================================================ + +=== Serialize a message with payload containing an integer, an unsigned long long, a float, an integer array and a string with message tag 1 into a buffer === + +// create a message buffer with tag 1 + +int message_tag = 1; +progbuf_h buf = progbuf_alloc (message_tag); + +// serialize a long value + +long long_val = 10; +int ret = progbuf_set_long (buf, long_val); +assert (ret == PROGBUF_SUCCESS); + +// serialize an unsigned long long value + +unsigned long long ulonglong_val = 0xFFFFFFFFFFFFFFFF; +ret = progbuf_set_ulonglong (buf, ulonglong_val); +assert (ret == PROGBUF_SUCCESS); + +// serialize a float value + +float float_val = 1.123; +ret = progbuf_set_float (buf, float_val); +assert (ret == PROGBUF_SUCCESS); + +// serialize an integer array + +const int intarr_val[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; +const size_t intarr_size = sizeof (intarr_val) / sizeof (int); +ret = progbuf_set_int_array (buf, intarr_val, intarr_size); +assert (ret == PROGBUF_SUCCESS); + +// serialize a string + +const char *string_val = "abcdefghij"; +ret = progbuf_set_string (buf, string_val); +assert (ret == PROGBUF_SUCCESS); + +// get message size and buffer to send over network + +size_t message_size; +void *message_buffer; +ret = progbuf_own_buffer(buf, &message_buffer, &message_size); +assert (ret == PROGBUF_SUCCESS); + +// free the memory + +ret = progbuf_free (buf); +assert (ret == PROGBUF_SUCCESS); + +======================================================== + +See check_progbuf.c file for more code samples. +