ndn-embeds 0.1.0
Lightweight NDN protocol stack for embedded systems
Loading...
Searching...
No Matches
common.hpp
Go to the documentation of this file.
1
9#pragma once
10
11#include <array>
12#include <cstddef>
13#include <cstdint>
14#include <optional>
15#include <string_view>
16
17namespace ndn {
18
24enum class Error : uint8_t {
25 Success = 0,
29 NotFound,
30 NoMemory,
31 Full,
32 Timeout,
37};
38
44constexpr const char* errorToString(Error error) {
45 switch (error) {
46 case Error::Success:
47 return "Success";
48 case Error::InvalidParam:
49 return "InvalidParam";
50 case Error::BufferTooSmall:
51 return "BufferTooSmall";
52 case Error::DecodeFailed:
53 return "DecodeFailed";
54 case Error::NotFound:
55 return "NotFound";
56 case Error::NoMemory:
57 return "NoMemory";
58 case Error::Full:
59 return "Full";
60 case Error::Timeout:
61 return "Timeout";
62 case Error::SendFailed:
63 return "SendFailed";
64 case Error::InvalidPacket:
65 return "InvalidPacket";
66 case Error::NameTooLong:
67 return "NameTooLong";
68 case Error::TooManyComponents:
69 return "TooManyComponents";
70 default:
71 return "Unknown";
72 }
73}
74
81enum class ContentType : uint8_t {
82 Blob = 0,
83 Link = 1,
84 Key = 2,
85 Nack = 3,
86};
87
89constexpr size_t LINK_MAX_DELEGATIONS = 5;
90
96using FaceId = uint16_t;
97
99constexpr FaceId FACE_ID_INVALID = 0;
100
102constexpr FaceId FACE_ID_LOCAL = 1;
103
107using TimeMs = uint64_t;
108
110constexpr size_t NAME_MAX_LENGTH = 128;
111
113constexpr size_t NAME_MAX_COMPONENTS = 10;
114
119constexpr size_t DATA_MAX_CONTENT_SIZE = 1440;
120
122constexpr size_t PACKET_MAX_SIZE = 1470;
123
125constexpr uint32_t INTEREST_DEFAULT_LIFETIME_MS = 4000;
126
146template <typename T>
147struct Result {
150
155 bool ok() const { return error == Error::Success; }
156
161 explicit operator bool() const { return ok(); }
162};
163
168TimeMs currentTimeMs();
169
174uint32_t generateRandomNonce();
175
176} // namespace ndn
constexpr size_t NAME_MAX_LENGTH
Maximum Name length (bytes)
Definition common.hpp:110
constexpr size_t NAME_MAX_COMPONENTS
Maximum number of Name components.
Definition common.hpp:113
ContentType
Content type.
Definition common.hpp:81
@ Key
Public key.
@ Nack
Network NACK.
@ Blob
Binary data (default)
uint64_t TimeMs
Timestamp type (milliseconds)
Definition common.hpp:107
constexpr uint32_t INTEREST_DEFAULT_LIFETIME_MS
Default Interest lifetime (milliseconds)
Definition common.hpp:125
constexpr size_t DATA_MAX_CONTENT_SIZE
Maximum content size of a Data packet (bytes) ESP-NOW v2.0: max 1470 bytes - TLV overhead (approx.
Definition common.hpp:119
constexpr FaceId FACE_ID_INVALID
Invalid Face ID.
Definition common.hpp:99
constexpr FaceId FACE_ID_LOCAL
Face ID for local application.
Definition common.hpp:102
constexpr size_t PACKET_MAX_SIZE
Maximum packet size (ESP-NOW v2.0 compatible)
Definition common.hpp:122
uint16_t FaceId
Face identifier.
Definition common.hpp:96
constexpr size_t LINK_MAX_DELEGATIONS
Maximum number of Names in a Link.
Definition common.hpp:89
constexpr const char * errorToString(Error error)
Convert error code to string.
Definition common.hpp:44
Error
Error codes.
Definition common.hpp:24
@ SendFailed
Send failed.
@ InvalidPacket
Invalid packet.
@ NameTooLong
Name is too long.
@ NotFound
Not found.
@ Success
Success.
@ DecodeFailed
Decode failed.
@ NoMemory
Out of memory.
@ BufferTooSmall
Buffer too small.
@ Full
Table is full.
@ TooManyComponents
Too many components.
@ Timeout
Timeout.
@ InvalidParam
Invalid parameter.
Result type template.
Definition common.hpp:147
bool ok() const
Check if the operation succeeded.
Definition common.hpp:155
T value
Result value.
Definition common.hpp:148
Error error
Error code.
Definition common.hpp:149