Merge branch 'master' into dev

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Thiago Macieira
2018-02-05 18:11:54 -08:00
14 changed files with 112 additions and 98 deletions
+2 -2
View File
@@ -80,7 +80,7 @@
* \value CborArrayType Type is a CBOR array
* \value CborMapType Type is a CBOR map (an associative container with key and value pairs)
* \value CborTagType Type is a CBOR tag (a 64-bit integer describing the item that follows, see CborKnownTags)
* \value CborSimpleType Type is one of CBOR Simple Types
* \value CborSimpleType Type is one of the CBOR Simple Types
* \value CborBooleanType Type is a boolean (true or false)
* \value CborNullType Type encodes a null
* \value CborUndefinedType Type encodes an undefined value
@@ -105,7 +105,7 @@
* \value CborExpectedBase64urlTag Item is a CBOR byte string that is expected to be encoded as Base64Url
* \value CborExpectedBase64Tag Item is a CBOR byte string that is expected to be encoded as Base64
* \value CborExpectedBase16Tag Item is a CBOR byte string that is expected to be encoded as Base16 (also known as "hexdump")
* \value CborUriTag Item is a CBOR text string containing an URI (RFC 3986) or IRI (RFC 3987)
* \value CborUriTag Item is a CBOR text string containing a URI (RFC 3986) or IRI (RFC 3987)
* \value CborBase64urlTag Item is a CBOR text string that was encoded as Base64Url
* \value CborBase64Tag Item is a CBOR text string that was encoded as Base64
* \value CborRegularExpressionTag Item is a CBOR text string containing a regular expression
+4 -3
View File
@@ -162,7 +162,7 @@ typedef enum CborError {
CborErrorGarbageAtEnd = 256,
CborErrorUnexpectedEOF,
CborErrorUnexpectedBreak,
CborErrorUnknownType, /* can only heppen in major type 7 */
CborErrorUnknownType, /* can only happen in major type 7 */
CborErrorIllegalType, /* type not allowed here */
CborErrorIllegalNumber,
CborErrorIllegalSimpleType, /* types of value less than 32 encoded in two bytes */
@@ -579,13 +579,14 @@ enum CborPrettyFlags {
CborPrettyNumericEncodingIndicators = 0x01,
CborPrettyTextualEncodingIndicators = 0,
CborPrettyIndicateIndetermineLength = 0x02,
CborPrettyIndicateIndeterminateLength = 0x02,
CborPrettyIndicateIndetermineLength = CborPrettyIndicateIndeterminateLength, /* deprecated */
CborPrettyIndicateOverlongNumbers = 0x04,
CborPrettyShowStringFragments = 0x100,
CborPrettyMergeStringFragments = 0,
CborPrettyDefaultFlags = CborPrettyIndicateIndetermineLength
CborPrettyDefaultFlags = CborPrettyIndicateIndeterminateLength
};
typedef CborError (*CborStreamFunction)(void *token, const char *fmt, ...)
+8 -7
View File
@@ -83,7 +83,7 @@
* cbor_encoder_close_container(&encoder, &mapEncoder);
* \endcode
*
* <h3 class="groupheader">Error checking and buffer size</h2>
* <h3 class="groupheader">Error checking and buffer size</h3>
*
* All functions operating on CborEncoder return a condition of type CborError.
* If the encoding was successful, they return CborNoError. Some functions do
@@ -134,7 +134,7 @@
* return CborNoError;
* \endcode
*
* Finally, the example below illustrates expands on the one above and also
* Finally, the example below expands on the one above and also
* deals with dynamically growing the buffer if the initial allocation wasn't
* big enough. Note the two places where the error checking was replaced with
* an cbor_assertion, showing where the author assumes no error can occur.
@@ -332,7 +332,7 @@ CborError cbor_encode_uint(CborEncoder *encoder, uint64_t value)
* Appends the negative 64-bit integer whose absolute value is \a
* absolute_value to the CBOR stream provided by \a encoder.
*
* If the value \a absolute_value is zero, this function encodes -2^64 - 1.
* If the value \a absolute_value is zero, this function encodes -2^64.
*
* \sa cbor_encode_uint, cbor_encode_int
*/
@@ -507,13 +507,14 @@ CborError cbor_encoder_create_array(CborEncoder *encoder, CborEncoder *arrayEnco
* with the same \a encoder and \a mapEncoder parameters.
*
* The number of pair of items inserted into the map must be exactly \a length
* items, otherwise the stream is invalid. If the number of items is not known
* items, otherwise the stream is invalid. If the number is not known
* when creating the map, the constant \ref CborIndefiniteLength may be passed as
* length instead.
*
* \b{Implementation limitation:} TinyCBOR cannot encode more than SIZE_MAX/2
* key-value pairs in the stream. If the length \a length is larger than this
* value, this function returns error CborErrorDataTooLarge.
* value (and is not \ref CborIndefiniteLength), this function returns error
* CborErrorDataTooLarge.
*
* \sa cbor_encoder_create_array
*/
@@ -530,8 +531,8 @@ CborError cbor_encoder_create_map(CborEncoder *encoder, CborEncoder *mapEncoder,
* same as were passed to cbor_encoder_create_array() or
* cbor_encoder_create_map().
*
* Since version 0.5, this function verifies that the number of items (or pair
* of items, in the case of a map) was correct. It is no longer needed to call
* Since version 0.5, this function verifies that the number of items (or pairs
* of items, in the case of a map) was correct. It is no longer necessary to call
* cbor_encoder_close_container_checked() instead.
*
* \sa cbor_encoder_create_array(), cbor_encoder_create_map()
+17 -14
View File
@@ -61,7 +61,7 @@
* CborParser parser;
* CborValue value;
* int result;
* cbor_parser_init(buffer, len, 0, &buffer, &value);
* cbor_parser_init(buffer, len, 0, &parser, &value);
* cbor_value_get_int(&value, &result);
* return result;
* }
@@ -69,7 +69,7 @@
*
* The code above does no error checking, which means it assumes the data comes
* from a source trusted to send one properly-encoded integer. The following
* example does the exact same operation, but includes error parsing and
* example does the exact same operation, but includes error checking and
* returns 0 on parsing failure:
*
* \code
@@ -78,7 +78,7 @@
* CborParser parser;
* CborValue value;
* int result;
* if (cbor_parser_init(buffer, len, 0, &buffer, &value) != CborNoError)
* if (cbor_parser_init(buffer, len, 0, &parser, &value) != CborNoError)
* return 0;
* if (!cbor_value_is_integer(&value) ||
* cbor_value_get_int(&value, &result) != CborNoError)
@@ -461,7 +461,7 @@ CborError cbor_value_validate_basic(const CborValue *it)
* If the type is not of fixed size, this function has undefined behavior. Code
* must be sure that the current type is one of the fixed-size types before
* calling this function. This function is provided because it can guarantee
* that runs in constant time (O(1)).
* that it runs in constant time (O(1)).
*
* If the caller is not able to determine whether the type is fixed or not, code
* can use the cbor_value_advance() function instead.
@@ -746,7 +746,7 @@ CborError cbor_value_leave_container(CborValue *it, const CborValue *recursed)
*
* Note that this function does not do range-checking: integral values that do
* not fit in a variable of type \c{int} are silently truncated to fit. Use
* cbor_value_get_int_checked() that is not acceptable.
* cbor_value_get_int_checked() if that is not acceptable.
*
* \sa cbor_value_get_type(), cbor_value_is_valid(), cbor_value_is_integer()
*/
@@ -804,7 +804,7 @@ CborError cbor_value_leave_container(CborValue *it, const CborValue *recursed)
* behavior is undefined, so checking with \ref cbor_value_get_type or with
* \ref cbor_value_is_integer is recommended.
*
* Unlike cbor_value_get_int64(), this function performs a check to see if the
* Unlike \ref cbor_value_get_int64(), this function performs a check to see if the
* stored integer fits in \a result without data loss. If the number is outside
* the valid range for the data type, this function returns the recoverable
* error CborErrorDataTooLarge. In that case, use either
@@ -843,7 +843,7 @@ CborError cbor_value_get_int64_checked(const CborValue *value, int64_t *result)
* behavior is undefined, so checking with \ref cbor_value_get_type or with
* \ref cbor_value_is_integer is recommended.
*
* Unlike cbor_value_get_int(), this function performs a check to see if the
* Unlike \ref cbor_value_get_int(), this function performs a check to see if the
* stored integer fits in \a result without data loss. If the number is outside
* the valid range for the data type, this function returns the recoverable
* error CborErrorDataTooLarge. In that case, use one of the other integer
@@ -863,8 +863,8 @@ CborError cbor_value_get_int_checked(const CborValue *value, int *result)
*
* But we can convert from signed to unsigned without fault (paragraph 2).
*
* The range for int is implementation-defined and int is not guaranteed use
* two's complement representation (int32_t is).
* The range for int is implementation-defined and int is not guaranteed to use
* two's complement representation (although int32_t is).
*/
if (value->flags & CborIteratorFlag_NegativeInteger) {
@@ -1200,7 +1200,7 @@ static CborError iterate_string_chunks(const CborValue *value, char *buffer, siz
/**
* \fn CborError cbor_value_copy_text_string(const CborValue *value, char *buffer, size_t *buflen, CborValue *next)
*
* Copies the string pointed by \a value into the buffer provided at \a buffer
* Copies the string pointed to by \a value into the buffer provided at \a buffer
* of \a buflen bytes. If \a buffer is a NULL pointer, this function will not
* copy anything and will only update the \a next value.
*
@@ -1216,7 +1216,10 @@ static CborError iterate_string_chunks(const CborValue *value, char *buffer, siz
* On success, this function sets the number of bytes copied to \c{*buflen}. If
* the buffer is large enough, this function will insert a null byte after the
* last copied byte, to facilitate manipulation of text strings. That byte is
* not included in the returned value of \c{*buflen}.
* not included in the returned value of \c{*buflen}. If there was no space for
* the terminating null, no error is returned, so callers must check the value
* of *buflen after the call, before relying on the '\0'; if it has not been
* changed by the call, there is no '\0'-termination on the buffer's contents.
*
* The \a next pointer, if not null, will be updated to point to the next item
* after this string. If \a value points to the last item, then \a next will be
@@ -1273,12 +1276,12 @@ CborError _cbor_value_copy_string(const CborValue *value, void *buffer,
}
/**
* Compares the entry \a value with the string \a string and store the result
* Compares the entry \a value with the string \a string and stores the result
* in \a result. If the value is different from \a string \a result will
* contain \c false.
*
* The entry at \a value may be a tagged string. If \a is not a string or a
* tagged string, the comparison result will be false.
* The entry at \a value may be a tagged string. If \a value is not a string or
* a tagged string, the comparison result will be false.
*
* CBOR requires text strings to be encoded in UTF-8, but this function does
* not validate either the strings in the stream or the string \a string to be
+2 -2
View File
@@ -41,7 +41,7 @@
*
* Allocates memory for the string pointed by \a value and copies it into this
* buffer. The pointer to the buffer is stored in \a buffer and the number of
* bytes copied is stored in \a len (those variables must not be NULL).
* bytes copied is stored in \a buflen (those variables must not be NULL).
*
* If the iterator \a value does not point to a text string, the behaviour is
* undefined, so checking with \ref cbor_value_get_type or \ref
@@ -72,7 +72,7 @@
*
* Allocates memory for the string pointed by \a value and copies it into this
* buffer. The pointer to the buffer is stored in \a buffer and the number of
* bytes copied is stored in \a len (those variables must not be NULL).
* bytes copied is stored in \a buflen (those variables must not be NULL).
*
* If the iterator \a value does not point to a byte string, the behaviour is
* undefined, so checking with \ref cbor_value_get_type or \ref
+12 -11
View File
@@ -42,7 +42,7 @@
* \defgroup CborPretty Converting CBOR to text
* \brief Group of functions used to convert CBOR to text form.
*
* This group contains two functions that are can be used to convert one
* This group contains two functions that can be used to convert a \ref
* CborValue object to a text representation. This module attempts to follow
* the recommendations from RFC 7049 section 6 "Diagnostic Notation", though it
* has a few differences. They are noted below.
@@ -58,13 +58,13 @@
* error CborErrorIO.
*
* These functions also perform UTF-8 validation in CBOR text strings. If they
* encounter a sequence of bytes that not permitted in UTF-8, they will return
* encounter a sequence of bytes that is not permitted in UTF-8, they will return
* CborErrorInvalidUtf8TextString. That includes encoding of surrogate points
* in UTF-8.
*
* \warning The output type produced by these functions is not guaranteed to
* remain stable. A future update of TinyCBOR may produce different output for
* the same input and parsers may be unable to handle them.
* the same input and parsers may be unable to handle it.
*
* \sa CborParsing, CborToJson, cbor_parser_init()
*/
@@ -102,7 +102,7 @@
* By default, float values are suffixed by "f" and half-float values suffixed by "f16" (doubles have no suffix).
* If the CborPrettyNumericEncodingIndicators flag is active, the values instead are encoded following the
* Section 6 recommended encoding indicators: float values are suffixed with "_2" and half-float with "_1".
* A dot is always present.
* A decimal point is always present.
* \par Arrays:
* Comma-separated list of elements, enclosed in square brackets ("[" and "]").
* \par Maps:
@@ -127,7 +127,7 @@
* number or the opening bracket or brace, followed by a number
* indicating the CBOR additional information: 0 for 1 byte, 1 for 2
* bytes, 2 for 4 bytes and 3 for 8 bytes.
* If the CborPrettyIndicateIndetermineLength option is active, maps,
* If the CborPrettyIndicateIndeterminateLength option is active, maps,
* arrays and strings encoded with indeterminate length will be marked by
* an underscore after the opening bracket or brace or the string (if not
* showing fragments), without a number after it.
@@ -139,11 +139,11 @@
*
* \value CborPrettyNumericEncodingIndicators Use numeric encoding indicators instead of textual for float and half-float.
* \value CborPrettyTextualEncodingIndicators Use textual encoding indicators for float ("f") and half-float ("f16").
* \value CborPrettyIndicateIndetermineLength Indicate when a map or array has indeterminate length.
* \value CborPrettyIndicateIndeterminateLength (default) Indicate when a map or array has indeterminate length.
* \value CborPrettyIndicateOverlongNumbers Indicate when a number or length was encoded with more bytes than needed.
* \value CborPrettyShowStringFragments If the byte or text string is transmitted in chunks, show each individually.
* \value CborPrettyMergeStringFragment Merge all chunked byte or text strings and display them in a single entry.
* \value CborPrettyDefaultFlags Default conversion flags.
* \value CborPrettyDefaultFlags Default conversion flags.
*/
static void printRecursionLimit(CborStreamFunction stream, void *out)
@@ -245,7 +245,7 @@ static const char *resolve_indicator(const uint8_t *ptr, const uint8_t *end, int
return no_indicator;
/* determine whether to show anything */
if ((flags & CborPrettyIndicateIndetermineLength) &&
if ((flags & CborPrettyIndicateIndeterminateLength) &&
additional_information == IndefiniteLength)
return indicators[IndefiniteLength - Value8Bit];
if ((flags & CborPrettyIndicateOverlongNumbers) == 0)
@@ -507,14 +507,15 @@ static CborError value_to_pretty(CborStreamFunction stream, void *out, CborValue
* Converts the current CBOR type pointed by \a value to its textual
* representation and writes it to the stream by calling the \a streamFunction.
* If an error occurs, this function returns an error code similar to
* CborParsing.
* \ref CborParsing.
*
* The textual representation can be controlled by the \a flags parameter (see
* CborPrettyFlags for more information).
* \ref CborPrettyFlags for more information).
*
* If no error ocurred, this function advances \a value to the next element.
* Often, concatenating the text representation of multiple elements can be
* done by appending a comma to the output stream.
* done by appending a comma to the output stream in between calls to this
* function.
*
* The \a streamFunction function will be called with the \a token value as the
* first parameter and a printf-style format string as the second, with a variable
+7 -5
View File
@@ -41,7 +41,7 @@ static CborError cbor_fprintf(void *out, const char *fmt, ...)
/**
* \fn CborError cbor_value_to_pretty(FILE *out, const CborValue *value)
*
* Converts the current CBOR type pointed by \a value to its textual
* Converts the current CBOR type pointed to by \a value to its textual
* representation and writes it to the \a out stream. If an error occurs, this
* function returns an error code similar to CborParsing.
*
@@ -49,13 +49,14 @@ static CborError cbor_fprintf(void *out, const char *fmt, ...)
*/
/**
* Converts the current CBOR type pointed by \a value to its textual
* Converts the current CBOR type pointed to by \a value to its textual
* representation and writes it to the \a out stream. If an error occurs, this
* function returns an error code similar to CborParsing.
*
* If no error ocurred, this function advances \a value to the next element.
* Often, concatenating the text representation of multiple elements can be
* done by appending a comma to the output stream.
* done by appending a comma to the output stream in between calls to this
* function.
*
* \sa cbor_value_to_pretty(), cbor_value_to_pretty_stream(), cbor_value_to_json_advance()
*/
@@ -65,7 +66,7 @@ CborError cbor_value_to_pretty_advance(FILE *out, CborValue *value)
}
/**
* Converts the current CBOR type pointed by \a value to its textual
* Converts the current CBOR type pointed to by \a value to its textual
* representation and writes it to the \a out stream. If an error occurs, this
* function returns an error code similar to CborParsing.
*
@@ -74,7 +75,8 @@ CborError cbor_value_to_pretty_advance(FILE *out, CborValue *value)
*
* If no error ocurred, this function advances \a value to the next element.
* Often, concatenating the text representation of multiple elements can be
* done by appending a comma to the output stream.
* done by appending a comma to the output stream in between calls to this
* function.
*
* \sa cbor_value_to_pretty_stream(), cbor_value_to_pretty(), cbor_value_to_json_advance()
*/
+18 -16
View File
@@ -45,7 +45,7 @@
* \defgroup CborToJson Converting CBOR to JSON
* \brief Group of functions used to convert CBOR to JSON.
*
* This group contains two functions that are can be used to convert one
* This group contains two functions that can be used to convert a \ref
* CborValue object to an equivalent JSON representation. This module attempts
* to follow the recommendations from RFC 7049 section 4.1 "Converting from
* CBOR to JSON", though it has a few differences. They are noted below.
@@ -71,13 +71,13 @@
* error CborErrorIO.
*
* These functions also perform UTF-8 validation in CBOR text strings. If they
* encounter a sequence of bytes that not permitted in UTF-8, they will return
* encounter a sequence of bytes that is not permitted in UTF-8, they will return
* CborErrorInvalidUtf8TextString. That includes encoding of surrogate points
* in UTF-8.
*
* \warning The metadata produced by these functions is not guaranteed to
* remain stable. A future update of TinyCBOR may produce different output for
* the same input and parsers may be unable to handle them.
* the same input and parsers may be unable to handle it.
*
* \sa CborParsing, CborPretty, cbor_parser_init()
*/
@@ -93,12 +93,12 @@
* \par Number precision:
* ALL JSON numbers, due to its JavaScript heritage, are IEEE 754
* double-precision floating point. This means JSON is not capable of
* representing integers numbers outside the range [-(2<sup>53</sup>)+1,
* representing all integers numbers outside the range [-(2<sup>53</sup>)+1,
* 2<sup>53</sup>-1] and is not capable of representing NaN or infinite. If the
* CBOR data contains a number outside the valid range, the conversion will
* lose precision. If the input was NaN or infinite, the result of the
* conversion will be "null". In addition, the distinction between half-,
* single- and double-precision is lost.
* conversion will be the JSON null value. In addition, the distinction between
* half-, single- and double-precision is lost.
*
* \par
* If enabled, the original value and original type are stored in the metadata.
@@ -122,7 +122,7 @@
*
* \par
* If the CborConvertTagsToObjects option is active, then the tag and the
* tagged value are converted to to a JSON object. Otherwise, if enabled, the
* tagged value are converted to a JSON object. Otherwise, if enabled, the
* last (innermost) tag is stored in the metadata.
*
* \par Non-string keys in maps:
@@ -136,7 +136,7 @@
* \par Duplicate keys in maps:
* Neither JSON nor CBOR allow duplicated keys, but current TinyCBOR does not
* validate that this is the case. If there are duplicated keys in the input,
* they will be repeated in the output, which may JSON tools may flag as
* they will be repeated in the output, which many JSON tools may flag as
* invalid. In addition to that, if the CborConvertStringifyMapKeys option is
* active, it is possible that a non-string key in a CBOR map will be converted
* to a string form that is identical to another key.
@@ -155,7 +155,7 @@ enum ConversionStatusFlags {
NumberPrecisionWasLost = 0x400,
NumberWasNaN = 0x800,
NumberWasInfinite = 0x1000,
NumberWasNegative = 0x2000, /* always used with NumberWasInifite or NumberWasTooBig */
NumberWasNegative = 0x2000, /* only used with NumberWasInifite or NumberWasTooBig */
FinalTypeMask = 0xff
};
@@ -457,8 +457,10 @@ static CborError map_to_json(FILE *out, CborValue *it, int flags, ConversionStat
return err;
/* first, print the key */
if (fprintf(out, "\"%s\":", key) < 0)
if (fprintf(out, "\"%s\":", key) < 0) {
free(key);
return CborErrorIO;
}
/* then, print the value */
CborType valueType = cbor_value_get_type(it);
@@ -657,19 +659,19 @@ static CborError value_to_json(FILE *out, CborValue *it, int flags, CborType typ
/**
* \fn CborError cbor_value_to_json(FILE *out, const CborValue *value, int flags)
*
* Converts the current CBOR type pointed by \a value to JSON and writes that
* Converts the current CBOR type pointed to by \a value to JSON and writes that
* to the \a out stream. If an error occurs, this function returns an error
* code similar to CborParsing. The \a flags parameter indicates one of the
* flags from CborToJsonFlags that control the conversion.
* code similar to CborParsing. The \a flags parameter indicates one or more of
* the flags from CborToJsonFlags that control the conversion.
*
* \sa cbor_value_to_json_advance(), cbor_value_to_pretty()
*/
/**
* Converts the current CBOR type pointed by \a value to JSON and writes that
* Converts the current CBOR type pointed to by \a value to JSON and writes that
* to the \a out stream. If an error occurs, this function returns an error
* code similar to CborParsing. The \a flags parameter indicates one of the
* flags from CborToJsonFlags that control the conversion.
* code similar to CborParsing. The \a flags parameter indicates one or more of
* the flags from CborToJsonFlags that control the conversion.
*
* If no error ocurred, this function advances \a value to the next element.
*
+8 -5
View File
@@ -55,7 +55,7 @@
* The CborValidationFlags enum contains flags that control the validation of a
* CBOR stream.
*
* \value CborValidateBasic Validates only the syntax correctedness of the stream.
* \value CborValidateBasic Validates only the syntactic correctedness of the stream.
* \value CborValidateCanonical Validates that the stream is in canonical format, according to
* RFC 7049 section 3.9.
* \value CborValidateStrictMode Performs strict validation, according to RFC 7049 section 3.10.
@@ -65,7 +65,7 @@
* enconded in their shortest form possible.
* \value CborValidateShortestFloatingPoint (Canonical) Validate that floating-point numbers are encoded
* in their shortest form possible.
* \value CborValidateShortestNumbers (Canonical) Validate both integrals and floating-point numbers
* \value CborValidateShortestNumbers (Canonical) Validate both integral and floating-point numbers
* are in their shortest form possible.
* \value CborValidateNoIndeterminateLength (Canonical) Validate that no string, array or map uses
* indeterminate length encoding.
@@ -74,7 +74,10 @@
* \value CborValidateMapKeysAreUnique (Strict mode) Validate that map keys are unique.
* \value CborValidateTagUse (Strict mode) Validate that known tags are used with the
* correct types. This does not validate that the content of
* those types is syntactically correct.
* those types is syntactically correct. For example, this
* option validates that tag 1 (DateTimeString) is used with
* a Text String, but it does not validate that the string is
* a valid date/time representation.
* \value CborValidateUtf8 (Strict mode) Validate that text strings are appropriately
* encoded in UTF-8.
* \value CborValidateMapKeysAreString Validate that all map keys are text strings.
@@ -632,10 +635,10 @@ static CborError validate_value(CborValue *it, int flags, int recursionLeft)
}
/**
* Performs a full validation controlled by the \a flags options of the CBOR
* Performs a full validation, controlled by the \a flags options, of the CBOR
* stream pointed by \a it and returns the error it found. If no error was
* found, it returns CborNoError and the application can iterate over the items
* with certainty that no other errors will appear during parsing.
* with certainty that no errors will appear during parsing.
*
* If \a flags is CborValidateBasic, the result should be the same as
* cbor_value_validate_basic().
+26 -27
View File
@@ -272,7 +272,6 @@ CborError encodeVariant(CborEncoder *encoder, const QVariant &v)
return CborErrorUnknownType;
}
bool compareFailed;
void compare(const QVariant &input, const QByteArray &output)
{
QByteArray buffer(output.length(), Qt::Uninitialized);
@@ -512,34 +511,34 @@ void tst_Encoder::tags()
QFETCH(QByteArray, output);
compare(QVariant::fromValue(Tag{1, input}), "\xc1" + output);
if (compareFailed) return;
if (QTest::currentTestFailed()) return;
compare(QVariant::fromValue(Tag{24, input}), "\xd8\x18" + output);
if (compareFailed) return;
if (QTest::currentTestFailed()) return;
compare(QVariant::fromValue(Tag{255, input}), "\xd8\xff" + output);
if (compareFailed) return;
if (QTest::currentTestFailed()) return;
compare(QVariant::fromValue(Tag{256, input}), raw("\xd9\1\0") + output);
if (compareFailed) return;
if (QTest::currentTestFailed()) return;
compare(QVariant::fromValue(Tag{CborSignatureTag, input}), raw("\xd9\xd9\xf7") + output);
if (compareFailed) return;
if (QTest::currentTestFailed()) return;
compare(QVariant::fromValue(Tag{65535, input}), raw("\xd9\xff\xff") + output);
if (compareFailed) return;
if (QTest::currentTestFailed()) return;
compare(QVariant::fromValue(Tag{65536, input}), raw("\xda\0\1\0\0") + output);
if (compareFailed) return;
if (QTest::currentTestFailed()) return;
compare(QVariant::fromValue(Tag{UINT32_MAX, input}), raw("\xda\xff\xff\xff\xff") + output);
if (compareFailed) return;
if (QTest::currentTestFailed()) return;
compare(QVariant::fromValue(Tag{UINT32_MAX + Q_UINT64_C(1), input}), raw("\xdb\0\0\0\1\0\0\0\0") + output);
if (compareFailed) return;
if (QTest::currentTestFailed()) return;
compare(QVariant::fromValue(Tag{UINT64_MAX, input}), raw("\xdb\xff\xff\xff\xff\xff\xff\xff\xff") + output);
if (compareFailed) return;
if (QTest::currentTestFailed()) return;
// nested tags
compare(QVariant::fromValue(Tag{1, QVariant::fromValue(Tag{1, input})}), "\xc1\xc1" + output);
@@ -551,10 +550,10 @@ void tst_Encoder::arrays()
QFETCH(QByteArray, output);
compare(make_list(input), "\x81" + output);
if (compareFailed) return;
if (QTest::currentTestFailed()) return;
compare(make_list(input, input), "\x82" + output + output);
if (compareFailed) return;
if (QTest::currentTestFailed()) return;
{
QVariantList list{input};
@@ -566,7 +565,7 @@ void tst_Encoder::arrays()
longoutput += longoutput;
}
compare(list, "\x98\x20" + longoutput);
if (compareFailed) return;
if (QTest::currentTestFailed()) return;
// now 256 elements (32 << 3)
for (int i = 0; i < 3; ++i) {
@@ -574,18 +573,18 @@ void tst_Encoder::arrays()
longoutput += longoutput;
}
compare(list, raw("\x99\1\0") + longoutput);
if (compareFailed) return;
if (QTest::currentTestFailed()) return;
}
// nested lists
compare(make_list(make_list(input)), "\x81\x81" + output);
if (compareFailed) return;
if (QTest::currentTestFailed()) return;
compare(make_list(make_list(input, input)), "\x81\x82" + output + output);
if (compareFailed) return;
if (QTest::currentTestFailed()) return;
compare(make_list(make_list(input), input), "\x82\x81" + output + output);
if (compareFailed) return;
if (QTest::currentTestFailed()) return;
compare(make_list(make_list(input), make_list(input)), "\x82\x81" + output + "\x81" + output);
}
@@ -596,13 +595,13 @@ void tst_Encoder::maps()
QFETCH(QByteArray, output);
compare(make_map({{1, input}}), "\xa1\1" + output);
if (compareFailed) return;
if (QTest::currentTestFailed()) return;
compare(make_map({{1, input}, {input, 24}}), "\xa2\1" + output + output + "\x18\x18");
if (compareFailed) return;
if (QTest::currentTestFailed()) return;
compare(make_map({{input, input}}), "\xa1" + output + output);
if (compareFailed) return;
if (QTest::currentTestFailed()) return;
{
Map map{{1, input}};
@@ -614,7 +613,7 @@ void tst_Encoder::maps()
longoutput += longoutput;
}
compare(QVariant::fromValue(map), "\xb8\x20" + longoutput);
if (compareFailed) return;
if (QTest::currentTestFailed()) return;
// now 256 elements (32 << 3)
for (int i = 0; i < 3; ++i) {
@@ -622,18 +621,18 @@ void tst_Encoder::maps()
longoutput += longoutput;
}
compare(QVariant::fromValue(map), raw("\xb9\1\0") + longoutput);
if (compareFailed) return;
if (QTest::currentTestFailed()) return;
}
// nested lists
// nested maps
compare(make_map({{1, make_map({{2, input}})}}), "\xa1\1\xa1\2" + output);
if (compareFailed) return;
if (QTest::currentTestFailed()) return;
compare(make_map({{1, make_map({{2, input}, {input, false}})}}), "\xa1\1\xa2\2" + output + output + "\xf4");
if (compareFailed) return;
if (QTest::currentTestFailed()) return;
compare(make_map({{1, make_map({{2, input}})}, {input, false}}), "\xa2\1\xa1\2" + output + output + "\xf4");
if (compareFailed) return;
if (QTest::currentTestFailed()) return;
}
void tst_Encoder::shortBuffer()
+1 -1
View File
@@ -113,7 +113,7 @@ static CborError qstring_printf(void *out, const char *fmt, ...)
CborError parseOne(CborValue *it, QString *parsed)
{
int flags = CborPrettyShowStringFragments | CborPrettyIndicateIndetermineLength |
int flags = CborPrettyShowStringFragments | CborPrettyIndicateIndeterminateLength |
CborPrettyIndicateOverlongNumbers;
parsed->clear();
+1 -1
View File
@@ -651,7 +651,7 @@ void compareMetaData(QByteArray data, const QString &expected, int otherFlags =
{
QString decoded;
// needs to be in in one map, with the entry called "v"
// needs to be in one map, with the entry called "v"
data = "\xa1\x61v" + data;
{
+1 -1
View File
@@ -104,7 +104,7 @@ int main(int argc, char **argv)
cbor_flags |= CborPrettyShowStringFragments;
break;
case 'n':
cbor_flags |= CborPrettyIndicateIndetermineLength | CborPrettyNumericEncodingIndicators;
cbor_flags |= CborPrettyIndicateIndeterminateLength | CborPrettyNumericEncodingIndicators;
break;
case 'M':
+5 -3
View File
@@ -365,7 +365,7 @@ encode_double:
for (item = json->child ; item; item = item->next) {
if (usingMetaData && strlen(item->string) > strlen(meta_data_marker)
&& strcmp(item->string + strlen(item->string) - 5, meta_data_marker) == 0)
&& strcmp(item->string + strlen(item->string) - strlen(meta_data_marker), meta_data_marker) == 0)
continue;
err = cbor_encode_text_stringz(&container, item->string);
@@ -407,7 +407,7 @@ int main(int argc, char **argv)
// fall through
case 'h':
puts("Usage: json2cbor [OPTION]... [FILE]...\n"
"Reads JSON content from FILE and convert to CBOR.\n"
"Reads JSON content from FILE and converts to CBOR.\n"
"\n"
"Options:\n"
" -M Interpret metadata added by cbordump tool\n"
@@ -448,8 +448,10 @@ int main(int argc, char **argv)
buffer = NULL;
do { // it the hard way
buffer = realloc(buffer, buffersize + chunk);
if (buffer == NULL)
if (buffer == NULL) {
perror("malloc");
return EXIT_FAILURE;
}
buffersize += fread(buffer + buffersize, 1, chunk, in);
} while (!feof(in) && !ferror(in));