Lines Matching refs:fd
85 bool WriteEnumEqualityOperatorSwitchCases(int fd, in WriteEnumEqualityOperatorSwitchCases() argument
91 dprintf(fd, " case %s::%s: return parent == %s::%s;\n", in WriteEnumEqualityOperatorSwitchCases()
97 [&fd, &child_name, &parent_name](CppType* new_parent) { in WriteEnumEqualityOperatorSwitchCases()
99 fd, *new_parent, child_name, parent_name); in WriteEnumEqualityOperatorSwitchCases()
104 bool WriteEnumEqualityOperator(int fd, in WriteEnumEqualityOperator() argument
111 dprintf(fd, "inline bool operator==(const %s& child, const %s& parent) {\n", in WriteEnumEqualityOperator()
113 dprintf(fd, " switch (child) {\n"); in WriteEnumEqualityOperator()
114 if (!WriteEnumEqualityOperatorSwitchCases(fd, parent, name, parent_name)) { in WriteEnumEqualityOperator()
117 dprintf(fd, " default: return false;\n"); in WriteEnumEqualityOperator()
118 dprintf(fd, " }\n}\n"); in WriteEnumEqualityOperator()
121 dprintf(fd, "inline bool operator==(const %s& parent, const %s& child) {\n", in WriteEnumEqualityOperator()
123 dprintf(fd, " return child == parent;\n}\n"); in WriteEnumEqualityOperator()
126 dprintf(fd, "inline bool operator!=(const %s& child, const %s& parent) {\n", in WriteEnumEqualityOperator()
128 dprintf(fd, " return !(child == parent);\n}\n"); in WriteEnumEqualityOperator()
131 dprintf(fd, "inline bool operator!=(const %s& parent, const %s& child) {\n", in WriteEnumEqualityOperator()
133 dprintf(fd, " return !(parent == child);\n}\n"); in WriteEnumEqualityOperator()
138 bool WriteEnumStreamOperatorSwitchCases(int fd, in WriteEnumStreamOperatorSwitchCases() argument
143 dprintf(fd, " case %s::%s: os << \"%s\"; break;\n", name.c_str(), in WriteEnumStreamOperatorSwitchCases()
148 type.enum_type.sub_members, [&fd, &name](CppType* parent) { in WriteEnumStreamOperatorSwitchCases()
149 return WriteEnumStreamOperatorSwitchCases(fd, *parent, name); in WriteEnumStreamOperatorSwitchCases()
153 bool WriteEnumOperators(int fd, const CppType& type) { in WriteEnumOperators() argument
157 fd, in WriteEnumOperators()
160 dprintf(fd, " switch (val) {\n"); in WriteEnumOperators()
161 if (!WriteEnumStreamOperatorSwitchCases(fd, type, name)) { in WriteEnumOperators()
164 dprintf(fd, in WriteEnumOperators()
170 [&fd, &type](CppType* parent) { in WriteEnumOperators()
171 return WriteEnumEqualityOperator(fd, type, *parent); in WriteEnumOperators()
177 int fd, in WriteDiscriminatedUnionEqualityOperator() argument
181 dprintf(fd, "\nbool %s::operator==(const %s& other) const {\n", name.c_str(), in WriteDiscriminatedUnionEqualityOperator()
183 dprintf(fd, " return this->which == other.which"); in WriteDiscriminatedUnionEqualityOperator()
185 dprintf(fd, " &&\n "); in WriteDiscriminatedUnionEqualityOperator()
188 dprintf(fd, in WriteDiscriminatedUnionEqualityOperator()
192 dprintf(fd, in WriteDiscriminatedUnionEqualityOperator()
196 dprintf(fd, in WriteDiscriminatedUnionEqualityOperator()
203 dprintf(fd, ";\n}\n"); in WriteDiscriminatedUnionEqualityOperator()
204 dprintf(fd, "bool %s::operator!=(const %s& other) const {\n", name.c_str(), in WriteDiscriminatedUnionEqualityOperator()
206 dprintf(fd, " return !(*this == other);\n}\n"); in WriteDiscriminatedUnionEqualityOperator()
211 bool WriteStructEqualityOperator(int fd, in WriteStructEqualityOperator() argument
215 dprintf(fd, "\nbool %s::operator==(const %s& other) const {\n", name.c_str(), in WriteStructEqualityOperator()
219 dprintf(fd, " return "); in WriteStructEqualityOperator()
221 dprintf(fd, " &&\n "); in WriteStructEqualityOperator()
224 dprintf(fd, "this->%s == other.%s", name.c_str(), name.c_str()); in WriteStructEqualityOperator()
226 dprintf(fd, ";\n}"); in WriteStructEqualityOperator()
227 dprintf(fd, "\nbool %s::operator!=(const %s& other) const {\n", name.c_str(), in WriteStructEqualityOperator()
229 dprintf(fd, " return !(*this == other);\n}\n"); in WriteStructEqualityOperator()
235 if (!WriteDiscriminatedUnionEqualityOperator(fd, *x.type, new_prefix)) { in WriteStructEqualityOperator()
246 int fd, in WriteStructMembers() argument
255 if (!WriteStructMembers(fd, x.type->name, in WriteStructMembers()
265 dprintf(fd, " bool has_%s;\n", ToUnderscoreId(x.name).c_str()); in WriteStructMembers()
271 dprintf(fd, " struct %s {\n", type_string.c_str()); in WriteStructMembers()
272 dprintf(fd, " %s();\n ~%s();\n\n", type_string.c_str(), in WriteStructMembers()
275 dprintf(fd, " bool operator==(const %s& other) const;\n", in WriteStructMembers()
277 dprintf(fd, " bool operator!=(const %s& other) const;\n\n", in WriteStructMembers()
279 dprintf(fd, " enum class Which {\n"); in WriteStructMembers()
283 dprintf(fd, " kUint64,\n"); in WriteStructMembers()
286 dprintf(fd, " kString,\n"); in WriteStructMembers()
289 dprintf(fd, " kBytes,\n"); in WriteStructMembers()
295 dprintf(fd, " kUninitialized,\n"); in WriteStructMembers()
296 dprintf(fd, " } which;\n"); in WriteStructMembers()
297 dprintf(fd, " union {\n"); in WriteStructMembers()
301 dprintf(fd, " uint64_t uint;\n"); in WriteStructMembers()
304 dprintf(fd, " std::string str;\n"); in WriteStructMembers()
307 dprintf(fd, " std::vector<uint8_t> bytes;\n"); in WriteStructMembers()
315 dprintf(fd, " bool placeholder_;\n"); in WriteStructMembers()
316 dprintf(fd, " };\n"); in WriteStructMembers()
317 dprintf(fd, " };\n"); in WriteStructMembers()
325 dprintf(fd, " %s %s;\n", type_string.c_str(), in WriteStructMembers()
331 void WriteEnumMembers(int fd, const CppType& type) { in WriteEnumMembers() argument
333 dprintf(fd, " k%s = %" PRIu64 "ull,\n", ToCamelCase(x.first).c_str(), in WriteEnumMembers()
337 WriteEnumMembers(fd, *x); in WriteEnumMembers()
343 bool WriteTypeDefinition(int fd, const CppType& type) { in WriteTypeDefinition() argument
347 dprintf(fd, "\nenum class %s : uint64_t {\n", name.c_str()); in WriteTypeDefinition()
348 WriteEnumMembers(fd, type); in WriteTypeDefinition()
349 dprintf(fd, "};\n"); in WriteTypeDefinition()
350 if (!WriteEnumOperators(fd, type)) in WriteTypeDefinition()
354 dprintf(fd, "\nstruct %s {\n", name.c_str()); in WriteTypeDefinition()
356 dprintf(fd, " // type key: %" PRIu64 "\n", type.type_key.value()); in WriteTypeDefinition()
358 dprintf(fd, " bool operator==(const %s& other) const;\n", name.c_str()); in WriteTypeDefinition()
359 dprintf(fd, " bool operator!=(const %s& other) const;\n\n", in WriteTypeDefinition()
361 if (!WriteStructMembers(fd, type.name, type.struct_type.members)) in WriteTypeDefinition()
363 dprintf(fd, "};\n"); in WriteTypeDefinition()
377 bool EnsureDependentTypeDefinitionsWritten(int fd, in EnsureDependentTypeDefinitionsWritten() argument
383 fd, *cpp_type.vector_type.element_type, defs); in EnsureDependentTypeDefinitionsWritten()
389 if (!EnsureDependentTypeDefinitionsWritten(fd, *x, defs)) in EnsureDependentTypeDefinitionsWritten()
392 WriteTypeDefinition(fd, cpp_type); in EnsureDependentTypeDefinitionsWritten()
400 if (!EnsureDependentTypeDefinitionsWritten(fd, *x.type, defs)) in EnsureDependentTypeDefinitionsWritten()
403 WriteTypeDefinition(fd, cpp_type); in EnsureDependentTypeDefinitionsWritten()
407 return EnsureDependentTypeDefinitionsWritten(fd, *cpp_type.optional_type, in EnsureDependentTypeDefinitionsWritten()
412 if (!EnsureDependentTypeDefinitionsWritten(fd, *x, defs)) in EnsureDependentTypeDefinitionsWritten()
417 fd, *cpp_type.tagged_type.real_type, defs)) { in EnsureDependentTypeDefinitionsWritten()
443 bool WriteTypeDefinitions(int fd, CppSymbolTable* table) { in WriteTypeDefinitions() argument
451 if (!EnsureDependentTypeDefinitionsWritten(fd, *real_type, &defs)) in WriteTypeDefinitions()
455 dprintf(fd, "\nenum class Type : uint64_t {\n"); in WriteTypeDefinitions()
456 dprintf(fd, " kUnknown = 0ull,\n"); in WriteTypeDefinitions()
458 dprintf(fd, " k%s = %" PRIu64 "ull,\n", ToCamelCase(type->name).c_str(), in WriteTypeDefinitions()
461 dprintf(fd, "};\n"); in WriteTypeDefinitions()
469 bool WriteTypeParserDefinition(int fd, CppSymbolTable* table) { in WriteTypeParserDefinition() argument
470 dprintf(fd, "\n//static\n"); in WriteTypeParserDefinition()
471 dprintf(fd, "Type TypeEnumValidator::SafeCast(uint64_t type_id) {\n"); in WriteTypeParserDefinition()
472 dprintf(fd, " switch (type_id) {\n"); in WriteTypeParserDefinition()
474 dprintf(fd, " case uint64_t{%" PRIu64 "}: return Type::k%s;\n", in WriteTypeParserDefinition()
477 dprintf(fd, " default: return Type::kUnknown;\n"); in WriteTypeParserDefinition()
478 dprintf(fd, " }\n}\n"); in WriteTypeParserDefinition()
484 bool WriteFunctionDeclarations(int fd, CppSymbolTable* table) { in WriteFunctionDeclarations() argument
493 dprintf(fd, "\nbool Encode%s(\n", cpp_name.c_str()); in WriteFunctionDeclarations()
494 dprintf(fd, " const %s& data,\n", cpp_name.c_str()); in WriteFunctionDeclarations()
495 dprintf(fd, " CborEncodeBuffer* buffer);\n"); in WriteFunctionDeclarations()
496 dprintf(fd, "ssize_t Encode%s(\n", cpp_name.c_str()); in WriteFunctionDeclarations()
497 dprintf(fd, " const %s& data,\n", cpp_name.c_str()); in WriteFunctionDeclarations()
498 dprintf(fd, " uint8_t* buffer,\n size_t length);\n"); in WriteFunctionDeclarations()
499 dprintf(fd, "ssize_t Decode%s(\n", cpp_name.c_str()); in WriteFunctionDeclarations()
500 dprintf(fd, " const uint8_t* buffer,\n size_t length,\n"); in WriteFunctionDeclarations()
501 dprintf(fd, " %s* data);\n", cpp_name.c_str()); in WriteFunctionDeclarations()
506 bool WriteMapEncoder(int fd,
511 bool WriteArrayEncoder(int fd,
522 bool WriteEncoder(int fd, in WriteEncoder() argument
530 if (!WriteMapEncoder(fd, name, cpp_type.struct_type.members, in WriteEncoder()
537 if (!WriteArrayEncoder(fd, name, cpp_type.struct_type.members, in WriteEncoder()
545 dprintf(fd, in WriteEncoder()
550 dprintf(fd, in WriteEncoder()
555 if (!WriteEncoder(fd, name + "." + ToUnderscoreId(x.name), *x.type, in WriteEncoder()
564 dprintf(fd, " CBOR_RETURN_ON_ERROR(cbor_encode_uint(&encoder%d, %s));\n", in WriteEncoder()
570 dprintf(fd, " if (!IsValidUtf8(%s)) {\n", cid.c_str()); in WriteEncoder()
571 dprintf(fd, " return -CborErrorInvalidUtf8TextString;\n"); in WriteEncoder()
572 dprintf(fd, " }\n"); in WriteEncoder()
573 dprintf(fd, in WriteEncoder()
581 dprintf(fd, in WriteEncoder()
590 dprintf(fd, " {\n"); in WriteEncoder()
593 dprintf(fd, " if (%s.size() < %d) {\n", cid.c_str(), in WriteEncoder()
595 dprintf(fd, " return -CborErrorTooFewItems;\n"); in WriteEncoder()
596 dprintf(fd, " }\n"); in WriteEncoder()
600 dprintf(fd, " if (%s.size() > %d) {\n", cid.c_str(), in WriteEncoder()
602 dprintf(fd, " return -CborErrorTooManyItems;\n"); in WriteEncoder()
603 dprintf(fd, " }\n"); in WriteEncoder()
605 dprintf(fd, " CborEncoder encoder%d;\n", encoder_depth + 1); in WriteEncoder()
606 dprintf(fd, in WriteEncoder()
610 dprintf(fd, " for (const auto& x : %s) {\n", cid.c_str()); in WriteEncoder()
611 if (!WriteEncoder(fd, "x", *cpp_type.vector_type.element_type, in WriteEncoder()
615 dprintf(fd, " }\n"); in WriteEncoder()
616 dprintf(fd, in WriteEncoder()
620 dprintf(fd, " }\n"); in WriteEncoder()
624 dprintf(fd, in WriteEncoder()
634 dprintf(fd, " case %s::%s::Which::kUint64:\n", in WriteEncoder()
637 if (!WriteEncoder(fd, ToUnderscoreId(name + ".uint"), *union_member, in WriteEncoder()
641 dprintf(fd, " break;\n"); in WriteEncoder()
644 dprintf(fd, " case %s::%s::Which::kString:\n", in WriteEncoder()
647 if (!WriteEncoder(fd, ToUnderscoreId(name + ".str"), *union_member, in WriteEncoder()
651 dprintf(fd, " break;\n"); in WriteEncoder()
654 dprintf(fd, " case %s::%s::Which::kBytes:\n", in WriteEncoder()
657 if (!WriteEncoder(fd, ToUnderscoreId(name + ".bytes"), in WriteEncoder()
662 dprintf(fd, " break;\n"); in WriteEncoder()
668 dprintf(fd, " case %s::%s::Which::kUninitialized:\n", in WriteEncoder()
671 dprintf(fd, " return -CborUnknownError;\n"); in WriteEncoder()
675 dprintf(fd, in WriteEncoder()
679 if (!WriteEncoder(fd, name, *cpp_type.tagged_type.real_type, in WriteEncoder()
697 int fd, in CountMemberTypes() argument
706 dprintf(fd, " int num_optionals_present = %s.has_%s;\n", in CountMemberTypes()
709 dprintf(fd, " num_optionals_present += %s.has_%s;\n", name_id.c_str(), in CountMemberTypes()
726 bool WriteMapEncoder(int fd, in WriteMapEncoder() argument
732 dprintf(fd, " CborEncoder encoder%d;\n", encoder_depth); in WriteMapEncoder()
733 MemberCountResult member_counts = CountMemberTypes(fd, name_id, members); in WriteMapEncoder()
735 dprintf(fd, in WriteMapEncoder()
741 dprintf(fd, in WriteMapEncoder()
755 dprintf(fd, " if (%s.has_%s) {\n", name_id.c_str(), in WriteMapEncoder()
760 dprintf(fd, in WriteMapEncoder()
765 dprintf(fd, in WriteMapEncoder()
771 dprintf(fd, " switch (%s.%s.which) {\n", fullname.c_str(), in WriteMapEncoder()
776 if (!WriteEncoder(fd, fullname, *member_type, nested_type_scope, in WriteMapEncoder()
782 dprintf(fd, " }\n"); in WriteMapEncoder()
786 dprintf(fd, in WriteMapEncoder()
799 bool WriteArrayEncoder(int fd, in WriteArrayEncoder() argument
805 dprintf(fd, " CborEncoder encoder%d;\n", encoder_depth); in WriteArrayEncoder()
806 MemberCountResult member_counts = CountMemberTypes(fd, name_id, members); in WriteArrayEncoder()
808 dprintf(fd, in WriteArrayEncoder()
813 dprintf(fd, in WriteArrayEncoder()
826 dprintf(fd, " if (%s.has_%s) {\n", name_id.c_str(), in WriteArrayEncoder()
830 dprintf(fd, " switch (%s.%s.which) {\n", fullname.c_str(), in WriteArrayEncoder()
835 if (!WriteEncoder(fd, fullname, *member_type, nested_type_scope, in WriteArrayEncoder()
841 dprintf(fd, " }\n"); in WriteArrayEncoder()
845 dprintf(fd, in WriteArrayEncoder()
895 bool WriteEncoders(int fd, CppSymbolTable* table) { in WriteEncoders() argument
909 dprintf(fd, "\n%s::%s::%s()\n", cpp_name.c_str(), dunion_cpp_name.c_str(), in WriteEncoders()
913 dprintf(fd, in WriteEncoders()
916 dprintf(fd, "\n%s::%s::~%s() {\n", cpp_name.c_str(), in WriteEncoders()
918 dprintf(fd, " switch (which) {\n"); in WriteEncoders()
922 dprintf(fd, " case Which::kUint64: break;\n"); in WriteEncoders()
925 dprintf(fd, " case Which::kString:\n"); in WriteEncoders()
926 dprintf(fd, " str.std::string::~basic_string();\n"); in WriteEncoders()
927 dprintf(fd, " break;\n"); in WriteEncoders()
930 dprintf(fd, " case Which::kBytes:\n"); in WriteEncoders()
931 dprintf(fd, " bytes.std::vector<uint8_t>::~vector();\n"); in WriteEncoders()
932 dprintf(fd, " break;\n"); in WriteEncoders()
938 dprintf(fd, " case Which::kUninitialized: break;\n"); in WriteEncoders()
939 dprintf(fd, " }\n"); in WriteEncoders()
940 dprintf(fd, "}\n"); in WriteEncoders()
977 dprintf(fd, vector_encode_function, cpp_name.c_str(), encoded_id.c_str()); in WriteEncoders()
978 dprintf(fd, "\nssize_t Encode%s(\n", cpp_name.c_str()); in WriteEncoders()
979 dprintf(fd, " const %s& data,\n", cpp_name.c_str()); in WriteEncoders()
980 dprintf(fd, " uint8_t* buffer,\n size_t length) {\n"); in WriteEncoders()
981 dprintf(fd, " CborEncoder encoder0;\n"); in WriteEncoders()
982 dprintf(fd, " cbor_encoder_init(&encoder0, buffer, length, 0);\n"); in WriteEncoders()
985 if (!WriteMapEncoder(fd, "data", real_type->struct_type.members, name)) in WriteEncoders()
988 if (!WriteArrayEncoder(fd, "data", real_type->struct_type.members, in WriteEncoders()
994 dprintf(fd, in WriteEncoders()
997 dprintf(fd, " if (extra_bytes_needed) {\n"); in WriteEncoders()
998 dprintf(fd, in WriteEncoders()
1000 dprintf(fd, " } else {\n"); in WriteEncoders()
1001 dprintf(fd, in WriteEncoders()
1005 dprintf(fd, " }\n"); in WriteEncoders()
1006 dprintf(fd, "}\n"); in WriteEncoders()
1011 bool WriteMapDecoder(int fd,
1017 bool WriteArrayDecoder(int fd,
1031 bool WriteDecoder(int fd, in WriteDecoder() argument
1039 dprintf(fd, in WriteDecoder()
1042 dprintf(fd, " CBOR_RETURN_ON_ERROR(cbor_value_advance_fixed(&it%d));\n", in WriteDecoder()
1048 dprintf(fd, " size_t length%d = 0;", temp_length); in WriteDecoder()
1049 dprintf(fd, in WriteDecoder()
1053 dprintf(fd, " if (cbor_value_is_length_known(&it%d)) {\n", in WriteDecoder()
1055 dprintf(fd, in WriteDecoder()
1059 dprintf(fd, " } else {\n"); in WriteDecoder()
1061 fd, in WriteDecoder()
1065 dprintf(fd, " }\n"); in WriteDecoder()
1066 dprintf(fd, " %s%sresize(length%d);\n", name.c_str(), in WriteDecoder()
1068 dprintf(fd, in WriteDecoder()
1073 dprintf(fd, " CBOR_RETURN_ON_ERROR(cbor_value_advance(&it%d));\n", in WriteDecoder()
1079 dprintf(fd, " size_t length%d = 0;", temp_length); in WriteDecoder()
1080 dprintf(fd, " if (cbor_value_is_length_known(&it%d)) {\n", in WriteDecoder()
1082 dprintf(fd, in WriteDecoder()
1086 dprintf(fd, " } else {\n"); in WriteDecoder()
1088 fd, in WriteDecoder()
1092 dprintf(fd, " }\n"); in WriteDecoder()
1094 dprintf(fd, " %s%sresize(length%d);\n", name.c_str(), in WriteDecoder()
1097 dprintf(fd, " if (length%d < %d) {\n", temp_length, in WriteDecoder()
1099 dprintf(fd, " return -CborErrorTooFewItems;\n"); in WriteDecoder()
1100 dprintf(fd, " } else if (length%d > %d) {\n", temp_length, in WriteDecoder()
1102 dprintf(fd, " return -CborErrorTooManyItems;\n"); in WriteDecoder()
1103 dprintf(fd, " }\n"); in WriteDecoder()
1105 dprintf(fd, in WriteDecoder()
1110 dprintf(fd, " CBOR_RETURN_ON_ERROR(cbor_value_advance(&it%d));\n", in WriteDecoder()
1115 dprintf(fd, " if (cbor_value_get_type(&it%d) != CborArrayType) {\n", in WriteDecoder()
1117 dprintf(fd, " return -1;\n"); in WriteDecoder()
1118 dprintf(fd, " }\n"); in WriteDecoder()
1119 dprintf(fd, " {\n"); in WriteDecoder()
1120 dprintf(fd, " CborValue it%d;\n", decoder_depth + 1); in WriteDecoder()
1121 dprintf(fd, " size_t it%d_length = 0;\n", decoder_depth + 1); in WriteDecoder()
1122 dprintf(fd, in WriteDecoder()
1128 dprintf(fd, " if (it%d_length < %d) {\n", decoder_depth + 1, in WriteDecoder()
1130 dprintf(fd, " return -CborErrorTooFewItems;\n"); in WriteDecoder()
1131 dprintf(fd, " }\n"); in WriteDecoder()
1135 dprintf(fd, " if (it%d_length > %d) {\n", decoder_depth + 1, in WriteDecoder()
1137 dprintf(fd, " return -CborErrorTooManyItems;\n"); in WriteDecoder()
1138 dprintf(fd, " }\n"); in WriteDecoder()
1140 dprintf(fd, " %s%sresize(it%d_length);\n", name.c_str(), in WriteDecoder()
1143 fd, in WriteDecoder()
1146 dprintf(fd, " for (auto i = %s%sbegin(); i != %s%send(); ++i) {\n", in WriteDecoder()
1149 if (!WriteDecoder(fd, "(*i)", ".", *cpp_type.vector_type.element_type, in WriteDecoder()
1153 dprintf(fd, " }\n"); in WriteDecoder()
1155 fd, in WriteDecoder()
1158 dprintf(fd, " }\n"); in WriteDecoder()
1162 dprintf(fd, in WriteDecoder()
1166 dprintf(fd, " CBOR_RETURN_ON_ERROR(cbor_value_advance_fixed(&it%d));\n", in WriteDecoder()
1173 return WriteMapDecoder(fd, name, member_accessor, in WriteDecoder()
1178 return WriteArrayDecoder(fd, name, member_accessor, in WriteDecoder()
1185 dprintf(fd, " CborType type%d = cbor_value_get_type(&it%d);\n", in WriteDecoder()
1192 dprintf(fd, " else "); in WriteDecoder()
1195 dprintf(fd, in WriteDecoder()
1199 dprintf(fd, " %s.which = decltype(%s)::Which::kUint64;\n", in WriteDecoder()
1201 if (!WriteDecoder(fd, name + ".uint", ".", *x, decoder_depth, in WriteDecoder()
1207 dprintf(fd, " if (type%d == CborTextStringType) {\n", in WriteDecoder()
1209 dprintf(fd, " %s.which = decltype(%s)::Which::kString;\n", in WriteDecoder()
1212 dprintf(fd, " new (&%s) std::string();\n", str_name.c_str()); in WriteDecoder()
1213 if (!WriteDecoder(fd, str_name, ".", *x, decoder_depth, in WriteDecoder()
1219 dprintf(fd, " if (type%d == CborByteStringType) {\n", in WriteDecoder()
1222 dprintf(fd, " %s.which = decltype(%s)::Which::kBytes;\n", in WriteDecoder()
1224 dprintf(fd, " new (&%s) std::vector<uint8_t>();\n", in WriteDecoder()
1226 if (!WriteDecoder(fd, bytes_name, ".", *x, decoder_depth, in WriteDecoder()
1234 dprintf(fd, " }\n"); in WriteDecoder()
1236 dprintf(fd, " else { return -1; }\n"); in WriteDecoder()
1241 dprintf(fd, " uint64_t tag%d = 0;\n", temp_tag); in WriteDecoder()
1242 dprintf(fd, " cbor_value_get_tag(&it%d, &tag%d);\n", decoder_depth, in WriteDecoder()
1244 dprintf(fd, " if (tag%d != %" PRIu64 "ull) {\n", temp_tag, in WriteDecoder()
1246 dprintf(fd, " return -1;\n"); in WriteDecoder()
1247 dprintf(fd, " }\n"); in WriteDecoder()
1248 dprintf(fd, " CBOR_RETURN_ON_ERROR(cbor_value_advance_fixed(&it%d));\n", in WriteDecoder()
1250 if (!WriteDecoder(fd, name, member_accessor, in WriteDecoder()
1270 bool WriteMapDecoder(int fd, in WriteMapDecoder() argument
1276 dprintf(fd, " if (cbor_value_get_type(&it%d) != CborMapType) {\n", in WriteMapDecoder()
1278 dprintf(fd, " return -1;\n"); in WriteMapDecoder()
1279 dprintf(fd, " }\n"); in WriteMapDecoder()
1280 dprintf(fd, " CborValue it%d;\n", decoder_depth); in WriteMapDecoder()
1281 dprintf(fd, " size_t it%d_length = 0;\n", decoder_depth); in WriteMapDecoder()
1282 dprintf(fd, in WriteMapDecoder()
1292 dprintf(fd, " if (it%d_length != %d", decoder_depth, in WriteMapDecoder()
1295 dprintf(fd, " && it%d_length != %d", decoder_depth, in WriteMapDecoder()
1298 dprintf(fd, ") {\n"); in WriteMapDecoder()
1299 dprintf(fd, " return -1;\n"); in WriteMapDecoder()
1300 dprintf(fd, " }\n"); in WriteMapDecoder()
1301 dprintf(fd, in WriteMapDecoder()
1311 dprintf(fd, " if (it%d_length > %d) {\n", decoder_depth, member_pos); in WriteMapDecoder()
1314 dprintf(fd, in WriteMapDecoder()
1319 dprintf(fd, in WriteMapDecoder()
1323 dprintf(fd, " %s%shas_%s = true;\n", name.c_str(), in WriteMapDecoder()
1325 if (!WriteDecoder(fd, fullname, ".", *x.type->optional_type, in WriteMapDecoder()
1329 dprintf(fd, " } else {\n"); in WriteMapDecoder()
1330 dprintf(fd, " %s%shas_%s = false;\n", name.c_str(), in WriteMapDecoder()
1332 dprintf(fd, " }\n"); in WriteMapDecoder()
1335 dprintf(fd, in WriteMapDecoder()
1340 dprintf(fd, in WriteMapDecoder()
1344 if (!WriteDecoder(fd, fullname, ".", *x.type, decoder_depth, in WriteMapDecoder()
1351 dprintf(fd, in WriteMapDecoder()
1364 bool WriteArrayDecoder(int fd, in WriteArrayDecoder() argument
1370 dprintf(fd, " if (cbor_value_get_type(&it%d) != CborArrayType) {\n", in WriteArrayDecoder()
1372 dprintf(fd, " return -1;\n"); in WriteArrayDecoder()
1373 dprintf(fd, " }\n"); in WriteArrayDecoder()
1374 dprintf(fd, " CborValue it%d;\n", decoder_depth); in WriteArrayDecoder()
1375 dprintf(fd, " size_t it%d_length = 0;\n", decoder_depth); in WriteArrayDecoder()
1376 dprintf(fd, in WriteArrayDecoder()
1386 dprintf(fd, " if (it%d_length != %d", decoder_depth, in WriteArrayDecoder()
1389 dprintf(fd, " && it%d_length != %d", decoder_depth, in WriteArrayDecoder()
1392 dprintf(fd, ") {\n"); in WriteArrayDecoder()
1393 dprintf(fd, " return -1;\n"); in WriteArrayDecoder()
1394 dprintf(fd, " }\n"); in WriteArrayDecoder()
1395 dprintf(fd, in WriteArrayDecoder()
1409 dprintf(fd, " if (it%d_length > %d) {\n", decoder_depth, member_pos); in WriteArrayDecoder()
1410 dprintf(fd, " %s%shas_%s = true;\n", name.c_str(), in WriteArrayDecoder()
1412 if (!WriteDecoder(fd, fullname, ".", *x.type->optional_type, in WriteArrayDecoder()
1416 dprintf(fd, " } else {\n"); in WriteArrayDecoder()
1417 dprintf(fd, " %s%shas_%s = false;\n", name.c_str(), in WriteArrayDecoder()
1419 dprintf(fd, " }\n"); in WriteArrayDecoder()
1421 if (!WriteDecoder(fd, fullname, ".", *x.type, decoder_depth, in WriteArrayDecoder()
1428 dprintf(fd, in WriteArrayDecoder()
1435 bool WriteEqualityOperators(int fd, CppSymbolTable* table) { in WriteEqualityOperators() argument
1441 if (!WriteStructEqualityOperator(fd, *real_type)) { in WriteEqualityOperators()
1451 bool WriteDecoders(int fd, CppSymbolTable* table) { in WriteDecoders() argument
1452 if (!WriteTypeParserDefinition(fd, table)) { in WriteDecoders()
1464 dprintf(fd, "\nssize_t Decode%s(\n", cpp_name.c_str()); in WriteDecoders()
1465 dprintf(fd, " const uint8_t* buffer,\n size_t length,\n"); in WriteDecoders()
1466 dprintf(fd, " %s* data) {\n", cpp_name.c_str()); in WriteDecoders()
1467 dprintf(fd, " CborParser parser;\n"); in WriteDecoders()
1468 dprintf(fd, " CborValue it0;\n"); in WriteDecoders()
1470 fd, in WriteDecoders()
1474 if (!WriteMapDecoder(fd, "data", "->", real_type->struct_type.members, 1, in WriteDecoders()
1479 if (!WriteArrayDecoder(fd, "data", "->", real_type->struct_type.members, in WriteDecoders()
1485 fd, in WriteDecoders()
1488 dprintf(fd, " return result;\n"); in WriteDecoders()
1489 dprintf(fd, "}\n"); in WriteDecoders()
1508 bool WriteHeaderPrologue(int fd, const std::string& header_filename) { in WriteHeaderPrologue() argument
1531 dprintf(fd, prologue, header_guard.c_str(), header_guard.c_str()); in WriteHeaderPrologue()
1535 bool WriteHeaderEpilogue(int fd, const std::string& header_filename) { in WriteHeaderEpilogue() argument
1574 dprintf(fd, epilogue, header_guard.c_str()); in WriteHeaderEpilogue()
1578 bool WriteSourcePrologue(int fd, const std::string& header_filename) { in WriteSourcePrologue() argument
1703 dprintf(fd, prologue, header_filename.c_str()); in WriteSourcePrologue()
1707 bool WriteSourceEpilogue(int fd) { in WriteSourceEpilogue() argument
1711 dprintf(fd, epilogue); in WriteSourceEpilogue()