new example starting to work
diff --git a/QCBOR.xcodeproj/project.pbxproj b/QCBOR.xcodeproj/project.pbxproj
index ad20feb..df31dee 100644
--- a/QCBOR.xcodeproj/project.pbxproj
+++ b/QCBOR.xcodeproj/project.pbxproj
@@ -14,6 +14,12 @@
E73B575E2161CA7C0080D658 /* float_tests.c in Sources */ = {isa = PBXBuildFile; fileRef = E73B575A2161CA7C0080D658 /* float_tests.c */; };
E73B575F2161CA7C0080D658 /* half_to_double_from_rfc7049.c in Sources */ = {isa = PBXBuildFile; fileRef = E73B575D2161CA7C0080D658 /* half_to_double_from_rfc7049.c */; };
E73B57652161F8F80080D658 /* run_tests.c in Sources */ = {isa = PBXBuildFile; fileRef = E73B57632161F8F70080D658 /* run_tests.c */; };
+ E743D0ED24AC54090017899F /* qcbor_encode.c in Sources */ = {isa = PBXBuildFile; fileRef = E776E08C214AE07400E67947 /* qcbor_encode.c */; };
+ E743D0EE24AC54110017899F /* qcbor_decode.c in Sources */ = {isa = PBXBuildFile; fileRef = E776E08E214AE07500E67947 /* qcbor_decode.c */; };
+ E743D0EF24AC54170017899F /* UsefulBuf.c in Sources */ = {isa = PBXBuildFile; fileRef = E776E08D214AE07500E67947 /* UsefulBuf.c */; };
+ E743D0F024AC541A0017899F /* ieee754.c in Sources */ = {isa = PBXBuildFile; fileRef = E73B57582161CA690080D658 /* ieee754.c */; };
+ E743D0F124AC54230017899F /* example.c in Sources */ = {isa = PBXBuildFile; fileRef = E743D0E124AC516D0017899F /* example.c */; };
+ E743D0F324AD08020017899F /* example.c in Sources */ = {isa = PBXBuildFile; fileRef = E743D0E124AC516D0017899F /* example.c */; };
E772021723B52C02006E966E /* qcbor_encode.c in Sources */ = {isa = PBXBuildFile; fileRef = E776E08C214AE07400E67947 /* qcbor_encode.c */; };
E772021823B52C02006E966E /* ieee754.c in Sources */ = {isa = PBXBuildFile; fileRef = E73B57582161CA690080D658 /* ieee754.c */; };
E772021923B52C02006E966E /* half_to_double_from_rfc7049.c in Sources */ = {isa = PBXBuildFile; fileRef = E73B575D2161CA7C0080D658 /* half_to_double_from_rfc7049.c */; };
@@ -32,6 +38,15 @@
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
+ E743D0E424AC51C00017899F /* CopyFiles */ = {
+ isa = PBXCopyFilesBuildPhase;
+ buildActionMask = 2147483647;
+ dstPath = /usr/share/man/man1/;
+ dstSubfolderSpec = 0;
+ files = (
+ );
+ runOnlyForDeploymentPostprocessing = 1;
+ };
E772022323B52C02006E966E /* CopyFiles */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
@@ -68,6 +83,9 @@
E73B575D2161CA7C0080D658 /* half_to_double_from_rfc7049.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = half_to_double_from_rfc7049.c; path = test/half_to_double_from_rfc7049.c; sourceTree = "<group>"; };
E73B57632161F8F70080D658 /* run_tests.c */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 3; lastKnownFileType = sourcecode.c.c; name = run_tests.c; path = test/run_tests.c; sourceTree = "<group>"; tabWidth = 3; };
E73B57642161F8F80080D658 /* run_tests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = run_tests.h; path = test/run_tests.h; sourceTree = "<group>"; };
+ E743D0E124AC516D0017899F /* example.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = example.c; sourceTree = "<group>"; };
+ E743D0E624AC51C00017899F /* Example */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = Example; sourceTree = BUILT_PRODUCTS_DIR; };
+ E743D0F224AC54600017899F /* example.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = example.h; sourceTree = "<group>"; };
E74BF411245D6713002CE8E8 /* UsefulBuf.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = UsefulBuf.h; path = inc/qcbor/UsefulBuf.h; sourceTree = "<group>"; };
E74FA9FE247D2F2C003F8ECE /* Tagging.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = Tagging.md; sourceTree = "<group>"; };
E772022723B52C02006E966E /* QCBOR_Disable_Exp_Mantissa */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = QCBOR_Disable_Exp_Mantissa; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -86,6 +104,13 @@
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
+ E743D0E324AC51C00017899F /* Frameworks */ = {
+ isa = PBXFrameworksBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
E772022223B52C02006E966E /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
@@ -103,6 +128,15 @@
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
+ E743D0E024AC51470017899F /* example */ = {
+ isa = PBXGroup;
+ children = (
+ E743D0E124AC516D0017899F /* example.c */,
+ E743D0F224AC54600017899F /* example.h */,
+ );
+ name = example;
+ sourceTree = "<group>";
+ };
E776E073214ADF7F00E67947 = {
isa = PBXGroup;
children = (
@@ -112,6 +146,7 @@
E776E092214AE07C00E67947 /* inc */,
E776E08B214AE06600E67947 /* src */,
E776E095214AE0B600E67947 /* test */,
+ E743D0E024AC51470017899F /* example */,
E776E07D214ADF7F00E67947 /* Products */,
);
sourceTree = "<group>";
@@ -121,6 +156,7 @@
children = (
E776E07C214ADF7F00E67947 /* QCBOR */,
E772022723B52C02006E966E /* QCBOR_Disable_Exp_Mantissa */,
+ E743D0E624AC51C00017899F /* Example */,
);
name = Products;
sourceTree = "<group>";
@@ -174,6 +210,23 @@
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
+ E743D0E524AC51C00017899F /* Example */ = {
+ isa = PBXNativeTarget;
+ buildConfigurationList = E743D0EA24AC51C00017899F /* Build configuration list for PBXNativeTarget "Example" */;
+ buildPhases = (
+ E743D0E224AC51C00017899F /* Sources */,
+ E743D0E324AC51C00017899F /* Frameworks */,
+ E743D0E424AC51C00017899F /* CopyFiles */,
+ );
+ buildRules = (
+ );
+ dependencies = (
+ );
+ name = Example;
+ productName = Example;
+ productReference = E743D0E624AC51C00017899F /* Example */;
+ productType = "com.apple.product-type.tool";
+ };
E772021523B52C02006E966E /* QCBOR_Disable_Exp_Mantissa */ = {
isa = PBXNativeTarget;
buildConfigurationList = E772022423B52C02006E966E /* Build configuration list for PBXNativeTarget "QCBOR_Disable_Exp_Mantissa" */;
@@ -217,6 +270,9 @@
LastUpgradeCheck = 1140;
ORGANIZATIONNAME = "Laurence Lundblade";
TargetAttributes = {
+ E743D0E524AC51C00017899F = {
+ CreatedOnToolsVersion = 11.5;
+ };
E776E07B214ADF7F00E67947 = {
CreatedOnToolsVersion = 9.4.1;
};
@@ -237,11 +293,24 @@
targets = (
E776E07B214ADF7F00E67947 /* QCBOR */,
E772021523B52C02006E966E /* QCBOR_Disable_Exp_Mantissa */,
+ E743D0E524AC51C00017899F /* Example */,
);
};
/* End PBXProject section */
/* Begin PBXSourcesBuildPhase section */
+ E743D0E224AC51C00017899F /* Sources */ = {
+ isa = PBXSourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ E743D0ED24AC54090017899F /* qcbor_encode.c in Sources */,
+ E743D0EE24AC54110017899F /* qcbor_decode.c in Sources */,
+ E743D0F024AC541A0017899F /* ieee754.c in Sources */,
+ E743D0EF24AC54170017899F /* UsefulBuf.c in Sources */,
+ E743D0F124AC54230017899F /* example.c in Sources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
E772021623B52C02006E966E /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
@@ -274,6 +343,7 @@
E776E090214AE07500E67947 /* UsefulBuf.c in Sources */,
0FA9BEBA216DC7AD00BA646B /* qcbor_encode_tests.c in Sources */,
E776E097214AE0C700E67947 /* cmd_line_main.c in Sources */,
+ E743D0F324AD08020017899F /* example.c in Sources */,
0FA9BEBD216DE31700BA646B /* UsefulBuf_Tests.c in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
@@ -281,6 +351,27 @@
/* End PBXSourcesBuildPhase section */
/* Begin XCBuildConfiguration section */
+ E743D0EB24AC51C00017899F /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ CODE_SIGN_STYLE = Automatic;
+ MACOSX_DEPLOYMENT_TARGET = 10.15;
+ MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
+ MTL_FAST_MATH = YES;
+ PRODUCT_NAME = "$(TARGET_NAME)";
+ };
+ name = Debug;
+ };
+ E743D0EC24AC51C00017899F /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ CODE_SIGN_STYLE = Automatic;
+ MACOSX_DEPLOYMENT_TARGET = 10.15;
+ MTL_FAST_MATH = YES;
+ PRODUCT_NAME = "$(TARGET_NAME)";
+ };
+ name = Release;
+ };
E772022523B52C02006E966E /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
@@ -463,6 +554,15 @@
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
+ E743D0EA24AC51C00017899F /* Build configuration list for PBXNativeTarget "Example" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ E743D0EB24AC51C00017899F /* Debug */,
+ E743D0EC24AC51C00017899F /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
E772022423B52C02006E966E /* Build configuration list for PBXNativeTarget "QCBOR_Disable_Exp_Mantissa" */ = {
isa = XCConfigurationList;
buildConfigurations = (
diff --git a/cmd_line_main.c b/cmd_line_main.c
index f7c6010..9e4a819 100644
--- a/cmd_line_main.c
+++ b/cmd_line_main.c
@@ -12,6 +12,7 @@
#include <stdio.h>
#include "run_tests.h"
+#include "example.h"
/*
@@ -31,6 +32,9 @@
{
(void)argc; // Avoid unused parameter error
+ RunQCborExample(); // TODO: organize this better
+
+
// This call prints out sizes of data structures to remind us
// to keep them small.
PrintSizesQCBOR(&fputs_wrapper, stdout);
diff --git a/example.c b/example.c
new file mode 100644
index 0000000..b07a76c
--- /dev/null
+++ b/example.c
@@ -0,0 +1,269 @@
+/*==============================================================================
+ example.c -- Example code for QCBOR
+
+ Copyright (c) 2020, Laurence Lundblade. All rights reserved.
+
+ SPDX-License-Identifier: BSD-3-Clause
+
+ See BSD-3-Clause license in README.md
+
+ Created on 6/30/2020
+=============================================================================*/
+
+
+#include <stdio.h>
+#include "example.h"
+#include "qcbor/qcbor_encode.h"
+#include "qcbor/qcbor_decode.h"
+
+#define MAX_CYLINDERS 16
+
+typedef struct
+{
+ UsefulBufC Manufacturer;
+ uint64_t uNumCylinders;
+ uint64_t uDisplacement;
+ uint64_t uHorsePower;
+ double uDesignedCompresion;
+ struct {
+ double uMeasuredCompression;
+ } cylinders[MAX_CYLINDERS];
+ bool bTurboCharged;
+} Engine;
+
+
+void EngineInit(Engine *pE)
+{
+ pE->uNumCylinders = 6;
+ pE->bTurboCharged = false;
+ pE->Manufacturer = UsefulBuf_FROM_SZ_LITERAL("Porsche");
+ pE->uDisplacement = 3296;
+ pE->uHorsePower = 210;
+ pE->uDesignedCompresion = 9.1;
+ pE->cylinders[0].uMeasuredCompression = 9.0;
+ pE->cylinders[1].uMeasuredCompression = 9.2;
+ pE->cylinders[2].uMeasuredCompression = 8.9;
+ pE->cylinders[3].uMeasuredCompression = 8.9;
+ pE->cylinders[4].uMeasuredCompression = 9.1;
+ pE->cylinders[5].uMeasuredCompression = 9.0;
+}
+
+
+UsefulBufC EncodeEngine(const Engine *pEngine, UsefulBuf Buffer)
+{
+ QCBOREncodeContext EncodeCtx;
+
+ QCBOREncode_Init(&EncodeCtx, Buffer);
+ QCBOREncode_OpenMap(&EncodeCtx);
+ QCBOREncode_AddTextToMap(&EncodeCtx, "Manufacturer", pEngine->Manufacturer);
+ QCBOREncode_AddUInt64ToMap(&EncodeCtx, "NumCylinders", pEngine->uNumCylinders);
+ QCBOREncode_AddUInt64ToMap(&EncodeCtx, "Displacement", pEngine->uDisplacement);
+ QCBOREncode_AddUInt64ToMap(&EncodeCtx, "HorsePower", pEngine->uHorsePower);
+ QCBOREncode_AddDoubleToMap(&EncodeCtx, "DesignedCompression", pEngine->uDesignedCompresion);
+ QCBOREncode_OpenArrayInMap(&EncodeCtx, "Cylinders");
+ for(uint64_t i = 0 ; i < pEngine->uNumCylinders; i++) {
+ QCBOREncode_AddDouble(&EncodeCtx, pEngine->cylinders[i].uMeasuredCompression);
+ }
+ QCBOREncode_CloseArray(&EncodeCtx);
+ QCBOREncode_AddBoolToMap(&EncodeCtx, "turbo", pEngine->bTurboCharged);
+ QCBOREncode_CloseMap(&EncodeCtx);
+
+ UsefulBufC EncodedCBOR;
+ QCBORError uErr;
+ uErr = QCBOREncode_Finish(&EncodeCtx, &EncodedCBOR);
+ if(uErr != QCBOR_SUCCESS) {
+ return NULLUsefulBufC;
+ } else {
+ return EncodedCBOR;
+ }
+}
+
+
+UsefulBufC EncodeEngineIndefinteLen(const Engine *pEngine, UsefulBuf Buffer)
+{
+ QCBOREncodeContext EncodeCtx;
+
+ QCBOREncode_Init(&EncodeCtx, Buffer);
+ QCBOREncode_OpenMapIndefiniteLength(&EncodeCtx);
+ QCBOREncode_AddTextToMap(&EncodeCtx, "Manufacturer", pEngine->Manufacturer);
+ QCBOREncode_AddUInt64ToMap(&EncodeCtx, "Displacement", pEngine->uDisplacement);
+ QCBOREncode_AddUInt64ToMap(&EncodeCtx, "HorsePower", pEngine->uHorsePower);
+ QCBOREncode_AddDoubleToMap(&EncodeCtx, "DesignedCompression", pEngine->uDesignedCompresion);
+ QCBOREncode_AddUInt64ToMap(&EncodeCtx, "NumCylinders", pEngine->uNumCylinders);
+ QCBOREncode_OpenArrayIndefiniteLengthInMap(&EncodeCtx, "Cylinders");
+ for(uint64_t i = 0 ; i < pEngine->uNumCylinders; i++) {
+ QCBOREncode_AddDouble(&EncodeCtx, pEngine->cylinders[i].uMeasuredCompression);
+ }
+ QCBOREncode_CloseArrayIndefiniteLength(&EncodeCtx);
+ QCBOREncode_AddBoolToMap(&EncodeCtx, "turbo", pEngine->bTurboCharged);
+ QCBOREncode_CloseMapIndefiniteLength(&EncodeCtx);
+
+ UsefulBufC EncodedCBOR;
+ QCBORError uErr;
+ uErr = QCBOREncode_Finish(&EncodeCtx, &EncodedCBOR);
+ if(uErr != QCBOR_SUCCESS) {
+ return NULLUsefulBufC;
+ } else {
+ return EncodedCBOR;
+ }
+}
+
+
+/*
+A -- require all fields ; easiest code
+B -- all are optional; messiest code; should this be accommodate better?
+C -- some are optional; not too hard
+
+It is a protocol error to have the wrong type for a label.
+
+ */
+
+QCBORError DecodeEngine(UsefulBufC EncodedEngine, Engine *pE)
+{
+ QCBORDecodeContext DecodeCtx;
+
+ QCBORDecode_Init(&DecodeCtx, EncodedEngine, QCBOR_DECODE_MODE_NORMAL);
+ QCBORDecode_EnterMap(&DecodeCtx);
+ QCBORDecode_GetTextInMapSZ(&DecodeCtx, "Manufacturer", &(pE->Manufacturer));
+ QCBORDecode_GetUInt64InMapSZ(&DecodeCtx, "Displacement", &(pE->uDisplacement));
+ QCBORDecode_GetUInt64InMapSZ(&DecodeCtx, "HorsePower", &(pE->uHorsePower));
+ QCBORDecode_GetDoubleInMapSZ(&DecodeCtx, "DesignedCompression", &(pE->uDesignedCompresion));
+ QCBORDecode_GetBoolInMapSZ(&DecodeCtx, "turbo", &(pE->bTurboCharged));
+
+ QCBORDecode_GetUInt64InMapSZ(&DecodeCtx, "NumCylinders", &(pE->uNumCylinders));
+
+ /* Must check error before referencing pE->uNumCylinders to be sure it
+ is valid. If any of the above errored, it won't be valid. */
+ if(QCBORDecode_GetError(&DecodeCtx)) {
+ return 100; // TODO: more error processing
+ }
+
+ if(pE->uNumCylinders > MAX_CYLINDERS) {
+ return 900;
+ }
+
+ QCBORDecode_EnterArrayFromMapSZ(&DecodeCtx, "Cylinders");
+ uint64_t i = 0;
+ while(1) {
+ QCBORDecode_GetDouble(&DecodeCtx, &(pE->cylinders[i].uMeasuredCompression));
+ i++;
+ if(i >= pE->uNumCylinders ) {
+ break;
+ }
+ }
+ QCBORDecode_ExitArray(&DecodeCtx);
+ QCBORDecode_ExitMap(&DecodeCtx);
+
+ QCBORError uErr = QCBORDecode_Finish(&DecodeCtx);
+
+ return uErr;
+}
+
+#if 0
+QCBORError CheckLabelAndType(const char *szLabel, uint8_t uQCBORType, QCBORItem *pItem)
+{
+ if(pItem->uLabelType != QCBOR_TYPE_TEXT_STRING) {
+ return QCBOR_ERR_NOT_FOUND;
+ }
+
+ UsefulBufC Label = UsefulBuf_FromSZ(szLabel);
+
+ if(UsefulBuf_Compare(Label, pItem->val.string)) {
+ return QCBOR_ERR_NOT_FOUND;
+ }
+
+ if(pItem->uDataType != uQCBORType) {
+ return QCBOR_ERR_UNEXPECTED_TYPE;
+ }
+
+ return QCBOR_SUCCESS;
+}
+
+void DecodeCylinders(QCBORDecodeContext *pDctx, Engine *pE, const QCBORItem *pItem)
+{
+
+}
+
+QCBORError DecodeEngineBasic(UsefulBufC EncodedEngine, Engine *pE)
+{
+ QCBORDecodeContext DecodeCtx;
+
+ QCBORDecode_Init(&DecodeCtx, EncodedEngine, 0);// TODO: fill in mode;
+
+ QCBORItem Item;
+ QCBORError uErr;
+
+ uErr = QCBORDecode_GetNext(&DecodeCtx, &Item);
+ if(uErr != QCBOR_SUCCESS) {
+ goto Done;
+ }
+ if(Item.uDataType != QCBOR_TYPE_MAP) {
+ uErr = 100;
+ goto Done;
+ }
+
+ while(1) {
+ uErr = QCBORDecode_GetNext(&DecodeCtx, &Item);
+ if(uErr != QCBOR_SUCCESS) {
+ goto Done;
+ }
+ if(Item.uDataType != QCBOR_TYPE_MAP) {
+ uErr = 100;
+ goto Done;
+ }
+
+ if(CheckLabelAndType("Manufacturer", QCBOR_TYPE_TEXT_STRING, &Item )) {
+ if(Item.uDataType != QCBOR_TYPE_TEXT_STRING) {
+ return 99; // TODO: what to do on wrong type?
+ } else {
+ // TODO: copy string or change data type
+ }
+
+ } else if(CheckLabel("NumCylinders", &Item)) {
+ if(Item.uDataType != QCBOR_TYPE_INT64) {
+ return 99; // TODO: what to do on wrong type?
+ } else {
+ // TODO: what about overflow
+ pE->uNumCylinders = (uint8_t)Item.val.int64;
+ // TODO: copy string or change data type
+ }
+ } else if(CheckLabel("Cylinders", &Item)) {
+ DecodeCylinders(&DecodeCtx, pE, &Item);
+ }
+
+ }
+
+
+Done:
+ return uErr;
+}
+
+#endif
+
+
+
+
+
+void RunQCborExample()
+{
+ Engine E, DecodedEngine;
+ MakeUsefulBufOnStack( EngineBuffer, 300);
+ UsefulBufC EncodedEngine;
+
+ MakeUsefulBufOnStack( InDefEngineBuffer, 300);
+ UsefulBufC InDefEncodedEngine;
+
+ EngineInit(&E);
+
+ EncodedEngine = EncodeEngine(&E, EngineBuffer);
+
+ printf("Engine Encoded in %zu bytes\n", EncodedEngine.len);
+
+ DecodeEngine(EncodedEngine, &DecodedEngine);
+
+
+ InDefEncodedEngine = EncodeEngineIndefinteLen(&E, InDefEngineBuffer);
+
+ printf("Indef Engine Encoded in %zu bytes\n", InDefEncodedEngine.len);
+
+}
diff --git a/example.h b/example.h
new file mode 100644
index 0000000..ac5caef
--- /dev/null
+++ b/example.h
@@ -0,0 +1,15 @@
+//
+// Header.h
+// Example
+//
+// Created by Laurence Lundblade on 6/30/20.
+// Copyright © 2020 Laurence Lundblade. All rights reserved.
+//
+
+#ifndef Header_h
+#define Header_h
+
+void RunQCborExample(void);
+
+
+#endif /* Header_h */
diff --git a/inc/qcbor/qcbor_decode.h b/inc/qcbor/qcbor_decode.h
index 3961449..9b468cc 100644
--- a/inc/qcbor/qcbor_decode.h
+++ b/inc/qcbor/qcbor_decode.h
@@ -420,6 +420,7 @@
#define QCBOR_CONVERT_TYPE_INT64 0x01
#define QCBOR_CONVERT_TYPE_UINT64 0x02
+#define QCBOR_CONVERT_TYPE_XINT64 0x80 // Type 0 or type 1
#define QCBOR_CONVERT_TYPE_FLOAT 0x04
#define QCBOR_CONVERT_TYPE_DOUBLE 0x40
#define QCBOR_CONVERT_TYPE_BIGFLOAT 0x08
@@ -1090,13 +1091,17 @@
On error, the decoder internal error state is set.
- The CBOR data item to decode must be a positive or negative integer. If not
+ The CBOR data item to decode must be a positive or negative integer (CBOR type 0 or 1). If not
@ref QCBOR_ERR_UNEXPECTED_TYPE is set.
CBOR can represent negative integers further from zero than can be represetned in
an int64_t. @ref QCBOR_ERR_INT_OVERFLOW is set if such input is encountered.
See also QCBORDecode_GetInt64Convert() and QCBORDecode_GetInt64ConvertAll().
+
+
+ A) A separate API for positive than negative
+ B)
*/
static void QCBORDecode_GetInt64(QCBORDecodeContext *pCtx, int64_t *pnValue);
@@ -1174,7 +1179,7 @@
can only decode CBOR positive integers. @ref QCBOR_ERR_NUMBER_SIGN_CONVERSION
is set if the input is a negative integer.
- See also QCBORDecode_GetUint64Convert() and QCBORDecode_GetUint64ConvertAll().
+ See also QCBORDecode_GetUInt64Convert() and QCBORDecode_GetUInt64ConvertAll().
*/
static void QCBORDecode_GetUInt64(QCBORDecodeContext *pCtx, uint64_t *puValue);
@@ -1192,7 +1197,7 @@
sets @ref QCBOR_ERR_NUMBER_SIGN_CONVERSION
is set if the value to be decoded is negatve.
- See also QCBORDecode_GetUint64Convert() and QCBORDecode_GetUint64ConvertAll().
+ See also QCBORDecode_GetUInt64Convert() and QCBORDecode_GetUInt64ConvertAll().
*/
static void QCBORDecode_GetUInt64Convert(QCBORDecodeContext *pCtx, uint32_t uOptions, uint64_t *puValue);
@@ -1210,7 +1215,7 @@
sets @ref QCBOR_ERR_NUMBER_SIGN_CONVERSION
if the value to be decoded is negatve.
- See also QCBORDecode_GetUint64Convert() and QCBORDecode_GetUint64ConvertAll().
+ See also QCBORDecode_GetUInt64Convert() and QCBORDecode_GetUInt64ConvertAll().
*/
void QCBORDecode_GetUInt64ConvertAll(QCBORDecodeContext *pCtx, uint32_t uOptions, uint64_t *puValue);
@@ -1339,46 +1344,59 @@
static void QCBORDecode_GetDateStringInMapN(QCBORDecodeContext *pCtx, uint8_t uTagRequired, int64_t nLabel, UsefulBufC *pValue);
-void QCBORDecode_GetDateStringInMapSZXX(QCBORDecodeContext *pCtx,
+static void QCBORDecode_GetDateStringInMapSZ(QCBORDecodeContext *pCtx,
uint8_t uTagRequired,
const char *szLabel,
UsefulBufC *pValue);
-/*
-@brief Decode the next item as an epoch date.
-
-@param[in] pCtx The decode context.
-@param[in] uTagRequirement One of @c QCBOR_TAGSPEC_MATCH_XXX.
-@param[out] pURI The decoded URI.
-
-Error handling is like QCBORDecode_GetBytes().
-
-See XYZ for discussion on tag requirements.
-*/
-void QCBORDecode_GetEpocDate(QCBORDecodeContext *pCtx, uint8_t uTagRequired, int64_t *puTime);
-
-static void QCBORDecode_GetEpochDateInMapN(QCBORDecodeContext *pCtx, uint8_t uTagRequired, int64_t nLabel, int64_t *puTime);
-
-void QCBORDecode_GetEpochDateInMapSZ(QCBORDecodeContext *pCtx, uint8_t uTagRequired, const char *szLabel, int64_t *puTime);
-
-
/**
-@brief Decode the next item as a big number.
+ @brief Decode the next item as an epoch date.
-@param[in] pCtx The decode context.
-@param[in] uTagRequirement One of @c QCBOR_TAGSPEC_MATCH_XXX.
-@param[out] pValue The big number.
- @param[out] pbIsNegative Is @c true if the big number is negative. This is only
- valid when @c uTagRequirement is @ref QCBOR_TAGSPEC_MATCH_TAG
+ @param[in] pCtx The decode context.
+ @param[in] uTagRequirement One of @c QCBOR_TAGSPEC_MATCH_XXX.
+ @param[out] puTime The decoded URI.
-Error handling is like QCBORDecode_GetBytes().
+ Error handling is like QCBORDecode_GetBytes().
-See XYZ for discussion on tag requirements. If the tag
- requirement is Content type, then there is no indication
- whether the number is positive or negative. The caller
- must know this from context.
+ See XYZ for discussion on tag requirements.
+*/
+void QCBORDecode_GetEpocDate(QCBORDecodeContext *pCtx, uint8_t uTagRequirement, int64_t *puTime);
+
+static void QCBORDecode_GetEpochDateInMapN(QCBORDecodeContext *pCtx, uint8_t uTagRequirement, int64_t nLabel, int64_t *puTime);
+
+void QCBORDecode_GetEpochDateInMapSZ(QCBORDecodeContext *pCtx, uint8_t uTagRequirement, const char *szLabel, int64_t *puTime);
+
+
+/*
+ @brief Decode the next item as a big number.
+
+ @param[in] pCtx The decode context.
+ @param[in] uTagRequirement One of @c QCBOR_TAGSPEC_MATCH_XXX.
+ @param[out] pValue The returned big number.
+ @param[out] pbIsNegative Is @c true if the big number is negative. This
+ is only valid when @c uTagRequirement is
+ @ref QCBOR_TAGSPEC_MATCH_TAG.
+
+ Error handling is like QCBORDecode_GetBytes().
+
+ The big number is in network byte order. The first byte in
+ @c pValue is the most significant byte. There may be leading
+ zeros.
+
+ The negative value is computed as -1 - n, where n is the
+ postive big number in @C pValue.
+
+ See XYZ for discussion on tag requirements.
+
+ Determination of the sign of the big number depends on the
+ tag requirement of the protocol using the big number. If the
+ protocol requires tagging, @ref QCBOR_TAGSPEC_MATCH_TAG,
+ then the sign indication is in the protocol and @c pbIsNegative
+ indicates the sign. If the protocol prohibits tagging,
+ @ref QCBOR_TAGSPEC_MATCH_TAG_CONTENT_TYPE, then the
+ protocol design must have some way of indicating the sign.
*/
void QCBORDecode_GetBignum(QCBORDecodeContext *pCtx,
uint8_t uTagRequirement,
@@ -1398,25 +1416,154 @@
bool *pbIsNegative);
+
+/**
+ @brief Decode the next item as a decimal fraction.
+
+ @param[in] pCtx The decode context.
+ @param[in] uTagRequirement One of @c QCBOR_TAGSPEC_MATCH_XXX.
+ @param[out] pnMantissa The mantissa.
+ @param[out] pnExponent The base 10 exponent.
+
+ Error handling is like QCBORDecode_GetBytes().
+
+ You can compute the value of this by:
+
+ mantissa * ( 10 ** exponent )
+
+ In the encoded CBOR, the mantissa may be a type 0 (unsigned),
+ type 1 (signed integer), type 2 tag xx (positive big number) or
+ type 2 tag xx (negative big number). This implementation will attempt
+ to convert all of these to an int64_t. If the value won't fit,
+ @ref QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW
+ or QCBOR_ERR_BAD_EXP_AND_MANTISSA will be
+ set.
+
+ The encoded CBOR exponent may be a type 0 (unsigned integer)
+ or type 1 (signed integer). This implementation will attempt
+ to convert all of these to an int64_t. If the value won't fit,
+ @ref QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW
+ or QCBOR_ERR_BAD_EXP_AND_MANTISSA will be
+ set.
+
+ Various format and type issues will result in
+ @ref QCBOR_ERR_BAD_EXP_AND_MANTISSA being set.
+
+ See XYZ for discussion on tag requirements.
+*/
void QCBORDecode_GetDecimalFraction(QCBORDecodeContext *pCtx,
uint8_t uTagRequirement,
int64_t *pnMantissa,
int64_t *pnExponent);
+void QCBORDecode_GetDecimalFractionInMapN(QCBORDecodeContext *pCtx,
+ uint8_t uTagRequirement,
+ int64_t nLabel,
+ int64_t *pnMantissa,
+ int64_t *pnExponent);
+
+void QCBORDecode_GetDecimalFractionInMapSZ(QCBORDecodeContext *pMe,
+ uint8_t uTagRequirement,
+ const char *szLabel,
+ int64_t *pnMantissa,
+ int64_t *pnExponent);
+
+
+
+/**
+ @brief Decode the next item as a decimal fraction with a big number mantissa.
+
+ @param[in] pCtx The decode context.
+ @param[in] uTagRequirement One of @c QCBOR_TAGSPEC_MATCH_XXX.
+ @param[in] MantissaBuffer The buffer in which to put the mantissa.
+ @param[out] pMantissa The big num mantissa.
+ @param[out] pbMantissaIsNegative Is @c true if @c pMantissa is negative.
+ @param[out] pnExponent The base 10 exponent.
+
+ Error handling is like QCBORDecode_GetBytes().
+
+ You can compute the value of this by:
+
+ mantissa * ( 10 ** exponent )
+
+ In the encoded CBOR, the mantissa may be a type 0 (unsigned),
+ type 1 (signed integer), type 2 tag xx (positive big number) or
+ type 2 tag xx (negative big number). This implementation will
+ all these to a big number. The limit to this conversion is the
+ size of @c MantissaBuffer.
+
+ The exponent is handled the same as for QCBORDecode_GetDecimalFraction().
+
+ See XYZ for discussion on tag requirements.
+*/
void QCBORDecode_GetDecimalFractionBig(QCBORDecodeContext *pCtx,
uint8_t uTagRequirement,
+ UsefulBuf MantissaBuffer,
UsefulBufC *pMantissa,
+ bool *pbMantissaIsNegative,
int64_t *pnExponent);
+void QCBORDecode_GetDecimalFractionBigInMapN(QCBORDecodeContext *pCtx,
+ uint8_t uTagRequirement,
+ int64_t nLabel,
+ UsefulBuf MantissaBuffer,
+ UsefulBufC *pbMantissaIsNegative,
+ bool *pbIsNegative,
+ int64_t *pnExponent);
+
+void QCBORDecode_GetDecimalFractionBigInMapSZ(QCBORDecodeContext *pCtx,
+ uint8_t uTagRequirement,
+ const char *szLabel,
+ UsefulBuf MantissaBuffer,
+ UsefulBufC *pMantissa,
+ bool *pbMantissaIsNegative,
+ int64_t *pnExponent);
+
+
+
+// TODO: finish these
void QCBORDecode_GetBigFloat(QCBORDecodeContext *pCtx,
uint8_t uTagRequirement,
- int64_t *pnMantissa,
- int64_t *pnExponent);
+ int64_t *pnMantissa,
+ int64_t *pnExponent);
+void QCBORDecode_GetBigFloatInMapN(QCBORDecodeContext *pCtx,
+ uint8_t uTagRequirement,
+ int64_t nLabel,
+ int64_t *pnMantissa,
+ int64_t *pnExponent);
+
+void QCBORDecode_GetBigFloatInMapSZ(QCBORDecodeContext *pCtx,
+ uint8_t uTagRequirement,
+ const char *szLabel,
+ int64_t *pnMantissa,
+ int64_t *pnExponent);
+
+
+// TODO: finish these
void QCBORDecode_GetBigFloatBig(QCBORDecodeContext *pCtx,
uint8_t uTagRequirement,
- UsefulBufC *pMantissa,
- int64_t *pnExponent);
+ UsefulBuf MantissaBuffer,
+ UsefulBufC *pMantissa,
+ bool *pbMantissaIsNegative,
+ int64_t *pnExponent);
+
+void QCBORDecode_GetBigFloatBigInMapN(QCBORDecodeContext *pCtx,
+ uint8_t uTagRequirement,
+ int64_t nLabel,
+ UsefulBuf MantissaBuffer,
+ UsefulBufC *pMantissa,
+ bool *pbMantissaIsNegative,
+ int64_t *pnExponent);
+
+void QCBORDecode_GetBigFloatBigInMapSZ(QCBORDecodeContext *pCtx,
+ uint8_t uTagRequirement,
+ const char *szLabel,
+ UsefulBuf MantissaBuffer,
+ UsefulBufC *pMantissa,
+ bool *pbMantissaIsNegative,
+ int64_t *pnExponent);
+
/*
@brief Decode the next item as a URI.
@@ -1445,7 +1592,7 @@
/*
- @brief Decode the next item as a base64 encoded text.
+ @brief Decode the next item as base64 encoded text.
@param[in] pCtx The decode context.
@param[in] uTagRequirement One of @c QCBOR_TAGSPEC_MATCH_XXX.
@@ -1471,6 +1618,21 @@
const char *szLabel,
UsefulBufC *pB64Text);
+// TODO: docoment these
+static void QCBORDecode_GetB64URL(QCBORDecodeContext *pCtx,
+ uint8_t uTagRequirement,
+ UsefulBufC *pB64Text);
+
+static void QCBORDecode_GetB64URLInMapN(QCBORDecodeContext *pCtx,
+ uint8_t uTagRequirement,
+ int64_t nLabel,
+ UsefulBufC *pB64Text);
+
+static void QCBORDecode_GetB64URLInMapSZ(QCBORDecodeContext *pCtx,
+ uint8_t uTagRequirement,
+ const char *szLabel,
+ UsefulBufC *pB64Text);
+
/*
@brief Decode the next item as a regular expression.
@@ -1519,22 +1681,22 @@
contents of pbIsNot7Bit can be ignored. It may be NULL.
*/
static void QCBORDecode_GetMIMEMessage(QCBORDecodeContext *pMe,
- uint8_t uTagRequirement,
- UsefulBufC *pMessage,
- bool *pbIsNot7Bit);
+ uint8_t uTagRequirement,
+ UsefulBufC *pMessage,
+ bool *pbIsNot7Bit);
static void QCBORDecode_GetMIMEMessageInMapN(QCBORDecodeContext *pMe,
- int64_t nLabel,
- uint8_t uTagRequirement,
- UsefulBufC *pMessage,
- bool *pbIsNot7Bit);
+ int64_t nLabel,
+ uint8_t uTagRequirement,
+ UsefulBufC *pMessage,
+ bool *pbIsNot7Bit);
static void QCBORDecode_GetMIMEMessageInMapSZ(QCBORDecodeContext *pMe,
- const char *szLabel,
- uint8_t uTagRequirement,
- UsefulBufC *pMessage,
- bool *pbIsNot7Bit);
+ const char *szLabel,
+ uint8_t uTagRequirement,
+ UsefulBufC *pMessage,
+ bool *pbIsNot7Bit);
/*
@brief Decode the next item as a UUID
@@ -1629,7 +1791,7 @@
/**
- @brief Decode some byte-string wrapped CBOR
+ @brief Decode some byte-string wrapped CBOR.
@param[in] pCtx The decode context.
@param[in] uTagRequirement Whether or not the byte string must be tagged.
@@ -1779,8 +1941,6 @@
provides no way to descend into and decode them. Use
QCBORDecode_EnterMapinMapN(), QCBORDecode_EnterArrayInMapN()
and such to decsend into and process maps and arrays.
-
- TODO: what does this do on arrays?
*/
QCBORError QCBORDecode_GetItemsInMap(QCBORDecodeContext *pCtx, QCBORItem *pItemList);
@@ -2095,17 +2255,17 @@
inline static void QCBORDecode_GetInt64(QCBORDecodeContext *pMe, int64_t *pnValue)
{
- QCBORDecode_GetInt64Convert(pMe, QCBOR_CONVERT_TYPE_INT64, pnValue);
+ QCBORDecode_GetInt64Convert(pMe, QCBOR_CONVERT_TYPE_XINT64, pnValue);
}
inline static void QCBORDecode_GetInt64InMapN(QCBORDecodeContext *pMe, int64_t nLabel, int64_t *pnValue)
{
- QCBORDecode_GetInt64ConvertInMapN(pMe, nLabel, QCBOR_CONVERT_TYPE_INT64, pnValue);
+ QCBORDecode_GetInt64ConvertInMapN(pMe, nLabel, QCBOR_CONVERT_TYPE_XINT64, pnValue);
}
inline static void QCBORDecode_GetInt64InMapSZ(QCBORDecodeContext *pMe, const char *szLabel, int64_t *pnValue)
{
- QCBORDecode_GetInt64ConvertInMapSZ(pMe, szLabel, QCBOR_CONVERT_TYPE_INT64, pnValue);
+ QCBORDecode_GetInt64ConvertInMapSZ(pMe, szLabel, QCBOR_CONVERT_TYPE_XINT64, pnValue);
}
@@ -2142,65 +2302,23 @@
static inline void QCBORDecode_GetUInt64(QCBORDecodeContext *pMe, uint64_t *puValue)
{
- QCBORDecode_GetUInt64Convert(pMe, QCBOR_CONVERT_TYPE_UINT64, puValue);
+ QCBORDecode_GetUInt64Convert(pMe, QCBOR_CONVERT_TYPE_XINT64, puValue);
}
inline static void QCBORDecode_GetUInt64InMapN(QCBORDecodeContext *pMe, int64_t nLabel, uint64_t *puValue)
{
- QCBORDecode_GetUInt64ConvertInMapN(pMe, nLabel, QCBOR_CONVERT_TYPE_UINT64, puValue);
+ QCBORDecode_GetUInt64ConvertInMapN(pMe, nLabel, QCBOR_CONVERT_TYPE_XINT64, puValue);
}
inline static void QCBORDecode_GetUInt64InMapSZ(QCBORDecodeContext *pMe, const char *szLabel, uint64_t *puValue)
{
- QCBORDecode_GetUInt64ConvertInMapSZ(pMe, szLabel, QCBOR_CONVERT_TYPE_UINT64, puValue);
+ QCBORDecode_GetUInt64ConvertInMapSZ(pMe, szLabel, QCBOR_CONVERT_TYPE_XINT64, puValue);
}
-void QCBORDecode_GetInt8ConvertInternal(QCBORDecodeContext *pMe, uint32_t uOptions, int8_t *pnValue, QCBORItem *pItem);
-
-void QCBORDecode_GetInt8ConvertInternalInMapN(QCBORDecodeContext *pMe, int64_t nLabel, uint32_t uOptions, int8_t *pnValue, QCBORItem *pItem);
-
-void QCBORDecode_GetInt8ConvertInternalInMapSZ(QCBORDecodeContext *pMe, const char *szLabel, uint32_t uOptions, int8_t *pnValue, QCBORItem *pItem);
-
-
-inline static void QCBORDecode_GetInt8Convert(QCBORDecodeContext *pMe, uint32_t uOptions, int8_t *pnValue)
-{
- QCBORItem Item;
- QCBORDecode_GetInt8ConvertInternal(pMe, uOptions, pnValue, &Item);
-}
-
-inline static void QCBORDecode_GetInt8ConvertInMapN(QCBORDecodeContext *pMe, int64_t nLabel, uint32_t uOptions, int8_t *pnValue)
-{
- QCBORItem Item;
- QCBORDecode_GetInt8ConvertInternalInMapN(pMe, nLabel, uOptions, pnValue, &Item);
-}
-
-inline static void QCBORDecode_GetInt8ConvertInMapSZ(QCBORDecodeContext *pMe, const char *szLabel, uint32_t uOptions, int8_t *pnValue)
-{
- QCBORItem Item;
- QCBORDecode_GetInt8ConvertInternalInMapSZ(pMe, szLabel, uOptions, pnValue, &Item);
-}
-
-inline static void QCBORDecode_GetInt8(QCBORDecodeContext *pMe, int8_t *pnValue)
-{
- QCBORDecode_GetInt8Convert(pMe, QCBOR_CONVERT_TYPE_INT64, pnValue);
-}
-
-inline static void QCBORDecode_GetInt8InMapN(QCBORDecodeContext *pMe, int64_t nLabel, int8_t *pnValue)
-{
- QCBORDecode_GetInt8ConvertInMapN(pMe, nLabel, QCBOR_CONVERT_TYPE_INT64, pnValue);
-}
-
-inline static void QCBORDecode_GetInt8InMapSZ(QCBORDecodeContext *pMe, const char *szLabel, int8_t *pnValue)
-{
- QCBORDecode_GetInt8ConvertInMapSZ(pMe, szLabel, QCBOR_CONVERT_TYPE_INT64, pnValue);
-}
-
-
-
void QCBORDecode_GetDoubleConvertInternal(QCBORDecodeContext *pMe, uint32_t uOptions, double *pValue, QCBORItem *pItem);
void QCBORDecode_GetDoubleConvertInternalInMapN(QCBORDecodeContext *pMe, int64_t nLabel, uint32_t uOptions, double *pdValue, QCBORItem *pItem);
@@ -2475,6 +2593,44 @@
}
+static inline void QCBORDecode_GetB64URL(QCBORDecodeContext *pMe,
+ uint8_t uTagRequirement,
+ UsefulBufC *pB64Text)
+{
+ const TagSpecification TagSpec = {uTagRequirement,
+ {QCBOR_TYPE_BASE64URL, QCBOR_TYPE_NONE, QCBOR_TYPE_NONE},
+ {QCBOR_TYPE_TEXT_STRING, QCBOR_TYPE_NONE, QCBOR_TYPE_NONE}
+ };
+
+ QCBORDecode_GetTaggedStringInternal(pMe, TagSpec, pB64Text);
+}
+
+
+inline static void QCBORDecode_GetB64URLInMapN(QCBORDecodeContext *pMe,
+ uint8_t uTagRequirement,
+ int64_t nLabel,
+ UsefulBufC *pB64Text)
+{
+ const TagSpecification TagSpec = {uTagRequirement,
+ {QCBOR_TYPE_BASE64URL, QCBOR_TYPE_NONE, QCBOR_TYPE_NONE},
+ {QCBOR_TYPE_TEXT_STRING, QCBOR_TYPE_NONE, QCBOR_TYPE_NONE}
+ };
+
+ QCBORDecode_GetTaggedStringInMapN(pMe, nLabel, TagSpec, pB64Text);
+}
+
+inline static void QCBORDecode_GetB64URLInMapSZ(QCBORDecodeContext *pMe,
+ uint8_t uTagRequirement,
+ const char *szLabel,
+ UsefulBufC *pB64Text)
+{
+ const TagSpecification TagSpec = {uTagRequirement,
+ {QCBOR_TYPE_BASE64URL, QCBOR_TYPE_NONE, QCBOR_TYPE_NONE},
+ {QCBOR_TYPE_TEXT_STRING, QCBOR_TYPE_NONE, QCBOR_TYPE_NONE}
+ };
+ QCBORDecode_GetTaggedStringInMapSZ(pMe, szLabel, TagSpec, pB64Text);
+}
+
static inline void QCBORDecode_GetRegex(QCBORDecodeContext *pMe,
uint8_t uTagRequirement,
diff --git a/src/qcbor_decode.c b/src/qcbor_decode.c
index f9ab55b..549bbbc 100644
--- a/src/qcbor_decode.c
+++ b/src/qcbor_decode.c
@@ -3479,7 +3479,7 @@
break;
case QCBOR_TYPE_INT64:
- if(uOptions & QCBOR_CONVERT_TYPE_INT64) {
+ if(uOptions & QCBOR_CONVERT_TYPE_XINT64) {
*pnValue = pItem->val.int64;
} else {
return QCBOR_ERR_CONVERSION_NOT_REQUESTED;
@@ -3487,7 +3487,7 @@
break;
case QCBOR_TYPE_UINT64:
- if(uOptions & QCBOR_CONVERT_TYPE_UINT64) {
+ if(uOptions & QCBOR_CONVERT_TYPE_XINT64) {
if(pItem->val.uint64 < INT64_MAX) {
*pnValue = pItem->val.int64;
} else {
@@ -3764,7 +3764,7 @@
{
switch(pItem->uDataType) {
// TODO: type flaot
- case QCBOR_TYPE_DOUBLE:
+ case QCBOR_CONVERT_TYPE_DOUBLE:
if(uOptions & QCBOR_CONVERT_TYPE_FLOAT) {
feclearexcept(FE_ALL_EXCEPT);
double dRounded = round(pItem->val.dfnum);
@@ -3786,7 +3786,7 @@
break;
case QCBOR_TYPE_INT64:
- if(uOptions & QCBOR_CONVERT_TYPE_INT64) {
+ if(uOptions & QCBOR_CONVERT_TYPE_XINT64) {
if(pItem->val.int64 >= 0) {
*puValue = (uint64_t)pItem->val.int64;
} else {
@@ -3798,7 +3798,7 @@
break;
case QCBOR_TYPE_UINT64:
- if(uOptions & QCBOR_CONVERT_TYPE_UINT64) {
+ if(uOptions & QCBOR_CONVERT_TYPE_XINT64) {
*puValue = pItem->val.uint64;
} else {
return QCBOR_ERR_CONVERSION_NOT_REQUESTED;
@@ -3894,7 +3894,7 @@
}
-void QCBORDecode_GetUint64ConvertInternalInMapSZ(QCBORDecodeContext *pMe,
+void QCBORDecode_GetUInt64ConvertInternalInMapSZ(QCBORDecodeContext *pMe,
const char * szLabel,
uint32_t uOptions,
uint64_t *puValue,
@@ -4068,7 +4068,7 @@
void QCBORDecode_GetUint64ConvertAllInMapSZ(QCBORDecodeContext *pMe, const char *szLabel, uint32_t uOptions, uint64_t *puValue)
{
QCBORItem Item;
- QCBORDecode_GetUint64ConvertInternalInMapSZ(pMe, szLabel, uOptions, puValue, &Item);
+ QCBORDecode_GetUInt64ConvertInternalInMapSZ(pMe, szLabel, uOptions, puValue, &Item);
if(pMe->uLastError == QCBOR_SUCCESS) {
// The above conversion succeeded
@@ -4364,19 +4364,25 @@
#ifndef QCBOR_CONFIG_DISABLE_EXP_AND_MANTISSA
-void FarfDecimalFraction(QCBORDecodeContext *pMe,
- uint8_t uTagRequirement,
- QCBORItem *pItem,
- int64_t *pnMantissa,
- int64_t *pnExponent)
+static void ProcessDecimalFraction(QCBORDecodeContext *pMe,
+ uint8_t uTagRequirement,
+ QCBORItem *pItem,
+ int64_t *pnMantissa,
+ int64_t *pnExponent)
{
QCBORError uErr;
if(pItem->uDataType == QCBOR_TYPE_ARRAY) {
+
if(uTagRequirement == QCBOR_TAGSPEC_MATCH_TAG_CONTENT_TYPE) {
pMe->uLastError = QCBOR_ERR_UNEXPECTED_TYPE;
return;
}
+ /* The decimal fraction was untagged so it shows up as an
+ array at this point. We are called to interpret it
+ as a decimal fraction, so do protocol decoding. If
+ it was tagged, iw would shouw up here with the
+ QCBOR_TYPE_DECIMAL_FRACTION or such. */
uErr = QCBORDecode_MantissaAndExponent(pMe, pItem);
if(uErr != QCBOR_SUCCESS) {
pMe->uLastError = (uint8_t)uErr;
@@ -4419,7 +4425,28 @@
}
}
-void QCBORDecode_GetDecimalFractionN(QCBORDecodeContext *pMe,
+
+void QCBORDecode_GetDecimalFraction(QCBORDecodeContext *pMe,
+ uint8_t uTagRequirement,
+ int64_t *pnMantissa,
+ int64_t *pnExponent)
+{
+ if(pMe->uLastError != QCBOR_SUCCESS) {
+ return;
+ }
+
+ QCBORItem Item;
+ QCBORError uError = QCBORDecode_GetNext(pMe, &Item);
+ if(uError) {
+ pMe->uLastError = (uint8_t)uError;
+ return;
+ }
+
+ ProcessDecimalFraction(pMe, uTagRequirement, &Item, pnMantissa, pnExponent);
+}
+
+
+void QCBORDecode_GetDecimalFractionInMapN(QCBORDecodeContext *pMe,
uint8_t uTagRequirement,
int64_t nLabel,
int64_t *pnMantissa,
@@ -4428,22 +4455,21 @@
QCBORItem Item;
QCBORDecode_GetItemInMapN(pMe, nLabel, QCBOR_TYPE_ANY, &Item);
- FarfDecimalFraction(pMe, uTagRequirement, &Item, pnMantissa, pnExponent);
+ ProcessDecimalFraction(pMe, uTagRequirement, &Item, pnMantissa, pnExponent);
}
-
-void QCBORDecode_GetDecimalFractionSZ(QCBORDecodeContext *pMe,
- uint8_t uTagRequirement,
- const char *szLabel,
- int64_t *pnMantissa,
- int64_t *pnExponent)
+void QCBORDecode_GetDecimalFractionInMapSZ(QCBORDecodeContext *pMe,
+ uint8_t uTagRequirement,
+ const char *szLabel,
+ int64_t *pnMantissa,
+ int64_t *pnExponent)
{
QCBORItem Item;
QCBORDecode_GetItemInMapSZ(pMe, szLabel, QCBOR_TYPE_ANY, &Item);
- FarfDecimalFraction(pMe, uTagRequirement, &Item, pnMantissa, pnExponent);
+ ProcessDecimalFraction(pMe, uTagRequirement, &Item, pnMantissa, pnExponent);
}
#endif /* ndef QCBOR_CONFIG_DISABLE_EXP_AND_MANTISSA */
@@ -4469,73 +4495,128 @@
#ifndef QCBOR_CONFIG_DISABLE_EXP_AND_MANTISSA
-void QCBORDecode_GetDecimalFractionBigN(QCBORDecodeContext *pMe,
- uint8_t uTagRequirement,
- int64_t nLabel,
- UsefulBuf pBufferForMantissa,
- UsefulBufC *pMantissa,
- bool *pbIsNegative,
- int64_t *pnExponent)
+static void ProcessDecimalFractionBig(QCBORDecodeContext *pMe,
+ uint8_t uTagRequirement,
+ QCBORItem *pItem,
+ UsefulBuf BufferForMantissa,
+ UsefulBufC *pMantissa,
+ bool *pbIsNegative,
+ int64_t *pnExponent)
+{
+
+ const TagSpecification TagSpec = {uTagRequirement,
+ {QCBOR_TYPE_DECIMAL_FRACTION, QCBOR_TYPE_DECIMAL_FRACTION_POS_BIGNUM, QCBOR_TYPE_DECIMAL_FRACTION_NEG_BIGNUM},
+ {QCBOR_TYPE_ARRAY, QCBOR_TYPE_NONE, QCBOR_TYPE_NONE}
+ };
+
+ QCBORError uErr = CheckTagRequirement(TagSpec, pItem->uDataType);
+ if(uErr != QCBOR_SUCCESS) {
+ pMe->uLastError = (uint8_t)uErr;
+ return;
+ }
+
+ if(pItem->uDataType == QCBOR_TYPE_ARRAY) {
+ uErr = QCBORDecode_MantissaAndExponent(pMe, pItem);
+ if(uErr != QCBOR_SUCCESS) {
+ pMe->uLastError = (uint8_t)uErr;
+ return;
+ }
+ }
+
+ uint64_t uMantissa;
+
+ switch (pItem->uDataType) {
+
+ case QCBOR_TYPE_DECIMAL_FRACTION:
+ if(pItem->val.expAndMantissa.Mantissa.nInt >= 0) {
+ uMantissa = (uint64_t)pItem->val.expAndMantissa.Mantissa.nInt;
+ *pbIsNegative = false;
+ } else {
+ uMantissa = (uint64_t)-pItem->val.expAndMantissa.Mantissa.nInt;
+ *pbIsNegative = true;
+ }
+ *pMantissa = ConvertIntToBigNum(uMantissa, BufferForMantissa);
+ *pnExponent = pItem->val.expAndMantissa.nExponent;
+ break;
+
+ case QCBOR_TYPE_DECIMAL_FRACTION_POS_BIGNUM:
+ *pnExponent = pItem->val.expAndMantissa.nExponent;
+ *pMantissa = pItem->val.expAndMantissa.Mantissa.bigNum;
+ *pbIsNegative = false;
+ break;
+
+ case QCBOR_TYPE_DECIMAL_FRACTION_NEG_BIGNUM:
+ *pnExponent = pItem->val.expAndMantissa.nExponent;
+ *pMantissa = pItem->val.expAndMantissa.Mantissa.bigNum;
+ *pbIsNegative = true;
+ break;
+
+ default:
+ pMe->uLastError = QCBOR_ERR_UNEXPECTED_TYPE;
+ }
+}
+
+
+void QCBORDecode_GetDecimalFractionBig(QCBORDecodeContext *pMe,
+ uint8_t uTagRequirement,
+ UsefulBuf MantissaBuffer,
+ UsefulBufC *pMantissa,
+ bool *pbMantissaIsNegative,
+ int64_t *pnExponent)
+{
+
+ if(pMe->uLastError != QCBOR_SUCCESS) {
+ return;
+ }
+
+ QCBORItem Item;
+ QCBORError uError = QCBORDecode_GetNext(pMe, &Item);
+ if(uError) {
+ pMe->uLastError = (uint8_t)uError;
+ return;
+ }
+
+ ProcessDecimalFractionBig(pMe, uTagRequirement, &Item, MantissaBuffer, pMantissa, pbMantissaIsNegative, pnExponent);
+
+}
+
+void QCBORDecode_GetDecimalFractionBigInMapN(QCBORDecodeContext *pMe,
+ uint8_t uTagRequirement,
+ int64_t nLabel,
+ UsefulBuf BufferForMantissa,
+ UsefulBufC *pMantissa,
+ bool *pbIsNegative,
+ int64_t *pnExponent)
{
QCBORItem Item;
- QCBORError uErr;
QCBORDecode_GetItemInMapN(pMe, nLabel, QCBOR_TYPE_ANY, &Item);
if(pMe->uLastError != QCBOR_SUCCESS) {
return;
}
- const TagSpecification TagSpec = {uTagRequirement,
- {QCBOR_TYPE_DECIMAL_FRACTION, QCBOR_TYPE_DECIMAL_FRACTION_POS_BIGNUM, QCBOR_TYPE_DECIMAL_FRACTION_NEG_BIGNUM},
- {QCBOR_TYPE_ARRAY, QCBOR_TYPE_NONE, QCBOR_TYPE_NONE}
- };
+ ProcessDecimalFractionBig(pMe, uTagRequirement, &Item, BufferForMantissa, pMantissa, pbIsNegative, pnExponent);
+}
- uErr = CheckTagRequirement(TagSpec, Item.uDataType);
- if(uErr != QCBOR_SUCCESS) {
- pMe->uLastError = (uint8_t)uErr;
+
+void QCBORDecode_GetDecimalFractionBigInMapSZ(QCBORDecodeContext *pMe,
+ uint8_t uTagRequirement,
+ const char *szLabel,
+ UsefulBuf BufferForMantissa,
+ UsefulBufC *pMantissa,
+ bool *pbIsNegative,
+ int64_t *pnExponent)
+{
+ QCBORItem Item;
+
+ QCBORDecode_GetItemInMapSZ(pMe, szLabel, QCBOR_TYPE_ANY, &Item);
+ if(pMe->uLastError != QCBOR_SUCCESS) {
return;
}
-
- if(Item.uDataType == QCBOR_TYPE_ARRAY) {
- uErr = QCBORDecode_MantissaAndExponent(pMe, &Item);
- if(uErr != QCBOR_SUCCESS) {
- pMe->uLastError = (uint8_t)uErr;
- return;
- }
- }
-
- uint64_t uMantissa;
-
- switch (Item.uDataType) {
-
- case QCBOR_TYPE_DECIMAL_FRACTION:
- if(Item.val.expAndMantissa.Mantissa.nInt >= 0) {
- uMantissa = (uint64_t)Item.val.expAndMantissa.Mantissa.nInt;
- *pbIsNegative = false;
- } else {
- uMantissa = (uint64_t)-Item.val.expAndMantissa.Mantissa.nInt;
- *pbIsNegative = true;
- }
- *pMantissa = ConvertIntToBigNum(uMantissa, pBufferForMantissa);
- *pnExponent = Item.val.expAndMantissa.nExponent;
- break;
-
- case QCBOR_TYPE_DECIMAL_FRACTION_POS_BIGNUM:
- *pnExponent = Item.val.expAndMantissa.nExponent;
- *pMantissa = Item.val.expAndMantissa.Mantissa.bigNum;
- *pbIsNegative = false;
- break;
- case QCBOR_TYPE_DECIMAL_FRACTION_NEG_BIGNUM:
- *pnExponent = Item.val.expAndMantissa.nExponent;
- *pMantissa = Item.val.expAndMantissa.Mantissa.bigNum;
- *pbIsNegative = true;
- break;
-
- default:
- pMe->uLastError = QCBOR_ERR_UNEXPECTED_TYPE;
- }
+ ProcessDecimalFractionBig(pMe, uTagRequirement, &Item, BufferForMantissa, pMantissa, pbIsNegative, pnExponent);
}
+
#endif /* ndef QCBOR_CONFIG_DISABLE_EXP_AND_MANTISSA */
/*