Skip to content

Commit 0db7e22

Browse files
author
TSonono
committed
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 755f9ef commit 0db7e22

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
@@ -227,6 +227,7 @@ CBOR_INLINE_API CborError cbor_encode_text_stringz(CborEncoder *encoder, const c
227227
{ return cbor_encode_text_string(encoder, string, strlen(string)); }
228228
CBOR_API CborError cbor_encode_byte_string(CborEncoder *encoder, const uint8_t *string, size_t length);
229229
CBOR_API CborError cbor_encode_floating_point(CborEncoder *encoder, CborType fpType, const void *value);
230+
CBOR_API CborError cbor_encode_raw(CborEncoder *encoder, const uint8_t *raw, size_t length);
230231

231232
CBOR_INLINE_API CborError cbor_encode_boolean(CborEncoder *encoder, bool value)
232233
{ 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
@@ -444,6 +444,20 @@ CborError cbor_encode_byte_string(CborEncoder *encoder, const uint8_t *string, s
444444
return encode_string(encoder, length, ByteStringType << MajorTypeShift, string);
445445
}
446446

447+
/**
448+
* Puts the data of length \a length in \a raw into to the encoding buffer of \a
449+
* encoder. This function can be used if you have stored CBOR encoded data and
450+
* want to push it to your current encoding buffer. Be aware, you are
451+
* responsible for the data in \a raw is valid and that the validity of the
452+
* resulting stream after this operation remains valid.
453+
*
454+
* \sa CborError cbor_encode_byte_string
455+
*/
456+
CborError cbor_encode_raw(CborEncoder *encoder, const uint8_t *raw, size_t length)
457+
{
458+
return append_to_buffer(encoder, raw, length);
459+
}
460+
447461
/**
448462
* Appends the byte string \a string of length \a length to the CBOR stream
449463
* provided by \a encoder. CBOR byte strings are arbitrary raw data.

0 commit comments

Comments
 (0)