1 #ifndef NDNDPDK_NDNI_TLV_ENCODER_H
2 #define NDNDPDK_NDNI_TLV_ENCODER_H
9 static __rte_always_inline uint8_t
10 TlvEncoder_SizeofVarNum(uint32_t n) {
11 if (likely(n < 0xFD)) {
13 }
else if (likely(n <= UINT16_MAX)) {
25 __attribute__((nonnull))
static __rte_always_inline
size_t
26 TlvEncoder_WriteVarNum(uint8_t* room, uint32_t n) {
27 if (likely(n < 0xFD)) {
30 }
else if (likely(n <= UINT16_MAX)) {
32 unaligned_uint16_t* b = RTE_PTR_ADD(room, 1);
33 *b = rte_cpu_to_be_16(n);
37 unaligned_uint32_t* b = RTE_PTR_ADD(room, 1);
38 *b = rte_cpu_to_be_32(n);
47 __attribute__((nonnull))
static __rte_always_inline
void
48 TlvEncoder_PrependTL(
struct rte_mbuf* m, uint32_t type, uint32_t length) {
49 uint8_t* room = (uint8_t*)rte_pktmbuf_prepend(m, TlvEncoder_SizeofVarNum(type) +
50 TlvEncoder_SizeofVarNum(length));
51 room += TlvEncoder_WriteVarNum(room, type);
52 TlvEncoder_WriteVarNum(room, length);
60 #define TlvEncoder_ConstTL1(type, length) \
62 static_assert(__builtin_constant_p((type)), ""); \
63 static_assert(__builtin_constant_p((length)), ""); \
64 static_assert((type) < 0xFD, ""); \
65 static_assert((length) <= UINT8_MAX, ""); \
66 rte_cpu_to_be_16(((type) << 8) | (length)); \
74 #define TlvEncoder_ConstTL3(type, length) \
76 static_assert(__builtin_constant_p((type)), ""); \
77 static_assert(__builtin_constant_p((length)), ""); \
78 static_assert(0xFD <= (type) && (type) <= UINT16_MAX, ""); \
79 static_assert((length) <= UINT8_MAX, ""); \
80 rte_cpu_to_be_32(0xFD000000 | ((type) << 8) | (length)); \