1 /*
2  * MessagePack for C dynamic typing routine
3  *
4  * Copyright (C) 2008-2009 FURUHASHI Sadayuki
5  *
6  *    Licensed under the Apache License, Version 2.0 (the "License");
7  *    you may not use this file except in compliance with the License.
8  *    You may obtain a copy of the License at
9  *
10  *        http://www.apache.org/licenses/LICENSE-2.0
11  *
12  *    Unless required by applicable law or agreed to in writing, software
13  *    distributed under the License is distributed on an "AS IS" BASIS,
14  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *    See the License for the specific language governing permissions and
16  *    limitations under the License.
17  */
18 #ifndef MSGPACK_OBJECT_H__
19 #define MSGPACK_OBJECT_H__
20 
21 #include "zone.h"
22 #include <stdio.h>
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 
29 /**
30  * @defgroup msgpack_object Dynamically typed object
31  * @ingroup msgpack
32  * @{
33  */
34 
35 typedef enum {
36 	MSGPACK_OBJECT_NIL					= 0x00,
37 	MSGPACK_OBJECT_BOOLEAN				= 0x01,
38 	MSGPACK_OBJECT_POSITIVE_INTEGER		= 0x02,
39 	MSGPACK_OBJECT_NEGATIVE_INTEGER		= 0x03,
40 	MSGPACK_OBJECT_DOUBLE				= 0x04,
41 	MSGPACK_OBJECT_RAW					= 0x05,
42 	MSGPACK_OBJECT_ARRAY				= 0x06,
43 	MSGPACK_OBJECT_MAP					= 0x07,
44 } msgpack_object_type;
45 
46 
47 struct msgpack_object;
48 struct msgpack_object_kv;
49 
50 typedef struct {
51 	uint32_t size;
52 	struct msgpack_object* ptr;
53 } msgpack_object_array;
54 
55 typedef struct {
56 	uint32_t size;
57 	struct msgpack_object_kv* ptr;
58 } msgpack_object_map;
59 
60 typedef struct {
61 	uint32_t size;
62 	const char* ptr;
63 } msgpack_object_raw;
64 
65 typedef union {
66 	bool boolean;
67 	uint64_t u64;
68 	int64_t  i64;
69 	double   dec;
70 	msgpack_object_array array;
71 	msgpack_object_map map;
72 	msgpack_object_raw raw;
73 } msgpack_object_union;
74 
75 typedef struct msgpack_object {
76 	msgpack_object_type type;
77 	msgpack_object_union via;
78 } msgpack_object;
79 
80 typedef struct msgpack_object_kv {
81 	msgpack_object key;
82 	msgpack_object val;
83 } msgpack_object_kv;
84 
85 
86 void msgpack_object_print(FILE* out, msgpack_object o);
87 
88 bool msgpack_object_equal(const msgpack_object x, const msgpack_object y);
89 
90 /** @} */
91 
92 
93 #ifdef __cplusplus
94 }
95 #endif
96 
97 #endif /* msgpack/object.h */
98 
99