// SPDX-License-Identifier: BSD-3-Clause OR Apache-2.0 #ifndef BUNDLE7_EID_H_INCLUDED #define BUNDLE7_EID_H_INCLUDED #include "ud3tn/eid.h" #include "cbor.h" #include // size_t #include // uint*_t // ------------------------------------- // BPv7 Endpoint Identifier (EID) Parser // ------------------------------------- /** * Parses the given CBOR buffer as EID string. If the buffer is larger than * required the remaining bytes will be ignored. * * Internally this function uses "bundle7_eid_parse_cbor()" * * @param buffer CBOR encoded EID * @param length buffer size * * @return parsed EID struct. If any error occures, an invalid EID will be returned (check with * `eid_is_error`). */ struct eid bundle7_eid_parse(const uint8_t *buffer, size_t length); /** * Parses EID with a given CBOR iterator * * @param it iterator to CBOR data stream / buffer * @param eid Destination EID struct * * @return CBOR error if something went south */ CborError bundle7_eid_parse_cbor(CborValue *it, struct eid *eid); // ----------------------------------------- // BPv7 Endpoint Identifier (EID) Serializer // ----------------------------------------- /** * Creates a CBOR encoded EID from given internal (struct) representation. * If any error occurred NULL will be returned. * * @param eid EID struct to be serialized * @param length Final CBOR length (output) * * @return CBOR encoded bytes */ uint8_t *bundle7_eid_serialize_alloc(const struct eid eid, size_t *length); /** * Creates CBOR encoded EID in the given output buffer. If the buffer is not * large enough 0 will be returned, in case of error -1 and otherwise the * number of bytes written to the buffer. * * Internally this function uses "bundle7_eid_serialize_cbor()" * * @param eid EID struct to be serialized * @param buffer CBOR output buffer * @param buffer_size length of the output buffer * * @return Number of CBOR bytes written to buffer. If an error occures -1 */ int bundle7_eid_serialize(const struct eid eid, uint8_t *buffer, size_t buffer_size); /** * Creates a CBOR encoded EID with the given CBOR encoder. You can use * this function to include EIDs in your CBOR encoding process. * * @param eid EID that should be encoded in CBOR * @param encoder CBOR encoder to already existing buffer * * @return CBOR error if something went wrong */ CborError bundle7_eid_serialize_cbor(const struct eid eid, CborEncoder *encoder); #endif // BUNDLE7_EID_H_INCLUDED