1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef DBUS_VALUES_UTIL_H_
6 #define DBUS_VALUES_UTIL_H_
7 
8 #include <stdint.h>
9 
10 #include "dbus/dbus_export.h"
11 
12 namespace base {
13 class Value;
14 }
15 
16 namespace dbus {
17 
18 class MessageReader;
19 class MessageWriter;
20 
21 // Pops a value from |reader| as a base::Value.
22 // Returns NULL if an error occurs.
23 // Note: Integer values larger than int32_t (including uint32_t) are converted
24 // to double.  Non-string dictionary keys are converted to strings.
25 CHROME_DBUS_EXPORT base::Value* PopDataAsValue(MessageReader* reader);
26 
27 // Appends a basic type value to |writer|. Basic types are BOOLEAN, INTEGER,
28 // DOUBLE, and STRING. Use this function for values that are known to be basic
29 // types and to handle basic type members of collections that should not
30 // have type "a{sv}" or "av". Otherwise, use AppendValueData.
31 CHROME_DBUS_EXPORT void AppendBasicTypeValueData(MessageWriter* writer,
32                                                  const base::Value& value);
33 
34 // Appends a basic type value to |writer| as a variant. Basic types are BOOLEAN,
35 // INTEGER, DOUBLE, and STRING. Use this function for values that are known to
36 // be basic types and to handle basic type members of collections that should
37 // not have type "a{sv}" or "av". Otherwise, use AppendValueDataAsVariant.
38 CHROME_DBUS_EXPORT void AppendBasicTypeValueDataAsVariant(
39     MessageWriter* writer,
40     const base::Value& value);
41 
42 // Appends a value to |writer|. Value can be a basic type, as well as a
43 // collection type, such as dictionary or list. Collections will be recursively
44 // written as variant containers, i.e. dictionaries will be written with type
45 // a{sv} and lists with type av. Any sub-dictionaries or sub-lists will also
46 // have these types.
47 CHROME_DBUS_EXPORT void AppendValueData(MessageWriter* writer,
48                                         const base::Value& value);
49 
50 // Appends a value to |writer| as a variant. Value can be a basic type, as well
51 // as a collection type, such as dictionary or list. Collections will be
52 // recursively written as variant containers, i.e. dictionaries will be written
53 // with type a{sv} and lists with type av. Any sub-dictionaries or sub-lists
54 // will also have these types.
55 CHROME_DBUS_EXPORT void AppendValueDataAsVariant(MessageWriter* writer,
56                                                  const base::Value& value);
57 
58 }  // namespace dbus
59 
60 #endif  // DBUS_VALUES_UTIL_H_
61