aura  0.1
 All Data Structures Functions Variables Modules Pages
retparse.c
1 #include <aura/aura.h>
2 #include <aura/private.h>
3 
4 #define DECLARE_GETFUNC(tp, name, swapfunc) \
5  tp aura_buffer_get_##name(struct aura_buffer *buf) \
6  { \
7  struct aura_node *node = buf->owner; \
8  tp result = *(tp *) &buf->data[buf->pos]; \
9  \
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); \
15  return result; \
16  } \
17 
18 #define noswap(v) v
19 
20 #define DECLARE_PUTFUNC(tp, name, swapfunc) \
21  void aura_buffer_put_##name(struct aura_buffer *buf, tp value) \
22  { \
23  struct aura_node *node = buf->owner; \
24  tp *target = (tp *) &buf->data[buf->pos]; \
25  \
26  if (node->need_endian_swap) \
27  value = swapfunc(value); \
28  \
29  if (buf->pos > buf->size) \
30  BUG(node, "attempt to access data beyound buffer boundary"); \
31  buf->pos += sizeof(tp); \
32  \
33  *target = value; \
34  } \
35 
36 DECLARE_GETFUNC(uint8_t, u8, noswap);
37 DECLARE_GETFUNC(int8_t, s8, noswap);
38 
39 DECLARE_GETFUNC(uint16_t, u16, __swap16);
40 DECLARE_GETFUNC(int16_t, s16, __swap16);
41 
42 DECLARE_GETFUNC(uint32_t, u32, __swap32);
43 DECLARE_GETFUNC(int32_t, s32, __swap32);
44 
45 DECLARE_GETFUNC(uint64_t, u64, __swap64);
46 DECLARE_GETFUNC(int64_t, s64, __swap64);
47 
48 DECLARE_PUTFUNC(uint8_t, u8, noswap);
49 DECLARE_PUTFUNC(int8_t, s8, noswap);
50 
51 DECLARE_PUTFUNC(uint16_t, u16, __swap16);
52 DECLARE_PUTFUNC(int16_t, s16, __swap16);
53 
54 DECLARE_PUTFUNC(uint32_t, u32, __swap32);
55 DECLARE_PUTFUNC(int32_t, s32, __swap32);
56 
57 DECLARE_PUTFUNC(uint64_t, u64, __swap64);
58 DECLARE_PUTFUNC(int64_t, s64, __swap64);
59 
60 const void *aura_buffer_get_bin(struct aura_buffer *buf, int len)
61 {
62  struct aura_node *node = buf->owner;
63  int pos = buf->pos;
64 
65  buf->pos += len;
66  if (buf->pos > buf->size)
67  BUG(node, "attempt to access data beyound buffer boundary");
68  return &buf->data[pos];
69 }
70 
71 void aura_buffer_put_bin(struct aura_buffer *buf, const void *data, int len)
72 {
73  struct aura_node *node = buf->owner;
74  int pos = buf->pos;
75 
76  if (pos > buf->size)
77  BUG(node, "attempt to access data beyound buffer boundary");
78 
79  memcpy(&buf->data[pos], data, len);
80  buf->pos += len;
81 }
82 
84 {
85  struct aura_node *node = buf->owner;
86  struct aura_buffer *ret;
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!");
92  return ret;
93 }
uint32_t magic
Definition: aura.h:335
struct aura_node * owner
Definition: aura.h:343
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.
Definition: retparse.c:71
int pos
Definition: aura.h:339
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...
Definition: retparse.c:60
int size
Definition: aura.h:337
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...
Definition: retparse.c:83
char * data
Definition: aura.h:347