apache-mynewt-bot removed a comment on issue #2200: cborencoder: Add functions calculating size of encoded data URL: https://github.com/apache/mynewt-core/pull/2200#issuecomment-589622694 <!-- style-bot --> ## Style check summary ### Our coding style is [here!](https://github.com/apache/mynewt-core/blob/master/CODING_STANDARDS.md) #### encoding/tinycbor/include/tinycbor/cbor.h <details> ```diff @@ -190,32 +190,59 @@ CBOR_API CborError cbor_encode_simple_value(CborEncoder *encoder, uint8_t value); CBOR_API CborError cbor_encode_tag(CborEncoder *encoder, CborTag tag); CBOR_API CborError cbor_encode_text_string(CborEncoder *encoder, const char *string, size_t length); -CBOR_INLINE_API CborError cbor_encode_text_stringz(CborEncoder *encoder, const char *string) -{ return cbor_encode_text_string(encoder, string, strlen(string)); } +CBOR_INLINE_API CborError +cbor_encode_text_stringz(CborEncoder *encoder, const char *string) +{ + return cbor_encode_text_string(encoder, string, strlen(string)); +} CBOR_API CborError cbor_encode_byte_string(CborEncoder *encoder, const uint8_t *string, size_t length); CBOR_API CborError cbor_encode_byte_iovec(CborEncoder *encoder, const struct cbor_iovec iov[], int iov_len); CBOR_API CborError cbor_encode_floating_point(CborEncoder *encoder, CborType fpType, const void *value); -CBOR_INLINE_API int cbor_encode_bytes_written(CborEncoder *encoder) -{ return encoder->writer->bytes_written; } -CBOR_INLINE_API CborError cbor_encode_boolean(CborEncoder *encoder, bool value) -{ return cbor_encode_simple_value(encoder, (int)value - 1 + (CborBooleanType & 0x1f)); } -CBOR_INLINE_API CborError cbor_encode_null(CborEncoder *encoder) -{ return cbor_encode_simple_value(encoder, CborNullType & 0x1f); } -CBOR_INLINE_API CborError cbor_encode_undefined(CborEncoder *encoder) -{ return cbor_encode_simple_value(encoder, CborUndefinedType & 0x1f); } +CBOR_INLINE_API int +cbor_encode_bytes_written(CborEncoder *encoder) +{ + return encoder->writer->bytes_written; +} +CBOR_INLINE_API CborError +cbor_encode_boolean(CborEncoder *encoder, bool value) +{ + return cbor_encode_simple_value(encoder, (int)value - 1 + (CborBooleanType & 0x1f)); +} +CBOR_INLINE_API CborError +cbor_encode_null(CborEncoder *encoder) +{ + return cbor_encode_simple_value(encoder, CborNullType & 0x1f); +} +CBOR_INLINE_API CborError +cbor_encode_undefined(CborEncoder *encoder) +{ + return cbor_encode_simple_value(encoder, CborUndefinedType & 0x1f); +} CBOR_API size_t cbor_encode_int_get_size(uint64_t ui); -CBOR_INLINE_API size_t cbor_encode_string_get_size(size_t s) -{ return cbor_encode_int_get_size(s) + s; } - -CBOR_INLINE_API CborError cbor_encode_half_float(CborEncoder *encoder, const void *value) -{ return cbor_encode_floating_point(encoder, CborHalfFloatType, value); } -CBOR_INLINE_API CborError cbor_encode_float(CborEncoder *encoder, float value) -{ return cbor_encode_floating_point(encoder, CborFloatType, &value); } -CBOR_INLINE_API CborError cbor_encode_double(CborEncoder *encoder, double value) -{ return cbor_encode_floating_point(encoder, CborDoubleType, &value); } +CBOR_INLINE_API size_t +cbor_encode_string_get_size(size_t s) +{ + return cbor_encode_int_get_size(s) + s; +} + +CBOR_INLINE_API CborError +cbor_encode_half_float(CborEncoder *encoder, const void *value) +{ + return cbor_encode_floating_point(encoder, CborHalfFloatType, value); +} +CBOR_INLINE_API CborError +cbor_encode_float(CborEncoder *encoder, float value) +{ + return cbor_encode_floating_point(encoder, CborFloatType, &value); +} +CBOR_INLINE_API CborError +cbor_encode_double(CborEncoder *encoder, double value) +{ + return cbor_encode_floating_point(encoder, CborDoubleType, &value); +} CBOR_API CborError cbor_encoder_create_array(CborEncoder *encoder, CborEncoder *arrayEncoder, size_t length); CBOR_API CborError cbor_encoder_create_map(CborEncoder *encoder, CborEncoder *mapEncoder, size_t length); ``` </details> #### encoding/tinycbor/src/cborencoder.c <details> ```diff @@ -391,24 +413,25 @@ * Returns size in bytes it will take to encode \a ui. * */ -size_t cbor_encode_int_get_size(uint64_t ui) -{ - size_t s = 1; - - if (ui >= Value8Bit) { - s += 1; - if (ui > 0xffU) { - s += 1; - } - if (ui > 0xffffU) { - s += 2; - } - if (ui > 0xffffffffU) { - s += 4; - } - } - - return s; +size_t +cbor_encode_int_get_size(uint64_t ui) +{ + size_t s = 1; + + if (ui >= Value8Bit) { + s += 1; + if (ui > 0xffU) { + s += 1; + } + if (ui > 0xffffU) { + s += 2; + } + if (ui > 0xffffffffU) { + s += 4; + } + } + + return s; } ``` </details>
---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services