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
33
34
43
44
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
76
77
79
80
81
82
83
84
85
86
95
96
97
98
102
103
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
130
131
135
136
137
138
139
140
/* ... */
#include <stdint.h>
#include <string.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "libjaylink-internal.h"
/* ... */
/* ... */
JAYLINK_PRIV void buffer_set_u16(uint8_t *buffer, uint16_t value,
size_t offset)
{
/* ... */
#ifdef WORDS_BIGENDIAN
buffer[offset + 0] = value;
buffer[offset + 1] = value >> 8;/* ... */
#else
memcpy(buffer + offset, &value, sizeof(value));
#endif
}{ ... }
/* ... */
JAYLINK_PRIV uint16_t buffer_get_u16(const uint8_t *buffer, size_t offset)
{
uint16_t value;
/* ... */
#ifdef WORDS_BIGENDIAN
value = (((uint16_t)buffer[offset + 1])) |
(((uint16_t)buffer[offset + 0]) << 8);/* ... */
#else
memcpy(&value, buffer + offset, sizeof(value));
#endif
return value;
}{ ... }
/* ... */
JAYLINK_PRIV void buffer_set_u32(uint8_t *buffer, uint32_t value,
size_t offset)
{
/* ... */
#ifdef WORDS_BIGENDIAN
buffer[offset + 0] = value;
buffer[offset + 1] = value >> 8;
buffer[offset + 2] = value >> 16;
buffer[offset + 3] = value >> 24;/* ... */
#else
memcpy(buffer + offset, &value, sizeof(value));
#endif
}{ ... }
/* ... */
JAYLINK_PRIV uint32_t buffer_get_u32(const uint8_t *buffer, size_t offset)
{
uint32_t value;
/* ... */
#ifdef WORDS_BIGENDIAN
value = (((uint32_t)buffer[offset + 3])) |
(((uint32_t)buffer[offset + 2]) << 8) |
(((uint32_t)buffer[offset + 1]) << 16) |
(((uint32_t)buffer[offset + 0]) << 24);/* ... */
#else
memcpy(&value, buffer + offset, sizeof(value));
#endif
return value;
}{ ... }