X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Finclude%2Futils%2Fproto.h;h=ab01cf5d1ed9cf53bf66fbbe8c29bf8003921631;hb=147e814d602f90e411a948613e85e627f5858018;hp=372e34d474b7be20dd5fc13ce6c04025748bc0a8;hpb=bf37a5afbf7364f853140c6859822ae52d2b61d8;p=sysdb.git diff --git a/src/include/utils/proto.h b/src/include/utils/proto.h index 372e34d..ab01cf5 100644 --- a/src/include/utils/proto.h +++ b/src/include/utils/proto.h @@ -28,7 +28,7 @@ #ifndef SDB_UTILS_PROTO_H #define SDB_UTILS_PROTO_H 1 -#include "utils/strbuf.h" +#include "core/data.h" #include #include @@ -37,15 +37,55 @@ extern "C" { #endif +/* + * sdb_proto_marshal: + * Encode the message into the wire format by adding an appropriate header. + * The encoded message is written to buf which has to be large enough to store + * the header (64 bits) and the entire message. + * + * Returns: + * - The number of bytes of the full encoded message on success. The function + * does not write more than 'buf_len' bytes. If the output was truncated + * then the return value is the number of bytes which would have been + * written if enough space had been available. + * - a negative value on error + */ ssize_t -sdb_proto_send(int fd, size_t msg_len, const char *msg); +sdb_proto_marshal(char *buf, size_t buf_len, uint32_t code, + uint32_t msg_len, const char *msg); +/* + * sdb_proto_marshal_data: + * Encode a datum into the wire format and write it to buf. + * + * Returns: + * - The number of bytes of the full encoded datum on success. The function + * does not write more than 'buf_len' bytes. If the output was truncated + * then the return value is the number of bytes which would have been + * written if enough space had been available. + * - a negative value else + */ ssize_t -sdb_proto_send_msg(int fd, uint32_t code, - uint32_t msg_len, const char *msg); +sdb_proto_marshal_data(char *buf, size_t buf_len, sdb_data_t *datum); +/* + * sdb_proto_unmarshal_header: + * Read and decode a message header from the specified string. + * + * Returns: + * - 0 on success + * - a negative value else + */ +int +sdb_proto_unmarshal_header(const char *buf, size_t buf_len, + uint32_t *code, uint32_t *msg_len); + +/* + * sdb_proto_unmarshal_int32: + * Read and decode a 32-bit integer from the specified string. + */ uint32_t -sdb_proto_get_int(sdb_strbuf_t *buf, size_t offset); +sdb_proto_unmarshal_int32(const char *buf, size_t buf_len); #ifdef __cplusplus } /* extern "C" */