34#ifndef qcbor_main_encode_h
35#define qcbor_main_encode_h
39#include "qcbor/qcbor_private.h"
143#define QCBOR_HEAD_BUFFER_SIZE (sizeof(uint64_t) + 2)
671 const uint8_t uSimple);
676 const int64_t nLabel,
677 const uint8_t uSimple);
835 const char *szLabel);
871 const char *szLabel);
1339 const char *szLabel,
1340 const uint8_t uSimple);
1353 const char *szLabel);
1358 const char *szLabel);
1382 const uint8_t uMajorType,
1383 const uint64_t uArgument,
1384 const uint8_t uMinLen);
1395 uint8_t uMajorType);
1400 uint8_t uMajorType);
1405 uint8_t uMajorType);
1410 uint8_t uMajorType);
1439 const uint8_t uMinLen,
1440 const uint64_t uArgument)
1442 QCBOREncode_Private_AppendCBORHead(pMe, CBOR_MAJOR_TYPE_SIMPLE, uArgument, uMinLen);
1458 pMe->pfnCloseMap = QCBOREncode_Private_CloseMapUnsorted;
1460 pMe->uConfigFlags = (int)uConfig;
1470 pMe->uConfigFlags = (int)uConfig;
1479 QCBOREncode_Private_AddBuffer(pMe, CBOR_MAJOR_TYPE_TEXT_STRING, Text);
1484 const char *szLabel,
1499 const int64_t nLabel,
1502 QCBOREncode_AddInt64(pMe, nLabel);
1515 const char *szLabel,
1516 const char *szString)
1530 const int64_t nLabel,
1531 const char *szString)
1533 QCBOREncode_AddInt64(pMe, nLabel);
1544 QCBOREncode_Private_AddBuffer(pMe, CBOR_MAJOR_TYPE_BYTE_STRING, Bytes);
1549 const char *szLabel,
1564 const int64_t nLabel,
1567 QCBOREncode_AddInt64(pMe, nLabel);
1573 const char *szLabel,
1582 const int64_t nLabel,
1585 QCBOREncode_AddInt64(pMe, nLabel);
1593#ifndef QCBOR_DISABLE_ENCODE_USAGE_GUARDS
1595 if(uNum < CBOR_SIMPLEV_FALSE || uNum > CBOR_SIMPLEV_NULL) {
1601 if(uNum >= CBOR_SIMPLEV_RESERVED_START && uNum <= CBOR_SIMPLEV_RESERVED_END) {
1607 QCBOREncode_Private_AddType7(pMe, 0, uNum);
1612 const char *szLabel,
1613 const uint8_t uSimple)
1621 const char *szLabel,
1622 const uint8_t uSimple)
1629 const int64_t nLabel,
1630 const uint8_t uSimple)
1632 QCBOREncode_AddInt64(pMe, nLabel);
1640 uint8_t uSimple = CBOR_SIMPLEV_FALSE;
1642 uSimple = CBOR_SIMPLEV_TRUE;
1663 QCBOREncode_AddInt64(pMe, nLabel);
1690 QCBOREncode_AddInt64(pMe, nLabel);
1717 QCBOREncode_AddInt64(pMe, nLabel);
1725 QCBOREncode_Private_OpenMapOrArray(pMe, CBOR_MAJOR_TYPE_ARRAY);
1745 QCBOREncode_AddInt64(pMe, nLabel);
1753 QCBOREncode_Private_CloseMapOrArray(pMe, CBOR_MAJOR_TYPE_ARRAY);
1760 QCBOREncode_Private_OpenMapOrArray(pMe, CBOR_MAJOR_TYPE_MAP);
1779 QCBOREncode_AddInt64(pMe, nLabel);
1786 (pMe->pfnCloseMap)(pMe);
1792 QCBOREncode_Private_OpenMapOrArrayIndefiniteLength(pMe, CBOR_MAJOR_NONE_TYPE_ARRAY_INDEFINITE_LEN);
1797 const char *szLabel)
1805 const char *szLabel)
1812 const int64_t nLabel)
1814 QCBOREncode_AddInt64(pMe, nLabel);
1821 QCBOREncode_Private_CloseMapOrArrayIndefiniteLength(pMe, CBOR_MAJOR_NONE_TYPE_ARRAY_INDEFINITE_LEN);
1828 QCBOREncode_Private_OpenMapOrArrayIndefiniteLength(pMe, CBOR_MAJOR_NONE_TYPE_MAP_INDEFINITE_LEN);
1833 const char *szLabel)
1841 const char *szLabel)
1848 const int64_t nLabel)
1850 QCBOREncode_AddInt64(pMe, nLabel);
1857 QCBOREncode_Private_CloseMapOrArrayIndefiniteLength(pMe, CBOR_MAJOR_NONE_TYPE_MAP_INDEFINITE_LEN);
1864 QCBOREncode_Private_OpenMapOrArray(pMe, CBOR_MAJOR_TYPE_BYTE_STRING);
1883 QCBOREncode_AddInt64(pMe, nLabel);
1897 const char *szLabel,
1912 const int64_t nLabel,
1915 QCBOREncode_AddInt64(pMe, nLabel);
static size_t UsefulOutBuf_GetEndPosition(UsefulOutBuf *pUOutBuf)
Returns position of end of data in the UsefulOutBuf.
Definition UsefulBuf.h:2138
static UsefulBufC UsefulBuf_FromSZ(const char *szString)
Convert a NULL-terminated string to a UsefulBufC.
Definition UsefulBuf.h:1995
static UsefulBuf UsefulOutBuf_RetrieveOutputStorage(UsefulOutBuf *pUOutBuf)
Retrieve the storage buffer passed in to UsefulOutBuf_Init().
Definition UsefulBuf.h:2434
static int UsefulOutBuf_IsBufferNULL(UsefulOutBuf *pUOutBuf)
Returns 1 if buffer given to UsefulOutBuf_Init() was NULL.
Definition UsefulBuf.h:2413
static int UsefulOutBuf_GetError(UsefulOutBuf *pUOutBuf)
Returns the current error status.
Definition UsefulBuf.h:2395
QCBORError
Definition qcbor_common.h:260
@ QCBOR_ERR_NOT_PREFERRED
Definition qcbor_common.h:554
@ QCBOR_ERR_NOT_ALLOWED
Definition qcbor_common.h:557
@ QCBOR_ERR_ENCODE_UNSUPPORTED
Definition qcbor_common.h:270
@ QCBOR_ERR_BUFFER_TOO_SMALL
Definition qcbor_common.h:266
QCBORError QCBOREncode_FinishGetSize(QCBOREncodeContext *pCtx, size_t *uEncodedLen)
Get the encoded CBOR and error status.
static void QCBOREncode_OpenMapInMapN(QCBOREncodeContext *pCtx, int64_t nLabel)
Definition qcbor_main_encode.h:1777
static void QCBOREncode_OpenMapInMap(QCBOREncodeContext *pCtx, const char *szLabel)
Definition qcbor_main_encode.h:1771
struct _QCBOREncodeContext QCBOREncodeContext
Definition qcbor_main_encode.h:311
static void QCBOREncode_AddUndefToMap(QCBOREncodeContext *pCtx, const char *szLabel)
Definition qcbor_main_encode.h:1709
static void QCBOREncode_OpenArrayIndefiniteLengthInMapN(QCBOREncodeContext *pCtx, int64_t nLabel)
Definition qcbor_main_encode.h:1811
static void QCBOREncode_AddNULLToMap(QCBOREncodeContext *pCtx, const char *szLabel)
Definition qcbor_main_encode.h:1682
static void QCBOREncode_OpenArray(QCBOREncodeContext *pCtx)
Indicates that the next items added are in an array.
Definition qcbor_main_encode.h:1723
static void QCBOREncode_AddEncodedToMapN(QCBOREncodeContext *pCtx, int64_t nLabel, UsefulBufC Encoded)
Definition qcbor_main_encode.h:1911
UsefulBufC QCBOREncode_EncodeHead(UsefulBuf Buffer, uint8_t uMajorType, uint8_t uMinLen, uint64_t uNumber)
Encode the head of a CBOR data item.
static void QCBOREncode_AddSimpleToMapSZ(QCBOREncodeContext *pCtx, const char *szLabel, const uint8_t uSimple)
Definition qcbor_main_encode.h:1611
static void QCBOREncode_AddBoolToMapN(QCBOREncodeContext *pCtx, int64_t nLabel, bool b)
Definition qcbor_main_encode.h:1661
static void QCBOREncode_OpenMapIndefiniteLength(QCBOREncodeContext *pCtx)
Indicates that the next items added are in an indefinite length map.
Definition qcbor_main_encode.h:1826
static void QCBOREncode_OpenArrayIndefiniteLengthInMap(QCBOREncodeContext *pCtx, const char *szLabel)
Definition qcbor_main_encode.h:1804
QCBOREncodeConfig
Definition qcbor_main_encode.h:151
@ QCBOR_ENCODE_CONFIG_PREFERRED
Definition qcbor_main_encode.h:240
@ QCBOR_ENCODE_CONFIG_DISALLOW_INDEFINITE_LENGTHS
Definition qcbor_main_encode.h:192
@ QCBOR_ENCODE_CONFIG_SORT
Definition qcbor_main_encode.h:164
@ QCBOR_ENCODE_CONFIG_ONLY_DCBOR_SIMPLE
Definition qcbor_main_encode.h:205
@ QCBOR_ENCODE_CONFIG_CDE
Definition qcbor_main_encode.h:261
@ QCBOR_ENCODE_CONFIG_DCBOR
Definition qcbor_main_encode.h:296
@ QCBOR_ENCODE_CONFIG_DISALLOW_NON_PREFERRED_NUMBERS
Definition qcbor_main_encode.h:198
@ QCBOR_ENCODE_CONFIG_ALLOW_NAN_PAYLOAD
Definition qcbor_main_encode.h:171
@ QCBOR_ENCODE_CONFIG_FLOAT_REDUCTION
Definition qcbor_main_encode.h:188
@ QCBOR_ENCODE_CONFIG_ONLY_PREFERRED_BIG_NUMBERS
Definition qcbor_main_encode.h:212
static void QCBOREncode_OpenArrayIndefiniteLength(QCBOREncodeContext *pCtx)
Indicates that the next items added are in an indefinite length array.
Definition qcbor_main_encode.h:1790
static void QCBOREncode_OpenArrayInMapN(QCBOREncodeContext *pCtx, int64_t nLabel)
Definition qcbor_main_encode.h:1743
static void QCBOREncode_AddUndefToMapSZ(QCBOREncodeContext *pCtx, const char *szLabel)
Definition qcbor_main_encode.h:1702
static void QCBOREncode_AddBytesToMapN(QCBOREncodeContext *pCtx, int64_t nLabel, UsefulBufC Bytes)
Definition qcbor_main_encode.h:1563
void QCBOREncode_AddEncoded(QCBOREncodeContext *pCtx, UsefulBufC Encoded)
Add some already-encoded CBOR bytes.
static void QCBOREncode_BstrWrapInMapN(QCBOREncodeContext *pCtx, int64_t nLabel)
Definition qcbor_main_encode.h:1881
static void QCBOREncode_AddBool(QCBOREncodeContext *pCtx, bool b)
Add a standard Boolean.
Definition qcbor_main_encode.h:1638
static void QCBOREncode_OpenBytesInMapSZ(QCBOREncodeContext *pCtx, const char *szLabel, UsefulBuf *pPlace)
Definition qcbor_main_encode.h:1572
void QCBOREncode_CancelBstrWrap(QCBOREncodeContext *pCtx)
Cancel byte string wrapping.
static void QCBOREncode_OpenMapInMapSZ(QCBOREncodeContext *pCtx, const char *szLabel)
Definition qcbor_main_encode.h:1764
static void QCBOREncode_AddEncodedToMapSZ(QCBOREncodeContext *pCtx, const char *szLabel, UsefulBufC Encoded)
Definition qcbor_main_encode.h:1896
static QCBORError QCBOREncode_GetErrorState(QCBOREncodeContext *pCtx)
Get the encoding error state.
Definition qcbor_main_encode.h:1935
void QCBOREncode_CloseBytes(QCBOREncodeContext *pCtx, size_t uAmount)
Close out a byte string written directly to encoded output.
static void QCBOREncode_OpenArrayIndefiniteLengthInMapSZ(QCBOREncodeContext *pCtx, const char *szLabel)
Definition qcbor_main_encode.h:1796
static void QCBOREncode_AddTextToMapSZ(QCBOREncodeContext *pCtx, const char *szLabel, UsefulBufC Text)
Definition qcbor_main_encode.h:1483
void QCBOREncode_CloseAndSortMap(QCBOREncodeContext *pCtx)
Close and sort an open map.
static void QCBOREncode_OpenMapIndefiniteLengthInMapN(QCBOREncodeContext *pCtx, int64_t nLabel)
Definition qcbor_main_encode.h:1847
static void QCBOREncode_AddSimple(QCBOREncodeContext *pCtx, const uint8_t uNum)
Add a simple value.
Definition qcbor_main_encode.h:1591
static void QCBOREncode_AddSZStringToMap(QCBOREncodeContext *pCtx, const char *szLabel, const char *szString)
Definition qcbor_main_encode.h:1523
static void QCBOREncode_AddSimpleToMap(QCBOREncodeContext *pCtx, const char *szLabel, const uint8_t uSimple)
Definition qcbor_main_encode.h:1620
static void QCBOREncode_AddBoolToMap(QCBOREncodeContext *pCtx, const char *szLabel, bool b)
Definition qcbor_main_encode.h:1655
static void QCBOREncode_OpenBytesInMapN(QCBOREncodeContext *pCtx, int64_t nLabel, UsefulBuf *pPlace)
Definition qcbor_main_encode.h:1581
static void QCBOREncode_BstrWrapInMap(QCBOREncodeContext *pCtx, const char *szLabel)
Definition qcbor_main_encode.h:1875
static void QCBOREncode_CloseBstrWrap(QCBOREncodeContext *pCtx, UsefulBufC *pWrappedCBOR)
Definition qcbor_main_encode.h:1888
static void QCBOREncode_CloseMap(QCBOREncodeContext *pCtx)
Close an open map.
Definition qcbor_main_encode.h:1784
UsefulBufC QCBOREncode_SubString(QCBOREncodeContext *pCtx, const size_t uStart)
Get a substring of encoded CBOR for cryptographic hash.
static size_t QCBOREncode_Tell(QCBOREncodeContext *pCtx)
Returns current end of encoded data.
Definition qcbor_main_encode.h:1956
static void QCBOREncode_CloseMapIndefiniteLength(QCBOREncodeContext *pCtx)
Close an open indefinite length map.
Definition qcbor_main_encode.h:1855
static void QCBOREncode_AddNULLToMapN(QCBOREncodeContext *pCtx, int64_t nLabel)
Definition qcbor_main_encode.h:1688
static void QCBOREncode_AddSZStringToMapN(QCBOREncodeContext *pCtx, int64_t nLabel, const char *szString)
Definition qcbor_main_encode.h:1529
static void QCBOREncode_BstrWrap(QCBOREncodeContext *pCtx)
Indicate start of encoded CBOR to be wrapped in a bstr.
Definition qcbor_main_encode.h:1862
static void QCBOREncode_AddEncodedToMap(QCBOREncodeContext *pCtx, const char *szLabel, UsefulBufC Encoded)
Definition qcbor_main_encode.h:1905
static void QCBOREncode_CloseArray(QCBOREncodeContext *pCtx)
Close an open array.
Definition qcbor_main_encode.h:1751
static void QCBOREncode_AddSZStringToMapSZ(QCBOREncodeContext *pCtx, const char *szLabel, const char *szString)
Definition qcbor_main_encode.h:1514
static void QCBOREncode_ConfigReduced(QCBOREncodeContext *pCtx, enum QCBOREncodeConfig uConfig)
Configure the encoder, reduced object code.
Definition qcbor_main_encode.h:1465
static void QCBOREncode_AddUndef(QCBOREncodeContext *pCtx)
Add an "undef" to the encoded output.
Definition qcbor_main_encode.h:1696
static void QCBOREncode_AddBytesToMap(QCBOREncodeContext *pCtx, const char *szLabel, UsefulBufC Bytes)
Definition qcbor_main_encode.h:1557
static void QCBOREncode_AddText(QCBOREncodeContext *pCtx, UsefulBufC Text)
Add a UTF-8 text string to the encoded output.
Definition qcbor_main_encode.h:1477
static void QCBOREncode_Config(QCBOREncodeContext *pCtx, enum QCBOREncodeConfig uConfig)
Configure the encoder.
Definition qcbor_main_encode.h:1449
static void QCBOREncode_OpenMapIndefiniteLengthInMapSZ(QCBOREncodeContext *pCtx, const char *szLabel)
Definition qcbor_main_encode.h:1832
static void QCBOREncode_AddUndefToMapN(QCBOREncodeContext *pCtx, int64_t nLabel)
Definition qcbor_main_encode.h:1715
static void QCBOREncode_AddBoolToMapSZ(QCBOREncodeContext *pCtx, const char *szLabel, bool b)
Definition qcbor_main_encode.h:1648
static void QCBOREncode_AddBytes(QCBOREncodeContext *pCtx, UsefulBufC Bytes)
Add a byte string to the encoded output.
Definition qcbor_main_encode.h:1541
void QCBOREncode_Init(QCBOREncodeContext *pCtx, UsefulBuf Storage)
static UsefulBuf QCBOREncode_RetrieveOutputStorage(QCBOREncodeContext *pCtx)
Retrieve the storage buffer passed in to QCBOREncode_Init().
Definition qcbor_main_encode.h:1928
static void QCBOREncode_OpenMapIndefiniteLengthInMap(QCBOREncodeContext *pCtx, const char *szLabel)
Definition qcbor_main_encode.h:1840
static void QCBOREncode_CloseArrayIndefiniteLength(QCBOREncodeContext *pCtx)
Close an open indefinite length array.
Definition qcbor_main_encode.h:1819
QCBORError QCBOREncode_Finish(QCBOREncodeContext *pCtx, UsefulBufC *pEncodedCBOR)
Get the encoded result.
static void QCBOREncode_AddTextToMapN(QCBOREncodeContext *pCtx, int64_t nLabel, UsefulBufC Text)
Definition qcbor_main_encode.h:1498
void QCBOREncode_CloseAndSortMapIndef(QCBOREncodeContext *pCtx)
static void QCBOREncode_AddSZString(QCBOREncodeContext *pCtx, const char *szString)
Add a UTF-8 text string to the encoded output.
Definition qcbor_main_encode.h:1508
static void QCBOREncode_OpenArrayInMapSZ(QCBOREncodeContext *pCtx, const char *szLabel)
Definition qcbor_main_encode.h:1729
static void QCBOREncode_OpenArrayInMap(QCBOREncodeContext *pCtx, const char *szLabel)
Definition qcbor_main_encode.h:1736
void QCBOREncode_OpenBytes(QCBOREncodeContext *pCtx, UsefulBuf *pPlace)
Set up to write a byte string value directly to encoded output.
static int QCBOREncode_IsBufferNULL(QCBOREncodeContext *pCtx)
Indicate whether the output storage buffer is NULL.
Definition qcbor_main_encode.h:1921
static void QCBOREncode_AddNULLToMapSZ(QCBOREncodeContext *pCtx, const char *szLabel)
Definition qcbor_main_encode.h:1675
static void QCBOREncode_AddBytesToMapSZ(QCBOREncodeContext *pCtx, const char *szLabel, UsefulBufC Bytes)
Definition qcbor_main_encode.h:1548
static void QCBOREncode_OpenMap(QCBOREncodeContext *pCtx)
Indicates that the next items added are in a map.
Definition qcbor_main_encode.h:1758
void QCBOREncode_CloseBstrWrap2(QCBOREncodeContext *pCtx, bool bIncludeCBORHead, UsefulBufC *pWrappedCBOR)
Close a wrapping bstr.
static void QCBOREncode_AddTextToMap(QCBOREncodeContext *pCtx, const char *szLabel, UsefulBufC Text)
Definition qcbor_main_encode.h:1492
static void QCBOREncode_AddNULL(QCBOREncodeContext *pCtx)
Add a NULL to the encoded output.
Definition qcbor_main_encode.h:1669
static void QCBOREncode_AddSimpleToMapN(QCBOREncodeContext *pCtx, const int64_t nLabel, const uint8_t uSimple)
Definition qcbor_main_encode.h:1628
static void QCBOREncode_BstrWrapInMapSZ(QCBOREncodeContext *pCtx, const char *szLabel)
Definition qcbor_main_encode.h:1868
Definition UsefulBuf.h:280
Definition UsefulBuf.h:291