2003-02-16 Anders Carlsson <andersca@codefactory.se>
[platform/upstream/dbus.git] / dbus / dbus-marshal.h
1 /* -*- mode: C; c-file-style: "gnu" -*- */
2 /* dbus-marshal.h  Marshalling routines
3  *
4  * Copyright (C) 2002  CodeFactory AB
5  *
6  * Licensed under the Academic Free License version 1.2
7  * 
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  * 
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  *
22  */
23
24 #ifndef DBUS_MARSHAL_H
25 #define DBUS_MARSHAL_H
26
27 #include <config.h>
28 #include <dbus/dbus-protocol.h>
29 #include <dbus/dbus-types.h>
30 #include <dbus/dbus-string.h>
31
32 #ifndef PACKAGE
33 #error "config.h not included here"
34 #endif
35
36 #ifdef WORDS_BIGENDIAN
37 #define DBUS_COMPILER_BYTE_ORDER DBUS_BIG_ENDIAN
38 #else
39 #define DBUS_COMPILER_BYTE_ORDER DBUS_LITTLE_ENDIAN
40 #endif
41
42 #define DBUS_UINT32_SWAP_LE_BE_CONSTANT(val)    ((dbus_uint32_t) ( \
43     (((dbus_uint32_t) (val) & (dbus_uint32_t) 0x000000ffU) << 24) |  \
44     (((dbus_uint32_t) (val) & (dbus_uint32_t) 0x0000ff00U) <<  8) |  \
45     (((dbus_uint32_t) (val) & (dbus_uint32_t) 0x00ff0000U) >>  8) |  \
46     (((dbus_uint32_t) (val) & (dbus_uint32_t) 0xff000000U) >> 24)))
47
48 #define DBUS_UINT32_SWAP_LE_BE(val) (DBUS_UINT32_SWAP_LE_BE_CONSTANT (val))
49 #define DBUS_INT32_SWAP_LE_BE(val)  ((dbus_int32_t)DBUS_UINT32_SWAP_LE_BE_CONSTANT (val))
50
51 #ifdef WORDS_BIGENDIAN
52 #define DBUS_INT32_TO_BE(val)   ((dbus_int32_t) (val))
53 #define DBUS_UINT32_TO_BE(val)  ((dbus_uint32_t) (val))
54 #define DBUS_INT32_TO_LE(val)   (DBUS_INT32_SWAP_LE_BE (val))
55 #define DBUS_UINT32_TO_LE(val)  (DBUS_UINT32_SWAP_LE_BE (val))
56 #else
57 #define DBUS_INT32_TO_LE(val)   ((dbus_int32_t) (val))
58 #define DBUS_UINT32_TO_LE(val)  ((dbus_uint32_t) (val))
59 #define DBUS_INT32_TO_BE(val)   ((dbus_int32_t) DBUS_UINT32_SWAP_LE_BE (val))
60 #define DBUS_UINT32_TO_BE(val)  (DBUS_UINT32_SWAP_LE_BE (val))
61 #endif
62
63 /* The transformation is symmetric, so the FROM just maps to the TO. */
64 #define DBUS_INT32_FROM_LE(val)  (DBUS_INT32_TO_LE (val))
65 #define DBUS_UINT32_FROM_LE(val) (DBUS_UINT32_TO_LE (val))
66 #define DBUS_INT32_FROM_BE(val)  (DBUS_INT32_TO_BE (val))
67 #define DBUS_UINT32_FROM_BE(val) (DBUS_UINT32_TO_BE (val))
68
69 void          _dbus_pack_int32    (dbus_int32_t         value,
70                                    int                  byte_order,
71                                    unsigned char       *data);
72 dbus_int32_t  _dbus_unpack_int32  (int                  byte_order,
73                                    const unsigned char *data);
74 void          _dbus_pack_uint32   (dbus_uint32_t        value,
75                                    int                  byte_order,
76                                    unsigned char       *data);
77 dbus_uint32_t _dbus_unpack_uint32 (int                  byte_order,
78                                    const unsigned char *data);
79
80 void        _dbus_marshal_set_int32  (DBusString       *str,
81                                       int               byte_order,
82                                       int               offset,
83                                       dbus_int32_t      value);
84 void        _dbus_marshal_set_uint32 (DBusString       *str,
85                                       int               byte_order,
86                                       int               offset,
87                                       dbus_uint32_t     value);
88 dbus_bool_t _dbus_marshal_set_string (DBusString       *str,
89                                       int               byte_order,
90                                       int               offset,
91                                       const DBusString *value);
92
93
94 dbus_bool_t _dbus_marshal_int32       (DBusString          *str,
95                                        int                  byte_order,
96                                        dbus_int32_t         value);
97 dbus_bool_t _dbus_marshal_uint32      (DBusString          *str,
98                                        int                  byte_order,
99                                        dbus_uint32_t        value);
100 dbus_bool_t _dbus_marshal_double      (DBusString          *str,
101                                        int                  byte_order,
102                                        double               value);
103 dbus_bool_t _dbus_marshal_string      (DBusString          *str,
104                                        int                  byte_order,
105                                        const char          *value);
106 dbus_bool_t _dbus_marshal_byte_array  (DBusString          *str,
107                                        int                  byte_order,
108                                        const unsigned char *value,
109                                        int                  len);
110 dbus_bool_t _dbus_marshal_int32_array (DBusString          *str,
111                                        int                  byte_order,
112                                        const dbus_int32_t  *value,
113                                        int                  len);
114 dbus_bool_t _dbus_marshal_uint32_array (DBusString          *str,
115                                         int                  byte_order,
116                                         const dbus_uint32_t  *value,
117                                         int                  len);
118 dbus_bool_t _dbus_marshal_double_array (DBusString          *str,
119                                         int                  byte_order,
120                                         const double        *value,
121                                         int                  len);
122 dbus_bool_t _dbus_marshal_string_array (DBusString          *str,
123                                         int                  byte_order,
124                                         const char         **value,
125                                         int                  len);
126
127 double         _dbus_demarshal_double       (const DBusString *str,
128                                              int               byte_order,
129                                              int               pos,
130                                              int              *new_pos);
131 dbus_int32_t   _dbus_demarshal_int32        (const DBusString *str,
132                                              int               byte_order,
133                                              int               pos,
134                                              int              *new_pos);
135 dbus_uint32_t  _dbus_demarshal_uint32       (const DBusString *str,
136                                              int               byte_order,
137                                              int               pos,
138                                              int              *new_pos);
139 char *         _dbus_demarshal_string       (const DBusString *str,
140                                              int               byte_order,
141                                              int               pos,
142                                              int              *new_pos);
143 unsigned char *_dbus_demarshal_byte_array   (const DBusString *str,
144                                              int               byte_order,
145                                              int               pos,
146                                              int              *new_pos,
147                                              int              *array_len);
148 dbus_int32_t * _dbus_demarshal_int32_array  (const DBusString *str,
149                                              int               byte_order,
150                                              int               pos,
151                                              int              *new_pos,
152                                              int              *array_len);
153 dbus_uint32_t *_dbus_demarshal_uint32_array (const DBusString *str,
154                                              int               byte_order,
155                                              int               pos,
156                                              int              *new_pos,
157                                              int              *array_len);
158 double *       _dbus_demarshal_double_array (const DBusString *str,
159                                              int               byte_order,
160                                              int               pos,
161                                              int              *new_pos,
162                                              int              *array_len);
163 char **        _dbus_demarshal_string_array (const DBusString *str,
164                                              int               byte_order,
165                                              int               pos,
166                                              int              *new_pos,
167                                              int              *array_len);
168
169
170 dbus_bool_t _dbus_marshal_get_arg_end_pos (const DBusString *str,
171                                            int               byte_order,
172                                            int               pos,
173                                            int              *end_pos);
174 dbus_bool_t _dbus_marshal_validate_arg    (const DBusString *str,
175                                            int               byte_order,
176                                            int               pos,
177                                            int              *end_pos);
178
179
180 #endif /* DBUS_PROTOCOL_H */