aws-crt-cpp
C++ wrapper around the aws-c-* libraries. Provides Cross-Platform Transport Protocols and SSL/TLS implementations for C++.
Loading...
Searching...
No Matches
Cbor.h
Go to the documentation of this file.
1#pragma once
7#include <aws/common/cbor.h>
8
9#include <aws/crt/Types.h>
10
11namespace Aws
12{
13 namespace Crt
14 {
15 namespace Cbor
16 {
35 enum class CborType
36 {
37 Unknown = AWS_CBOR_TYPE_UNKNOWN,
38 UInt = AWS_CBOR_TYPE_UINT,
39 NegInt = AWS_CBOR_TYPE_NEGINT,
40 Float = AWS_CBOR_TYPE_FLOAT,
41 Bytes = AWS_CBOR_TYPE_BYTES,
42 Text = AWS_CBOR_TYPE_TEXT,
43 ArrayStart = AWS_CBOR_TYPE_ARRAY_START,
44 MapStart = AWS_CBOR_TYPE_MAP_START,
45 Tag = AWS_CBOR_TYPE_TAG,
46 Bool = AWS_CBOR_TYPE_BOOL,
47 Null = AWS_CBOR_TYPE_NULL,
48 Undefined = AWS_CBOR_TYPE_UNDEFINED,
49 Break = AWS_CBOR_TYPE_BREAK,
50 IndefBytesStart = AWS_CBOR_TYPE_INDEF_BYTES_START,
51 IndefTextStart = AWS_CBOR_TYPE_INDEF_TEXT_START,
52 IndefArrayStart = AWS_CBOR_TYPE_INDEF_ARRAY_START,
53 IndefMapStart = AWS_CBOR_TYPE_INDEF_MAP_START,
54 };
55
57 {
58 public:
59 CborEncoder(const CborEncoder &) = delete;
61 CborEncoder &operator=(const CborEncoder &) = delete;
63
64 CborEncoder(Allocator *allocator = ApiAllocator()) noexcept;
65 ~CborEncoder() noexcept;
66
73 ByteCursor GetEncodedData() noexcept;
74
78 void Reset() noexcept;
79
86 void WriteUInt(uint64_t value) noexcept;
87
95 void WriteNegInt(uint64_t value) noexcept;
96
106 void WriteFloat(double value) noexcept;
107
115 void WriteBytes(ByteCursor value) noexcept;
116
124 void WriteText(ByteCursor value) noexcept;
125
133 void WriteArrayStart(size_t number_entries) noexcept;
134
144 void WriteMapStart(size_t number_entries) noexcept;
145
155 void WriteTag(uint64_t tag_number) noexcept;
156
160 void WriteNull() noexcept;
161
165 void WriteUndefined() noexcept;
166
170 void WriteBool(bool value) noexcept;
171
177 void WriteBreak() noexcept;
178
184 void WriteIndefBytesStart() noexcept;
185
191 void WriteIndefTextStart() noexcept;
192
198 void WriteIndefArrayStart() noexcept;
199
205 void WriteIndefMapStart() noexcept;
206
207 private:
208 struct aws_cbor_encoder *m_encoder;
209 };
210
212 {
213
214 public:
215 CborDecoder(const CborDecoder &) = delete;
219
226 CborDecoder(ByteCursor src, Allocator *allocator = ApiAllocator()) noexcept;
227 ~CborDecoder() noexcept;
228
235 size_t GetRemainingLength() noexcept;
236
245 Optional<CborType> PeekType() noexcept;
246
266 bool ConsumeNextWholeDataItem() noexcept;
267
286 bool ConsumeNextSingleElement() noexcept;
287
302 Optional<uint64_t> PopNextUnsignedIntVal() noexcept;
303 Optional<uint64_t> PopNextNegativeIntVal() noexcept;
304 Optional<double> PopNextFloatVal() noexcept;
305 Optional<bool> PopNextBooleanVal() noexcept;
306 Optional<ByteCursor> PopNextBytesVal() noexcept;
307 Optional<ByteCursor> PopNextTextVal() noexcept;
308
324 Optional<uint64_t> PopNextArrayStart() noexcept;
325
341 Optional<uint64_t> PopNextMapStart() noexcept;
342
352 Optional<uint64_t> PopNextTagVal() noexcept;
353
357 int LastError() const noexcept { return m_lastError ? m_lastError : AWS_ERROR_UNKNOWN; }
358
359 private:
360 struct aws_cbor_decoder *m_decoder;
361 /* Error */
362 int m_lastError;
363 };
364 } // namespace Cbor
365
366 } // namespace Crt
367} // namespace Aws
#define AWS_CRT_CPP_API
Definition Exports.h:36
Definition Cbor.h:212
CborDecoder & operator=(CborDecoder &&)=delete
CborDecoder(CborDecoder &&)=delete
CborDecoder & operator=(const CborDecoder &)=delete
CborDecoder(const CborDecoder &)=delete
Definition Cbor.h:57
CborEncoder(CborEncoder &&)=delete
CborEncoder & operator=(const CborEncoder &)=delete
CborEncoder(const CborEncoder &)=delete
CborEncoder & operator=(CborEncoder &&)=delete
Definition Optional.h:19
CborType
Definition Cbor.h:36
aws_byte_cursor ByteCursor
Definition Types.h:31
aws_allocator Allocator
Definition Allocator.h:14
AWS_CRT_CPP_API Allocator * ApiAllocator() noexcept
Definition Allocator.cpp:24
Definition Allocator.h:11