20 return Error::Success;
29 for (
size_t i = 0; i < delegationCount_; ++i) {
31 return Error::InvalidParam;
36 return Error::Success;
48 if (index >= delegationCount_) {
51 return &delegations_[index];
59 for (
size_t i = 0; i < delegationCount_; ++i) {
60 if (delegations_[i].equals(
name)) {
71 if (delegationCount_ == 0) {
73 return Error::InvalidParam;
78 TlvEncoder encoder(contentBuf,
sizeof(contentBuf));
80 for (
size_t i = 0; i < delegationCount_; ++i) {
83 if (err != Error::Success) {
90 if (err != Error::Success) {
94 return Error::Success;
99 return {.
value =
Link{}, .error = Error::InvalidPacket};
103 return {.value =
Link{}, .error = Error::InvalidPacket};
107 link.name_ = data.
name();
113 size_t bytesRead = 0;
115 if (!nameResult.ok()) {
116 return {.value =
Link{}, .error = nameResult.error};
120 if (err != Error::Success) {
121 return {.value =
Link{}, .error = err};
124 decoder.
skip(bytesRead);
127 if (link.delegationCount_ == 0) {
128 return {.value =
Link{}, .error = Error::InvalidPacket};
131 return {.value = link, .error = Error::Success};
const Name & name() const
Get the Name (const reference)
bool hasContent() const
Check if content is set.
size_t contentSize() const
Get the content size.
Data & setContentType(ContentType type)
Set the content type.
const uint8_t * content() const
Get a pointer to the content data.
Error setContent(const uint8_t *data, size_t size)
Set binary data as content.
ContentType contentType() const
Get the content type.
Data & setName(const Name &name)
Set the Name (supports method chaining)
const Name & name() const
Get the Name (const reference)
Link & setName(const Name &name)
Set the Name.
Error addDelegation(const Name &delegation)
Add a delegation (Name)
const Name * delegation(size_t index) const
Get a delegation by index.
Link()=default
Default constructor.
void clearDelegations()
Clear all delegations.
bool hasDelegation(const Name &name) const
Check if a given Name is in the delegation list.
Error toData(Data &data) const
Convert the Link to a Data packet.
static Result< Link > fromData(const Data &data)
Decode a Link from a Data packet.
static Result< Name > fromWire(const uint8_t *buf, size_t len, size_t *bytesRead=nullptr)
Decode a Name from TLV wire format.
static Result< Name > fromUri(std::string_view uri)
Create a Name from a URI string.
const uint8_t * current() const
Pointer to current position.
Error skip(size_t len)
Skip a specified number of bytes.
size_t remaining() const
Remaining readable bytes.
bool hasMore() const
Check if there is more data.
size_t position() const
Get current position.
void setPosition(size_t pos)
Set current position.
size_t size() const
Current write position (= number of bytes written)
size_t remaining() const
Remaining writable bytes.
uint8_t * current()
Pointer to current position.
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.
constexpr size_t LINK_MAX_DELEGATIONS
Maximum number of Names in a Link.
NDN TLV (Type-Length-Value) encoding.