Skip to content

Commit 087d213

Browse files
TSononosjlongland
authored andcommitted
Added the method cbor_encode_raw to the API
This method allows for writing raw data directly to the encoding buffer. This can be useful if you have something stored as CBOR encoded data. Fixes #162. Signed-off-by: Tofik Sonono <[email protected]>
1 parent 26c63e3 commit 087d213

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/cbor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ CBOR_INLINE_API CborError cbor_encode_text_stringz(CborEncoder *encoder, const c
251251
{ return cbor_encode_text_string(encoder, string, strlen(string)); }
252252
CBOR_API CborError cbor_encode_byte_string(CborEncoder *encoder, const uint8_t *string, size_t length);
253253
CBOR_API CborError cbor_encode_floating_point(CborEncoder *encoder, CborType fpType, const void *value);
254+
CBOR_API CborError cbor_encode_raw(CborEncoder *encoder, const uint8_t *raw, size_t length);
254255

255256
CBOR_INLINE_API CborError cbor_encode_boolean(CborEncoder *encoder, bool value)
256257
{ return cbor_encode_simple_value(encoder, (int)value - 1 + (CborBooleanType & 0x1f)); }

src/cborencoder.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,20 @@ CborError cbor_encode_byte_string(CborEncoder *encoder, const uint8_t *string, s
473473
return encode_string(encoder, length, ByteStringType << MajorTypeShift, string);
474474
}
475475

476+
/**
477+
* Puts the data of length \a length in \a raw into to the encoding buffer of \a
478+
* encoder. This function can be used if you have stored CBOR encoded data and
479+
* want to push it to your current encoding buffer. Be aware, you are
480+
* responsible for the data in \a raw is valid and that the validity of the
481+
* resulting stream after this operation remains valid.
482+
*
483+
* \sa CborError cbor_encode_byte_string
484+
*/
485+
CborError cbor_encode_raw(CborEncoder *encoder, const uint8_t *raw, size_t length)
486+
{
487+
return append_to_buffer(encoder, raw, length);
488+
}
489+
476490
/**
477491
* Appends the text string \a string of length \a length to the CBOR stream
478492
* provided by \a encoder. CBOR requires that \a string be valid UTF-8, but

0 commit comments

Comments
 (0)