2 #include <aura/private.h>
4 #define DECLARE_GETFUNC(tp, name, swapfunc) \
5 tp aura_buffer_get_##name(struct aura_buffer *buf) \
7 struct aura_node *node = buf->owner; \
8 tp result = *(tp *) &buf->data[buf->pos]; \
10 buf->pos += sizeof(tp); \
11 if (buf->pos > buf->size) \
12 BUG(node, "attempt to access data beyound buffer boundary"); \
13 if (node->need_endian_swap) \
14 result = swapfunc(result); \
20 #define DECLARE_PUTFUNC(tp, name, swapfunc) \
21 void aura_buffer_put_##name(struct aura_buffer *buf, tp value) \
23 struct aura_node *node = buf->owner; \
24 tp *target = (tp *) &buf->data[buf->pos]; \
26 if (node->need_endian_swap) \
27 value = swapfunc(value); \
29 if (buf->pos > buf->size) \
30 BUG(node, "attempt to access data beyound buffer boundary"); \
31 buf->pos += sizeof(tp); \
36 DECLARE_GETFUNC(uint8_t, u8, noswap);
37 DECLARE_GETFUNC(int8_t, s8, noswap);
39 DECLARE_GETFUNC(uint16_t, u16, __swap16);
40 DECLARE_GETFUNC(int16_t, s16, __swap16);
42 DECLARE_GETFUNC(uint32_t, u32, __swap32);
43 DECLARE_GETFUNC(int32_t, s32, __swap32);
45 DECLARE_GETFUNC(uint64_t, u64, __swap64);
46 DECLARE_GETFUNC(int64_t, s64, __swap64);
48 DECLARE_PUTFUNC(uint8_t, u8, noswap);
49 DECLARE_PUTFUNC(int8_t, s8, noswap);
51 DECLARE_PUTFUNC(uint16_t, u16, __swap16);
52 DECLARE_PUTFUNC(int16_t, s16, __swap16);
54 DECLARE_PUTFUNC(uint32_t, u32, __swap32);
55 DECLARE_PUTFUNC(int32_t, s32, __swap32);
57 DECLARE_PUTFUNC(uint64_t, u64, __swap64);
58 DECLARE_PUTFUNC(int64_t, s64, __swap64);
62 struct aura_node *node = buf->
owner;
67 BUG(node,
"attempt to access data beyound buffer boundary");
68 return &buf->
data[pos];
73 struct aura_node *node = buf->
owner;
77 BUG(node,
"attempt to access data beyound buffer boundary");
79 memcpy(&buf->
data[pos], data, len);
85 struct aura_node *node = buf->
owner;
87 if (!node->tr->buffer_get)
88 BUG(node,
"This node doesn't support aura_buffer as argument");
89 ret = node->tr->buffer_get(buf);
90 if (ret->
magic != AURA_BUFFER_MAGIC_ID)
91 BUG(node,
"Fetched an aura_buffer with invalid magic - check your code!");
void aura_buffer_put_bin(struct aura_buffer *buf, const void *data, int len)
Copy data of len bytes to aura buffer from a buffer pointed by data.
const void * aura_buffer_get_bin(struct aura_buffer *buf, int len)
Get a pointer to the binary data block within buffer and advance internal pointer by len bytes...
struct aura_buffer * aura_buffer_get_buf(struct aura_buffer *buf)
Retrieve aura_buffer pointer from within the buffer and advance internal pointer by it's size...