1 : // Copyright 2014 Google Inc. All Rights Reserved.
2 : //
3 : // Licensed under the Apache License, Version 2.0 (the "License");
4 : // you may not use this file except in compliance with the License.
5 : // You may obtain a copy of the License at
6 : //
7 : // http://www.apache.org/licenses/LICENSE-2.0
8 : //
9 : // Unless required by applicable law or agreed to in writing, software
10 : // distributed under the License is distributed on an "AS IS" BASIS,
11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 : // See the License for the specific language governing permissions and
13 : // limitations under the License.
14 :
15 : #include "syzygy/crashdata/crashdata.h"
16 :
17 : // This uses 'assert' and not base DCHECKs so that it is portable.
18 : #include <assert.h>
19 :
20 : namespace crashdata {
21 :
22 E : Leaf* ValueGetLeaf(Value* value) {
23 E : assert(value != nullptr);
24 E : value->set_type(Value_Type_LEAF);
25 E : return value->mutable_leaf();
26 E : }
27 :
28 E : List* ValueGetList(Value* value) {
29 E : assert(value != nullptr);
30 E : value->set_type(Value_Type_LIST);
31 E : return value->mutable_list();
32 E : }
33 :
34 E : Dictionary* ValueGetDict(Value* value) {
35 E : assert(value != nullptr);
36 E : value->set_type(Value_Type_DICTIONARY);
37 E : return value->mutable_dictionary();
38 E : }
39 :
40 E : Value* DictAddValue(const char* key, Dictionary* dict) {
41 E : assert(key != nullptr);
42 E : assert(dict != nullptr);
43 E : KeyValue* kv = dict->add_values();
44 E : kv->set_key(key);
45 E : return kv->mutable_value();
46 E : }
47 :
48 E : Value* DictAddValue(const std::string& key, Dictionary* dict) {
49 E : assert(dict != nullptr);
50 E : return DictAddValue(key.c_str(), dict);
51 E : }
52 :
53 E : Leaf* DictAddLeaf(const char* key, Dictionary* dict) {
54 E : assert(key != nullptr);
55 E : assert(dict != nullptr);
56 E : Value* v = DictAddValue(key, dict);
57 E : Leaf* l = ValueGetLeaf(v);
58 E : return l;
59 E : }
60 :
61 E : Leaf* DictAddLeaf(const std::string& key, Dictionary* dict) {
62 E : assert(dict != nullptr);
63 E : return DictAddLeaf(key.c_str(), dict);
64 E : }
65 :
66 E : void LeafSetInt(google::protobuf::int64 value, Leaf* leaf) {
67 E : assert(leaf != nullptr);
68 E : leaf->set_type(Leaf_Type_INTEGER);
69 E : leaf->set_integer(value);
70 E : }
71 :
72 E : void LeafSetUInt(google::protobuf::uint64 value, Leaf* leaf) {
73 E : assert(leaf != nullptr);
74 E : leaf->set_type(Leaf_Type_UNSIGNED_INTEGER);
75 E : leaf->set_unsigned_integer(value);
76 E : }
77 :
78 E : void LeafSetReal(double value, Leaf* leaf) {
79 E : assert(leaf != nullptr);
80 E : leaf->set_type(Leaf_Type_REAL);
81 E : leaf->set_real(value);
82 E : }
83 :
84 E : std::string* LeafGetString(Leaf* leaf) {
85 E : assert(leaf != nullptr);
86 E : leaf->set_type(Leaf_Type_STRING);
87 E : return leaf->mutable_string();
88 E : }
89 :
90 E : Address* LeafGetAddress(Leaf* leaf) {
91 E : assert(leaf != nullptr);
92 E : leaf->set_type(Leaf_Type_ADDRESS);
93 E : return leaf->mutable_address();
94 E : }
95 :
96 E : StackTrace* LeafGetStackTrace(Leaf* leaf) {
97 E : assert(leaf != nullptr);
98 E : leaf->set_type(Leaf_Type_STACK_TRACE);
99 E : return leaf->mutable_stack_trace();
100 E : }
101 :
102 E : Blob* LeafGetBlob(Leaf* leaf) {
103 E : assert(leaf != nullptr);
104 E : leaf->set_type(Leaf_Type_BLOB);
105 E : return leaf->mutable_blob();
106 E : }
107 :
108 : } // namespace crashdata
|