Statistics
| Branch: | Revision:

grapes / include / int_coding.h @ ce1abd38

History | View | Annotate | Download (648 Bytes)

1
#ifndef INT_CODING
2
#define INT_CODING
3

    
4
#if defined(_WIN32)
5
#include <winsock2.h>
6
#else
7
#include <arpa/inet.h>
8
#endif
9
#include <string.h>
10

    
11
static inline void int_cpy(uint8_t *p, int v)
12
{
13
  uint32_t tmp;
14
  
15
  tmp = htonl(v);
16
  memcpy(p, &tmp, 4);
17
}
18

    
19
static inline void int16_cpy(uint8_t *p, uint16_t v)
20
{
21
  uint16_t tmp;
22

    
23
  tmp = htons(v);
24
  memcpy(p, &tmp, 2);
25
}
26

    
27
static inline uint32_t int_rcpy(const uint8_t *p)
28
{
29
  uint32_t tmp;
30
  
31
  memcpy(&tmp, p, 4);
32
  tmp = ntohl(tmp);
33

    
34
  return tmp;
35
}
36

    
37
static inline uint16_t int16_rcpy(const uint8_t *p)
38
{
39
  uint16_t tmp;
40

    
41
  memcpy(&tmp, p, 2);
42
  tmp = ntohs(tmp);
43
  return tmp;
44
}
45

    
46
#endif        /* INT_CODING */