From f5418fa6666fa2da8792b32ee6fe35f8b09bb860 Mon Sep 17 00:00:00 2001 From: Tobias Markmann Date: Thu, 6 Aug 2015 22:19:52 +0200 Subject: [PATCH] cbor: add API to encode non null-terminated byte strings --- sys/cbor/cbor.c | 5 +++++ sys/include/cbor.h | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/sys/cbor/cbor.c b/sys/cbor/cbor.c index 55c64b6f7..ae230fbff 100644 --- a/sys/cbor/cbor.c +++ b/sys/cbor/cbor.c @@ -576,6 +576,11 @@ size_t cbor_serialize_byte_string(cbor_stream_t *stream, const char *val) return encode_bytes(CBOR_BYTES, stream, val, strlen(val)); } +size_t cbor_serialize_byte_stringl(cbor_stream_t *stream, const char *val, size_t length) +{ + return encode_bytes(CBOR_BYTES, stream, val, length); +} + size_t cbor_deserialize_unicode_string(const cbor_stream_t *stream, size_t offset, char *val, size_t length) { diff --git a/sys/include/cbor.h b/sys/include/cbor.h index e3c35366e..7761ac1fd 100644 --- a/sys/include/cbor.h +++ b/sys/include/cbor.h @@ -370,6 +370,17 @@ size_t cbor_deserialize_double(const cbor_stream_t *stream, size_t offset, */ size_t cbor_serialize_byte_string(cbor_stream_t *stream, const char *val); +/** + * @brief Serializes an arbitrary byte string + * + * @param[out] stream The destination stream for serializing the byte stream + * @param[in] val The arbitrary byte string which may include null bytes + * @param[in] length The size of the byte string in bytes + * + * @return Number of bytes written to stream @p stream + */ +size_t cbor_serialize_byte_stringl(cbor_stream_t *stream, const char *val, size_t length); + /** * @brief Deserialize bytes from @p stream to @p val *