Nestring lib
Netstring lib
A netstring lib in C which can be used to encode/decode (serializer/deserialize) properties and/or metadata for remote service data and events for the - yet to be implemented - event admin.
Background
In computer programming, a netstring is a formatting method for byte strings that uses a declarative notation to indicate the size of the string.[1][2]
Netstrings store the byte length of the data that follows, making it easier to unambiguously pass text and byte data between programs that could be sensitive to values that could be interpreted as delimiters or terminators (such as a null character).
The format consists of the string's length written using ASCII digits, followed by a colon, the byte data, and a comma. "Length" in this context means "number of 8-bit units", so if the string is, for example, encoded using UTF-8, this may or may not be identical to the number of textual characters that are present in the string.
Source: https://en.wikipedia.org/wiki/Netstring
Implementation hints
Use the implementation in https://github.com/apache/celix/blob/master/bundles/pubsub/pubsub_protocol/pubsub_protocol_lib/src/pubsub_wire_protocol_common.c (pubsubProtocol_addNetstringEntryToBuffer and pubsubProtocol_parseNetstring) as a basis for the netstring lib.
Place the implementation in libs/netstring and ensure that the lib file name is celix_netstring and the lib name is netstring with a Celix::netstring alias. The lib should depend on Celix::utils and use the celix_err implementation to report error messages (https://github.com/apache/celix/blob/master/libs/utils/include/celix_err.h).
The celix_status_t should be extended with a netstring facility and CELIX_ERROR_MAKE using celix_errno.h (https://github.com/apache/celix/blob/rel/celix-2.3.0/libs/utils/include/celix_errno.h)
A possible api could be:
//celix_netstring.h
#define CELIX_FACILITY_NETSTRING 3 //maybe add to celix_errno.h
#define CELIX_NETSTRING_ERROR_TOO_LONG CELIX_ERROR_MAKE(CELIX_FACILITY_NETSTRING, 1)
#define CELIX_NETSTRING_ERROR_NO_COLON CELIX_ERROR_MAKE(CELIX_FACILITY_NETSTRING, 2)
//rest of netstring error codes
celix_status_t celix_netstring_encode(const char* string, FILE* netstringOutput);
celix_status_t celix_netstring_decode(FILE* netstringInput, char** stringResult);
About event-admin, I would like to update the current status:
Zhenbao Xu is busying working on porting RSA/PSA to a closed source web server due to civetweb's lack of reverse proxy support: https://github.com/civetweb/civetweb/issues/1131 Once the job is done, he will come back to us. I'm pretty sure he will be happy to help review any PR related to netstring and event admin.
Place the implementation in libs/netstring and ensure that the lib file name is celix_netstring and the lib name is netstring with a Celix::netstring alias. The lib should depend on Celix::utils and use the celix_err implementation to report error messages
@pnoltes As described in #674, properties will support netstring encoding, which will cause a mutual dependency between Celix:utils and Celix:netstring. To solve this problem, we may need to place netstring in Celix:utils; or we can separate celix_err and celix_errno into the library Celix:err, then Celix:utils and Celix:netstring depend on Celix:err. Do you have any other views?
To solve this problem, we may need to place netstring in Celix:utils; or we can separate celix_err and celix_errno into the library Celix:err, then Celix:utils and Celix:netstring depend on Celix:err.
Or a standalone netstring lib which does not depend on Celix:utils? It seems that we can reuse existing errno to report error, logging is not really needed. Customized FILE * may also help netstring mux/demux.