ndn-embeds 0.1.0
Lightweight NDN protocol stack for embedded systems
Loading...
Searching...
No Matches
common.hpp File Reference

Common definitions for the NDN protocol stack. More...

#include <array>
#include <cstddef>
#include <cstdint>
#include <optional>
#include <string_view>

Go to the source code of this file.

Classes

struct  ndn::Result< T >
 Result type template. More...
 

Typedefs

using ndn::FaceId = uint16_t
 Face identifier.
 
using ndn::TimeMs = uint64_t
 Timestamp type (milliseconds)
 

Enumerations

enum class  ndn::Error : uint8_t {
  Success = 0 , InvalidParam , BufferTooSmall , DecodeFailed ,
  NotFound , NoMemory , Full , Timeout ,
  SendFailed , InvalidPacket , NameTooLong , TooManyComponents
}
 Error codes. More...
 
enum class  ndn::ContentType : uint8_t { Blob = 0 , Link = 1 , Key = 2 , Nack = 3 }
 Content type. More...
 

Functions

constexpr const char * ndn::errorToString (Error error)
 Convert error code to string.
 
TimeMs ndn::currentTimeMs ()
 Get current time (milliseconds)
 
uint32_t ndn::generateRandomNonce ()
 Generate a random Nonce value.
 

Variables

constexpr size_t ndn::LINK_MAX_DELEGATIONS = 5
 Maximum number of Names in a Link.
 
constexpr FaceId ndn::FACE_ID_INVALID = 0
 Invalid Face ID.
 
constexpr FaceId ndn::FACE_ID_LOCAL = 1
 Face ID for local application.
 
constexpr size_t ndn::NAME_MAX_LENGTH = 128
 Maximum Name length (bytes)
 
constexpr size_t ndn::NAME_MAX_COMPONENTS = 10
 Maximum number of Name components.
 
constexpr size_t ndn::DATA_MAX_CONTENT_SIZE = 1440
 Maximum content size of a Data packet (bytes) ESP-NOW v2.0: max 1470 bytes - TLV overhead (approx.
 
constexpr size_t ndn::PACKET_MAX_SIZE = 1470
 Maximum packet size (ESP-NOW v2.0 compatible)
 
constexpr uint32_t ndn::INTEREST_DEFAULT_LIFETIME_MS = 4000
 Default Interest lifetime (milliseconds)
 

Detailed Description

Common definitions for the NDN protocol stack.

Provides fundamental types and definitions used throughout the NDN library, including error codes, constants, and the Result type.

Definition in file common.hpp.

Typedef Documentation

◆ FaceId

using ndn::FaceId = typedef uint16_t

Face identifier.

A 16-bit integer that uniquely identifies each Face.

Definition at line 96 of file common.hpp.

◆ TimeMs

using ndn::TimeMs = typedef uint64_t

Timestamp type (milliseconds)

Definition at line 107 of file common.hpp.

Enumeration Type Documentation

◆ ContentType

enum class ndn::ContentType : uint8_t
strong

Content type.

Represents the content type of a Data packet.

See also
https://docs.named-data.net/NDN-packet-spec/current/types.html
Enumerator
Blob 

Binary data (default)

Link 

Link Object (list of Names for forwarding hints)

Key 

Public key.

Nack 

Network NACK.

Definition at line 81 of file common.hpp.

◆ Error

enum class ndn::Error : uint8_t
strong

Error codes.

Represents errors that may occur in NDN library operations.

Enumerator
Success 

Success.

InvalidParam 

Invalid parameter.

BufferTooSmall 

Buffer too small.

DecodeFailed 

Decode failed.

NotFound 

Not found.

NoMemory 

Out of memory.

Full 

Table is full.

Timeout 

Timeout.

SendFailed 

Send failed.

InvalidPacket 

Invalid packet.

NameTooLong 

Name is too long.

TooManyComponents 

Too many components.

Definition at line 24 of file common.hpp.

Function Documentation

◆ currentTimeMs()

TimeMs ndn::currentTimeMs ( )

◆ errorToString()

constexpr const char * ndn::errorToString ( Error  error)
constexpr

Convert error code to string.

Parameters
errorError code
Returns
String representation of the error

Definition at line 44 of file common.hpp.

References ndn::errorToString().

Referenced by ndn::errorToString().

◆ generateRandomNonce()

uint32_t ndn::generateRandomNonce ( )

Generate a random Nonce value.

Returns
32-bit random value

Definition at line 11 of file common.cpp.

References ndn::generateRandomNonce().

Referenced by ndn::Interest::generateNonce(), and ndn::generateRandomNonce().

Variable Documentation

◆ DATA_MAX_CONTENT_SIZE

constexpr size_t ndn::DATA_MAX_CONTENT_SIZE = 1440
constexpr

Maximum content size of a Data packet (bytes) ESP-NOW v2.0: max 1470 bytes - TLV overhead (approx.

30-40 bytes) Measured: max 1434 bytes with /ndn/ping/<seq>

Definition at line 119 of file common.hpp.

Referenced by ndn::Data::fromWire(), ndn::Data::setContent(), and ndn::Link::toData().

◆ FACE_ID_INVALID

constexpr FaceId ndn::FACE_ID_INVALID = 0
constexpr

Invalid Face ID.

Definition at line 99 of file common.hpp.

Referenced by ndn::Forwarder::addFace(), ndn::EspNowFace::addPeer(), and ndn::PitEntry::face().

◆ FACE_ID_LOCAL

constexpr FaceId ndn::FACE_ID_LOCAL = 1
constexpr

◆ INTEREST_DEFAULT_LIFETIME_MS

constexpr uint32_t ndn::INTEREST_DEFAULT_LIFETIME_MS = 4000
constexpr

Default Interest lifetime (milliseconds)

Definition at line 125 of file common.hpp.

Referenced by ndn::Interest::encode().

◆ LINK_MAX_DELEGATIONS

constexpr size_t ndn::LINK_MAX_DELEGATIONS = 5
constexpr

Maximum number of Names in a Link.

Definition at line 89 of file common.hpp.

Referenced by ndn::Link::addDelegation().

◆ NAME_MAX_COMPONENTS

constexpr size_t ndn::NAME_MAX_COMPONENTS = 10
constexpr

Maximum number of Name components.

Definition at line 113 of file common.hpp.

◆ NAME_MAX_LENGTH

constexpr size_t ndn::NAME_MAX_LENGTH = 128
constexpr

Maximum Name length (bytes)

Definition at line 110 of file common.hpp.

Referenced by ndn::Name::fromUri().

◆ PACKET_MAX_SIZE