-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
/
Copy pathserialize.h
81 lines (65 loc) · 1.56 KB
/
serialize.h
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
81
// This file is a part of Julia. License is MIT: https://julialang.org/license
#ifndef JL_SERIALIZE_H
#define JL_SERIALIZE_H
#ifdef __cplusplus
extern "C" {
#endif
#define write_uint8(s, n) ios_putc((n), (s))
#define read_uint8(s) ((uint8_t)ios_getc((s)))
#define write_int8(s, n) write_uint8((s), (n))
#define read_int8(s) read_uint8((s))
/* read and write in host byte order */
static inline void write_int32(ios_t *s, int32_t i) JL_NOTSAFEPOINT
{
ios_write(s, (char*)&i, 4);
}
static inline int32_t read_int32(ios_t *s) JL_NOTSAFEPOINT
{
int32_t x = 0;
ios_read(s, (char*)&x, 4);
return x;
}
static inline uint64_t read_uint64(ios_t *s) JL_NOTSAFEPOINT
{
uint64_t x = 0;
ios_read(s, (char*)&x, 8);
return x;
}
static inline void write_uint64(ios_t *s, uint64_t i) JL_NOTSAFEPOINT
{
ios_write(s, (char*)&i, 8);
}
static inline void write_uint16(ios_t *s, uint16_t i) JL_NOTSAFEPOINT
{
ios_write(s, (char*)&i, 2);
}
static inline uint16_t read_uint16(ios_t *s) JL_NOTSAFEPOINT
{
int16_t x = 0;
ios_read(s, (char*)&x, 2);
return x;
}
static inline void write_uint32(ios_t *s, uint32_t i) JL_NOTSAFEPOINT
{
ios_write(s, (char*)&i, 4);
}
static inline uint32_t read_uint32(ios_t *s) JL_NOTSAFEPOINT
{
uint32_t x = 0;
ios_read(s, (char*)&x, 4);
return x;
}
#ifdef _P64
#define write_uint(s, i) write_uint64(s, i)
#else
#define write_uint(s, i) write_uint32(s, i)
#endif
#ifdef _P64
#define read_uint(s) read_uint64(s)
#else
#define read_uint(s) read_uint32(s)
#endif
#ifdef __cplusplus
}
#endif
#endif /* JL_SERIALIZE_H */