1 /*
2 * Copyright (C) 2023 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "perfetto/protozero/gen_field_helpers.h"
18
19 namespace protozero {
20 namespace internal {
21 namespace gen_helpers {
22
DeserializeString(const protozero::Field & field,std::string * dst)23 void DeserializeString(const protozero::Field& field, std::string* dst) {
24 field.get(dst);
25 }
26
27 template bool DeserializePackedRepeated<proto_utils::ProtoWireType::kVarInt,
28 uint64_t>(const protozero::Field& field,
29 std::vector<uint64_t>* dst);
30
31 template bool DeserializePackedRepeated<proto_utils::ProtoWireType::kVarInt,
32 int64_t>(const protozero::Field& field,
33 std::vector<int64_t>* dst);
34
35 template bool DeserializePackedRepeated<proto_utils::ProtoWireType::kVarInt,
36 uint32_t>(const protozero::Field& field,
37 std::vector<uint32_t>* dst);
38
39 template bool DeserializePackedRepeated<proto_utils::ProtoWireType::kVarInt,
40 int32_t>(const protozero::Field& field,
41 std::vector<int32_t>* dst);
42
SerializeTinyVarInt(uint32_t field_id,bool value,Message * msg)43 void SerializeTinyVarInt(uint32_t field_id, bool value, Message* msg) {
44 msg->AppendTinyVarInt(field_id, value);
45 }
46
47 template void SerializeExtendedVarInt<uint64_t>(uint32_t field_id,
48 uint64_t value,
49 Message* msg);
50
51 template void SerializeExtendedVarInt<uint32_t>(uint32_t field_id,
52 uint32_t value,
53 Message* msg);
54
55 template void SerializeFixed<double>(uint32_t field_id,
56 double value,
57 Message* msg);
58
59 template void SerializeFixed<float>(uint32_t field_id,
60 float value,
61 Message* msg);
62
63 template void SerializeFixed<uint64_t>(uint32_t field_id,
64 uint64_t value,
65 Message* msg);
66
67 template void SerializeFixed<int64_t>(uint32_t field_id,
68 int64_t value,
69 Message* msg);
70
71 template void SerializeFixed<uint32_t>(uint32_t field_id,
72 uint32_t value,
73 Message* msg);
74
75 template void SerializeFixed<int32_t>(uint32_t field_id,
76 int32_t value,
77 Message* msg);
78
SerializeString(uint32_t field_id,const std::string & value,Message * msg)79 void SerializeString(uint32_t field_id,
80 const std::string& value,
81 Message* msg) {
82 msg->AppendString(field_id, value);
83 }
84
SerializeUnknownFields(const std::string & unknown_fields,Message * msg)85 void SerializeUnknownFields(const std::string& unknown_fields, Message* msg) {
86 msg->AppendRawProtoBytes(unknown_fields.data(), unknown_fields.size());
87 }
88
89 MessageSerializer::MessageSerializer() = default;
90
91 MessageSerializer::~MessageSerializer() = default;
92
SerializeAsArray()93 std::vector<uint8_t> MessageSerializer::SerializeAsArray() {
94 return msg_.SerializeAsArray();
95 }
96
SerializeAsString()97 std::string MessageSerializer::SerializeAsString() {
98 return msg_.SerializeAsString();
99 }
100
101 template bool EqualsField<std::string>(const std::string&, const std::string&);
102
103 } // namespace gen_helpers
104 } // namespace internal
105 } // namespace protozero
106