1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
#pragma once
#include <al/types.h>
#include <al/str.h>
#include <al/wstr.h>
#include <al/array.h>
#include "../util/buffer.h"
#define NNWT_PACKET_HEADER_LENGTH (u32)(sizeof(u32)) // Just size for now.
struct nn_packet {
struct nn_buffer buffer;
u32 rindex;
u32 windex;
void *opaque;
};
#define NNWT_PACKET_WRITE_TYPE(p, type, v) \
nn_buffer_write(&(p)->buffer, &(v), (p)->windex, sizeof(type)); \
(p)->windex += (u32)sizeof(type)
#define NNWT_PACKET_WRITE_DATA(p, data, length) \
nn_buffer_write(&(p)->buffer, data, (p)->windex, length); \
(p)->windex += (u32)length
#define NNWT_PACKET_READ_TYPE(p, type, r) \
NNWT_BUFFER_READ_TYPE(&(p)->buffer, (p)->rindex, type, r); \
(p)->rindex += (u32)sizeof(type)
#define NNWT_PACKET_READ_DATA(p, length, r) \
r = (__typeof__(r))nn_buffer_get_ptr(&(p)->buffer, (p)->rindex); \
(p)->rindex += (u32)length
static inline u32 nn_packet_get_u32(struct nn_packet *packet, u32 index)
{
u32 value;
NNWT_BUFFER_READ_TYPE(&packet->buffer, index, u32, value);
return value;
}
struct nn_packet *nn_packet_create(void);
struct nn_packet *nn_packet_clone(struct nn_packet *packet);
void nn_packet_reset(struct nn_packet *packet);
void nn_packet_write_size(struct nn_packet *packet);
u32 nn_packet_get_size(struct nn_packet *packet);
void nn_packet_write_bool(struct nn_packet *packet, bool v);
void nn_packet_write_u8(struct nn_packet *packet, u8 v);
void nn_packet_write_s8(struct nn_packet *packet, s8 v);
void nn_packet_write_u16(struct nn_packet *packet, u16 v);
void nn_packet_write_s16(struct nn_packet *packet, s16 v);
void nn_packet_write_u32(struct nn_packet *packet, u32 v);
void nn_packet_write_s32(struct nn_packet *packet, s32 v);
void nn_packet_write_u64(struct nn_packet *packet, u64 v);
void nn_packet_write_s64(struct nn_packet *packet, s64 v);
void nn_packet_write_f32(struct nn_packet *packet, f32 v);
void nn_packet_write_f64(struct nn_packet *packet, f64 v);
void nn_packet_write_str(struct nn_packet *packet, str *s);
void nn_packet_write_buffer(struct nn_packet *packet, struct nn_buffer *buf);
bool nn_packet_read_bool(struct nn_packet *packet);
u8 nn_packet_read_u8(struct nn_packet *packet);
s8 nn_packet_read_s8(struct nn_packet *packet);
u16 nn_packet_read_u16(struct nn_packet *packet);
s16 nn_packet_read_s16(struct nn_packet *packet);
u32 nn_packet_read_u32(struct nn_packet *packet);
s32 nn_packet_read_s32(struct nn_packet *packet);
u64 nn_packet_read_u64(struct nn_packet *packet);
s64 nn_packet_read_s64(struct nn_packet *packet);
f32 nn_packet_read_f32(struct nn_packet *packet);
f64 nn_packet_read_f64(struct nn_packet *packet);
void nn_packet_read_str(struct nn_packet *packet, str *s);
void nn_packet_read_buffer(struct nn_packet *packet, struct nn_buffer *buf);
void nn_packet_write_wstr(struct nn_packet *packet, wstr *w);
void nn_packet_read_wstr(struct nn_packet *packet, wstr *w);
void nn_packet_free(struct nn_packet *packet);
|