1
+ #if defined _msgpack_included
2
+ #endinput
3
+ #endif
4
+ # define _msgpack_included
5
+
6
+ enum MsgPack_Type {
7
+ MSGPACK_OBJECT_NIL = 0x 00 ,
8
+ MSGPACK_OBJECT_BOOLEAN = 0x 01 ,
9
+ MSGPACK_OBJECT_POSITIVE_INTEGER = 0x 02 ,
10
+ MSGPACK_OBJECT_NEGATIVE_INTEGER = 0x 03 ,
11
+ MSGPACK_OBJECT_DOUBLE = 0x 04 ,
12
+ MSGPACK_OBJECT_RAW = 0x 05 ,
13
+ MSGPACK_OBJECT_ARRAY = 0x 06 ,
14
+ MSGPACK_OBJECT_MAP = 0x 07 ,
15
+ };
16
+
17
+ /*
18
+ * Packing Functions
19
+ */
20
+
21
+ // create a pack handle to pack with
22
+ native Handle: MsgPack_NewPack ();
23
+
24
+ native MsgPack_PackInt (Handle: pack, value);
25
+ native MsgPack_PackFloat (Handle: pack, Float: value);
26
+ native MsgPack_PackNil (Handle: pack);
27
+ native MsgPack_PackTrue (Handle: pack);
28
+ native MsgPack_PackFalse (Handle: pack);
29
+ native MsgPack_PackArray (Handle: pack, size);
30
+ native MsgPack_PackMap (Handle: pack, size);
31
+
32
+ // pack some bytes. does not null terminate
33
+ native MsgPack_PackRaw (Handle: pack, const String: buffer[], buffer_length);
34
+
35
+ stock MsgPack_PackString (Handle: pack, const String: null_terminated_string[]) {
36
+ return MsgPack_PackRaw (pack, null_terminated_string, strlen (null_terminated_string));
37
+ }
38
+
39
+ // get the pack length in bytes
40
+ native MsgPack_GetPackSize (Handle: pack);
41
+
42
+ // get the buffer so you can send it somewhere
43
+ native MsgPack_GetPackBuffer (Handle: pack, const String: buffer[], buffer_length);
44
+
45
+ /*
46
+ * Unpacking Functions
47
+ */
48
+
49
+ // create a messagepack object handle.
50
+ // offset is the number of bytes consumed
51
+ // enabling save_buffer copies the buffer so objects still work properly when the buffer goes out of scope
52
+ // the buffer is shared between all objects that come from here and will be deleted when they are all closed
53
+ native Handle: MsgPack_NewUnpack (const String: buffer[], buffer_length, & offset= 0 , bool: save_buffer= true );
54
+
55
+
56
+ // pretty print object to console for debugging
57
+ native MsgPack_UnpackPrint (Handle: obj);
58
+
59
+ // get the object type
60
+ native MsgPack_Type: MsgPack_UnpackType (Handle: obj);
61
+
62
+ // get the number of elements for maps, arrays, and raws. returns 0 if not one of those types
63
+ native MsgPack_UnpackCount (Handle: obj);
64
+
65
+ native bool: MsgPack_UnpackBool (Handle: obj);
66
+ native MsgPack_UnpackInt (Handle: obj);
67
+ native Float: MsgPack_UnpackFloat (Handle: obj);
68
+ native MsgPack_UnpackRaw (Handle: obj, String: buffer[], buffer_length);
69
+ stock MsgPack_UnpackString (Handle: obj, String: buffer[], buffer_length) {
70
+ new written = MsgPack_UnpackRaw (obj, buffer, buffer_length);
71
+ if (written- 1 >= buffer_length)
72
+ buffer[buffer_length] = 0 ;
73
+ else
74
+ buffer[written] = 0 ;
75
+
76
+ return written;
77
+ }
78
+ native Handle: MsgPack_UnpackArray (Handle: obj, index);
79
+ native Handle: MsgPack_UnpackKey (Handle: obj, index);
80
+ native Handle: MsgPack_UnpackValue (Handle: obj, index);
81
+ native Handle: MsgPack_UnpackNext (Handle: obj);
82
+ native any: MsgPack_UnpackArrayCell (Handle: obj, index);
83
+
84
+ // //////////////////////////////////////////////// old functions
85
+ #pragma deprecated Renamed Object to Unpack
86
+ native MsgPack_ObjectPrint (Handle: obj);
87
+
88
+ #pragma deprecated Renamed Object to Unpack
89
+ native MsgPack_Type: MsgPack_ObjectType (Handle: obj);
90
+
91
+ #pragma deprecated Renamed Object to Unpack
92
+ native MsgPack_ObjectCount (Handle: obj);
93
+
94
+ #pragma deprecated Renamed Object to Unpack
95
+ native bool: MsgPack_ObjectBool (Handle: obj);
96
+
97
+ #pragma deprecated Renamed Object to Unpack
98
+ native MsgPack_ObjectInt (Handle: obj);
99
+
100
+ #pragma deprecated Renamed Object to Unpack
101
+ native Float: MsgPack_ObjectFloat (Handle: obj);
102
+
103
+ #pragma deprecated Renamed Object to Unpack
104
+ native MsgPack_ObjectRaw (Handle: obj, String: buffer[], buffer_length);
105
+
106
+ #pragma deprecated Renamed Object to Unpack
107
+ stock MsgPack_ObjectString (Handle: obj, String: buffer[], buffer_length) {
108
+ return MsgPack_UnpackString (obj, buffer, buffer_length);
109
+ }
110
+
111
+ #pragma deprecated Renamed Object to Unpack
112
+ native Handle: MsgPack_ObjectArray (Handle: obj, index);
113
+
114
+ #pragma deprecated Renamed Object to Unpack
115
+ native Handle: MsgPack_ObjectKey (Handle: obj, index);
116
+
117
+ #pragma deprecated Renamed Object to Unpack
118
+ native Handle: MsgPack_ObjectValue (Handle: obj, index);
119
+
120
+ public Extension: __ext_MsgPack =
121
+ {
122
+ name = " msgpack" ,
123
+ file = " msgpack.ext" ,
124
+ #if defined AUTOLOAD_EXTENSIONS
125
+ autoload = 1 ,
126
+ #else
127
+ autoload = 0 ,
128
+ #endif
129
+ #if defined REQUIRE_EXTENSIONS
130
+ required = 1 ,
131
+ #else
132
+ required = 0 ,
133
+ #endif
134
+ }
0 commit comments