Skip to content

Commit c9ebbaa

Browse files
Merge commit 'refs/pull/169/head' of github.com:intel/tinycbor into dev
Signed-off-by: Thiago Macieira <[email protected]>
2 parents 10f7399 + 0db7e22 commit c9ebbaa

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/cbor.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,8 @@ CBOR_API const char *cbor_error_string(CborError error);
208208
typedef enum CborEncoderAppendType
209209
{
210210
CborEncoderAppendCborData = 0,
211-
CborEncoderAppendStringData = 1
211+
CborEncoderAppendStringData = 1,
212+
CborEncoderApendRawData = 2
212213
} CborEncoderAppendType;
213214

214215
typedef CborError (*CborEncoderWriteFunction)(void *, const void *, size_t, CborEncoderAppendType);
@@ -247,6 +248,7 @@ CBOR_INLINE_API CborError cbor_encode_text_stringz(CborEncoder *encoder, const c
247248
{ return cbor_encode_text_string(encoder, string, strlen(string)); }
248249
CBOR_API CborError cbor_encode_byte_string(CborEncoder *encoder, const uint8_t *string, size_t length);
249250
CBOR_API CborError cbor_encode_floating_point(CborEncoder *encoder, CborType fpType, const void *value);
251+
CBOR_API CborError cbor_encode_raw(CborEncoder *encoder, const uint8_t *raw, size_t length);
250252

251253
CBOR_INLINE_API CborError cbor_encode_boolean(CborEncoder *encoder, bool value)
252254
{ 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
@@ -472,6 +472,20 @@ CborError cbor_encode_byte_string(CborEncoder *encoder, const uint8_t *string, s
472472
return encode_string(encoder, length, ByteStringType << MajorTypeShift, string);
473473
}
474474

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

0 commit comments

Comments
 (0)