Home | History | Annotate | Download | only in base
      1 // Copyright 2018 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 module mojo_base.mojom;
      6 
      7 // Value represents a value that can be serialized to/from JSON.
      8 //
      9 // One notable caveat is that Value supports arbitrary binary data, which JSON
     10 // does not support natively.
     11 union Value {
     12   // Null type placeholder. This field is never used.
     13   uint8 null_value;
     14   // Primitive types.
     15   bool bool_value;
     16   int32 int_value;
     17   double double_value;
     18   // Unicode string.
     19   string string_value;
     20   // Binary blob with arbitrary bytes. Not supported for JSON.
     21   array<uint8> binary_value;
     22   // Basic container support for lists and maps.
     23   DictionaryValue dictionary_value;
     24   ListValue list_value;
     25 };
     26 
     27 // Interfaces that only want to handle a value of dictionary or list type
     28 // should use base.mojom.DictionaryValue or base.mojom.ListValue in the method
     29 // declaration. Though both of these types are mapped to base::Value in C++,
     30 // the generated deserialization will guarantee that the method is only invoked
     31 // with a base::Value of the correct subtype.
     32 struct DictionaryValue {
     33   map<string, Value> storage;
     34 };
     35 
     36 struct ListValue {
     37   array<Value> storage;
     38 };
     39