Lines Matching full:fd

86 bool WriteEnumEqualityOperatorSwitchCases(int fd,  in WriteEnumEqualityOperatorSwitchCases()  argument
92 dprintf(fd, " case %s::%s: return parent == %s::%s;\n", in WriteEnumEqualityOperatorSwitchCases()
98 [&fd, &child_name, &parent_name](CppType* new_parent) { in WriteEnumEqualityOperatorSwitchCases()
100 fd, *new_parent, child_name, parent_name); in WriteEnumEqualityOperatorSwitchCases()
105 bool WriteEnumEqualityOperator(int fd, in WriteEnumEqualityOperator() argument
112 dprintf(fd, "inline bool operator==(const %s& child, const %s& parent) {\n", in WriteEnumEqualityOperator()
114 dprintf(fd, " switch (child) {\n"); in WriteEnumEqualityOperator()
115 if (!WriteEnumEqualityOperatorSwitchCases(fd, parent, name, parent_name)) { in WriteEnumEqualityOperator()
118 dprintf(fd, " default: return false;\n"); in WriteEnumEqualityOperator()
119 dprintf(fd, " }\n}\n"); in WriteEnumEqualityOperator()
122 dprintf(fd, "inline bool operator==(const %s& parent, const %s& child) {\n", in WriteEnumEqualityOperator()
124 dprintf(fd, " return child == parent;\n}\n"); in WriteEnumEqualityOperator()
127 dprintf(fd, "inline bool operator!=(const %s& child, const %s& parent) {\n", in WriteEnumEqualityOperator()
129 dprintf(fd, " return !(child == parent);\n}\n"); in WriteEnumEqualityOperator()
132 dprintf(fd, "inline bool operator!=(const %s& parent, const %s& child) {\n", in WriteEnumEqualityOperator()
134 dprintf(fd, " return !(parent == child);\n}\n"); in WriteEnumEqualityOperator()
139 bool WriteEnumStreamOperatorSwitchCases(int fd, in WriteEnumStreamOperatorSwitchCases() argument
144 dprintf(fd, " case %s::%s: os << \"%s\"; break;\n", name.c_str(), in WriteEnumStreamOperatorSwitchCases()
149 type.enum_type.sub_members, [&fd, &name](CppType* parent) { in WriteEnumStreamOperatorSwitchCases()
150 return WriteEnumStreamOperatorSwitchCases(fd, *parent, name); in WriteEnumStreamOperatorSwitchCases()
154 bool WriteEnumOperators(int fd, const CppType& type) { in WriteEnumOperators() argument
158 fd, in WriteEnumOperators()
161 dprintf(fd, " switch (val) {\n"); in WriteEnumOperators()
162 if (!WriteEnumStreamOperatorSwitchCases(fd, type, name)) { in WriteEnumOperators()
165 dprintf(fd, in WriteEnumOperators()
171 [&fd, &type](CppType* parent) { in WriteEnumOperators()
172 return WriteEnumEqualityOperator(fd, type, *parent); in WriteEnumOperators()
178 int fd, in WriteDiscriminatedUnionEqualityOperator() argument
182 dprintf(fd, "\nbool %s::operator==(const %s& other) const {\n", name.c_str(), in WriteDiscriminatedUnionEqualityOperator()
184 dprintf(fd, " return this->which == other.which"); in WriteDiscriminatedUnionEqualityOperator()
186 dprintf(fd, " &&\n "); in WriteDiscriminatedUnionEqualityOperator()
189 dprintf(fd, in WriteDiscriminatedUnionEqualityOperator()
193 dprintf(fd, in WriteDiscriminatedUnionEqualityOperator()
197 dprintf(fd, in WriteDiscriminatedUnionEqualityOperator()
204 dprintf(fd, ";\n}\n"); in WriteDiscriminatedUnionEqualityOperator()
205 dprintf(fd, "bool %s::operator!=(const %s& other) const {\n", name.c_str(), in WriteDiscriminatedUnionEqualityOperator()
207 dprintf(fd, " return !(*this == other);\n}\n"); in WriteDiscriminatedUnionEqualityOperator()
212 bool WriteStructEqualityOperator(int fd, in WriteStructEqualityOperator() argument
216 dprintf(fd, "\nbool %s::operator==(const %s& other) const {\n", name.c_str(), in WriteStructEqualityOperator()
220 dprintf(fd, " return "); in WriteStructEqualityOperator()
222 dprintf(fd, " &&\n "); in WriteStructEqualityOperator()
225 dprintf(fd, "this->%s == other.%s", name.c_str(), name.c_str()); in WriteStructEqualityOperator()
227 dprintf(fd, ";\n}"); in WriteStructEqualityOperator()
228 dprintf(fd, "\nbool %s::operator!=(const %s& other) const {\n", name.c_str(), in WriteStructEqualityOperator()
230 dprintf(fd, " return !(*this == other);\n}\n"); in WriteStructEqualityOperator()
236 if (!WriteDiscriminatedUnionEqualityOperator(fd, *x.type, new_prefix)) { in WriteStructEqualityOperator()
245 // file descriptor |fd|.
247 int fd, in WriteStructMembers() argument
256 if (!WriteStructMembers(fd, x.type->name, in WriteStructMembers()
266 dprintf(fd, " bool has_%s;\n", ToUnderscoreId(x.name).c_str()); in WriteStructMembers()
272 dprintf(fd, " struct %s {\n", type_string.c_str()); in WriteStructMembers()
273 dprintf(fd, " %s();\n ~%s();\n\n", type_string.c_str(), in WriteStructMembers()
276 dprintf(fd, " bool operator==(const %s& other) const;\n", in WriteStructMembers()
278 dprintf(fd, " bool operator!=(const %s& other) const;\n\n", in WriteStructMembers()
280 dprintf(fd, " enum class Which {\n"); in WriteStructMembers()
284 dprintf(fd, " kUint64,\n"); in WriteStructMembers()
287 dprintf(fd, " kString,\n"); in WriteStructMembers()
290 dprintf(fd, " kBytes,\n"); in WriteStructMembers()
296 dprintf(fd, " kUninitialized,\n"); in WriteStructMembers()
297 dprintf(fd, " } which;\n"); in WriteStructMembers()
298 dprintf(fd, " union {\n"); in WriteStructMembers()
302 dprintf(fd, " uint64_t uint;\n"); in WriteStructMembers()
305 dprintf(fd, " std::string str;\n"); in WriteStructMembers()
308 dprintf(fd, " std::vector<uint8_t> bytes;\n"); in WriteStructMembers()
316 dprintf(fd, " bool placeholder_;\n"); in WriteStructMembers()
317 dprintf(fd, " };\n"); in WriteStructMembers()
318 dprintf(fd, " };\n"); in WriteStructMembers()
326 dprintf(fd, " %s %s;\n", type_string.c_str(), in WriteStructMembers()
332 void WriteEnumMembers(int fd, const CppType& type) { in WriteEnumMembers() argument
334 dprintf(fd, " k%s = %" PRIu64 "ull,\n", ToCamelCase(x.first).c_str(), in WriteEnumMembers()
338 WriteEnumMembers(fd, *x); in WriteEnumMembers()
342 // Writes a C++ type definition for |type| to the file descriptor |fd|. This
344 bool WriteTypeDefinition(int fd, const CppType& type) { in WriteTypeDefinition() argument
348 dprintf(fd, "\nenum class %s : uint64_t {\n", name.c_str()); in WriteTypeDefinition()
349 WriteEnumMembers(fd, type); in WriteTypeDefinition()
350 dprintf(fd, "};\n"); in WriteTypeDefinition()
351 if (!WriteEnumOperators(fd, type)) in WriteTypeDefinition()
355 dprintf(fd, "\nstruct %s {\n", name.c_str()); in WriteTypeDefinition()
357 dprintf(fd, " // type key: %" PRIu64 "\n", type.type_key.value()); in WriteTypeDefinition()
359 dprintf(fd, " bool operator==(const %s& other) const;\n", name.c_str()); in WriteTypeDefinition()
360 dprintf(fd, " bool operator!=(const %s& other) const;\n\n", in WriteTypeDefinition()
362 if (!WriteStructMembers(fd, type.name, type.struct_type.members)) in WriteTypeDefinition()
364 dprintf(fd, "};\n"); in WriteTypeDefinition()
373 // descriptor |fd| before writing |cpp_type| to the file descriptor |fd|. This
378 bool EnsureDependentTypeDefinitionsWritten(int fd, in EnsureDependentTypeDefinitionsWritten() argument
384 fd, *cpp_type.vector_type.element_type, defs); in EnsureDependentTypeDefinitionsWritten()
390 if (!EnsureDependentTypeDefinitionsWritten(fd, *x, defs)) in EnsureDependentTypeDefinitionsWritten()
393 WriteTypeDefinition(fd, cpp_type); in EnsureDependentTypeDefinitionsWritten()
401 if (!EnsureDependentTypeDefinitionsWritten(fd, *x.type, defs)) in EnsureDependentTypeDefinitionsWritten()
404 WriteTypeDefinition(fd, cpp_type); in EnsureDependentTypeDefinitionsWritten()
408 return EnsureDependentTypeDefinitionsWritten(fd, *cpp_type.optional_type, in EnsureDependentTypeDefinitionsWritten()
413 if (!EnsureDependentTypeDefinitionsWritten(fd, *x, defs)) in EnsureDependentTypeDefinitionsWritten()
418 fd, *cpp_type.tagged_type.real_type, defs)) { in EnsureDependentTypeDefinitionsWritten()
431 // |fd| will compile without modification. For example, the following would be
444 bool WriteTypeDefinitions(int fd, CppSymbolTable* table) { in WriteTypeDefinitions() argument
452 if (!EnsureDependentTypeDefinitionsWritten(fd, *real_type, &defs)) in WriteTypeDefinitions()
456 dprintf(fd, "\nenum class Type : uint64_t {\n"); in WriteTypeDefinitions()
457 dprintf(fd, " kUnknown = 0ull,\n"); in WriteTypeDefinitions()
459 dprintf(fd, " k%s = %" PRIu64 "ull,\n", ToCamelCase(type->name).c_str(), in WriteTypeDefinitions()
462 dprintf(fd, "};\n"); in WriteTypeDefinitions()
470 bool WriteTypeParserDefinition(int fd, CppSymbolTable* table) { in WriteTypeParserDefinition() argument
471 dprintf(fd, "\n//static\n"); in WriteTypeParserDefinition()
472 dprintf(fd, "Type TypeEnumValidator::SafeCast(uint64_t type_id) {\n"); in WriteTypeParserDefinition()
473 dprintf(fd, " switch (type_id) {\n"); in WriteTypeParserDefinition()
475 dprintf(fd, " case uint64_t{%" PRIu64 "}: return Type::k%s;\n", in WriteTypeParserDefinition()
478 dprintf(fd, " default: return Type::kUnknown;\n"); in WriteTypeParserDefinition()
479 dprintf(fd, " }\n}\n"); in WriteTypeParserDefinition()
484 // type in |table| to the file descriptor |fd|.
485 bool WriteFunctionDeclarations(int fd, CppSymbolTable* table) { in WriteFunctionDeclarations() argument
494 dprintf(fd, "\nbool Encode%s(\n", cpp_name.c_str()); in WriteFunctionDeclarations()
495 dprintf(fd, " const %s& data,\n", cpp_name.c_str()); in WriteFunctionDeclarations()
496 dprintf(fd, " CborEncodeBuffer* buffer);\n"); in WriteFunctionDeclarations()
497 dprintf(fd, "ssize_t Encode%s(\n", cpp_name.c_str()); in WriteFunctionDeclarations()
498 dprintf(fd, " const %s& data,\n", cpp_name.c_str()); in WriteFunctionDeclarations()
499 dprintf(fd, " uint8_t* buffer,\n size_t length);\n"); in WriteFunctionDeclarations()
500 dprintf(fd, "ssize_t Decode%s(\n", cpp_name.c_str()); in WriteFunctionDeclarations()
501 dprintf(fd, " const uint8_t* buffer,\n size_t length,\n"); in WriteFunctionDeclarations()
502 dprintf(fd, " %s* data);\n", cpp_name.c_str()); in WriteFunctionDeclarations()
507 bool WriteMapEncoder(int fd,
512 bool WriteArrayEncoder(int fd,
519 // descriptor |fd|. |name| is the C++ variable name that needs to be encoded.
523 bool WriteEncoder(int fd, in WriteEncoder() argument
531 if (!WriteMapEncoder(fd, name, cpp_type.struct_type.members, in WriteEncoder()
538 if (!WriteArrayEncoder(fd, name, cpp_type.struct_type.members, in WriteEncoder()
546 dprintf(fd, in WriteEncoder()
551 dprintf(fd, in WriteEncoder()
556 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()
569 dprintf(fd, " if (!IsValidUtf8(%s)) {\n", cid.c_str()); in WriteEncoder()
570 dprintf(fd, " return -CborErrorInvalidUtf8TextString;\n"); in WriteEncoder()
571 dprintf(fd, " }\n"); in WriteEncoder()
572 dprintf(fd, in WriteEncoder()
580 dprintf(fd, in WriteEncoder()
589 dprintf(fd, " {\n"); in WriteEncoder()
592 dprintf(fd, " if (%s.size() < %d) {\n", cid.c_str(), in WriteEncoder()
594 dprintf(fd, " return -CborErrorTooFewItems;\n"); in WriteEncoder()
595 dprintf(fd, " }\n"); in WriteEncoder()
599 dprintf(fd, " if (%s.size() > %d) {\n", cid.c_str(), in WriteEncoder()
601 dprintf(fd, " return -CborErrorTooManyItems;\n"); in WriteEncoder()
602 dprintf(fd, " }\n"); in WriteEncoder()
604 dprintf(fd, " CborEncoder encoder%d;\n", encoder_depth + 1); in WriteEncoder()
605 dprintf(fd, in WriteEncoder()
609 dprintf(fd, " for (const auto& x : %s) {\n", cid.c_str()); in WriteEncoder()
610 if (!WriteEncoder(fd, "x", *cpp_type.vector_type.element_type, in WriteEncoder()
614 dprintf(fd, " }\n"); in WriteEncoder()
615 dprintf(fd, in WriteEncoder()
619 dprintf(fd, " }\n"); in WriteEncoder()
623 dprintf(fd, in WriteEncoder()
633 dprintf(fd, " case %s::%s::Which::kUint64:\n", in WriteEncoder()
636 if (!WriteEncoder(fd, ToUnderscoreId(name + ".uint"), *union_member, in WriteEncoder()
640 dprintf(fd, " break;\n"); in WriteEncoder()
643 dprintf(fd, " case %s::%s::Which::kString:\n", in WriteEncoder()
646 if (!WriteEncoder(fd, ToUnderscoreId(name + ".str"), *union_member, in WriteEncoder()
650 dprintf(fd, " break;\n"); in WriteEncoder()
653 dprintf(fd, " case %s::%s::Which::kBytes:\n", in WriteEncoder()
656 if (!WriteEncoder(fd, ToUnderscoreId(name + ".bytes"), in WriteEncoder()
661 dprintf(fd, " break;\n"); in WriteEncoder()
667 dprintf(fd, " case %s::%s::Which::kUninitialized:\n", in WriteEncoder()
670 dprintf(fd, " return -CborUnknownError;\n"); in WriteEncoder()
674 dprintf(fd, in WriteEncoder()
678 if (!WriteEncoder(fd, name, *cpp_type.tagged_type.real_type, in WriteEncoder()
696 int fd, in CountMemberTypes() argument
705 dprintf(fd, " int num_optionals_present = %s.has_%s;\n", in CountMemberTypes()
708 dprintf(fd, " num_optionals_present += %s.has_%s;\n", name_id.c_str(), in CountMemberTypes()
720 // |members| to the file descriptor |fd|. |name| is the C++ variable name that
725 bool WriteMapEncoder(int fd, in WriteMapEncoder() argument
731 dprintf(fd, " CborEncoder encoder%d;\n", encoder_depth); in WriteMapEncoder()
732 MemberCountResult member_counts = CountMemberTypes(fd, name_id, members); in WriteMapEncoder()
734 dprintf(fd, in WriteMapEncoder()
740 dprintf(fd, in WriteMapEncoder()
754 dprintf(fd, " if (%s.has_%s) {\n", name_id.c_str(), in WriteMapEncoder()
759 dprintf(fd, in WriteMapEncoder()
764 dprintf(fd, in WriteMapEncoder()
770 dprintf(fd, " switch (%s.%s.which) {\n", fullname.c_str(), in WriteMapEncoder()
775 if (!WriteEncoder(fd, fullname, *member_type, nested_type_scope, in WriteMapEncoder()
781 dprintf(fd, " }\n"); in WriteMapEncoder()
785 dprintf(fd, in WriteMapEncoder()
793 // |members| to the file descriptor |fd|. |name| is the C++ variable name that
798 bool WriteArrayEncoder(int fd, in WriteArrayEncoder() argument
804 dprintf(fd, " CborEncoder encoder%d;\n", encoder_depth); in WriteArrayEncoder()
805 MemberCountResult member_counts = CountMemberTypes(fd, name_id, members); in WriteArrayEncoder()
807 dprintf(fd, in WriteArrayEncoder()
812 dprintf(fd, in WriteArrayEncoder()
825 dprintf(fd, " if (%s.has_%s) {\n", name_id.c_str(), in WriteArrayEncoder()
829 dprintf(fd, " switch (%s.%s.which) {\n", fullname.c_str(), in WriteArrayEncoder()
834 if (!WriteEncoder(fd, fullname, *member_type, nested_type_scope, in WriteArrayEncoder()
840 dprintf(fd, " }\n"); in WriteArrayEncoder()
844 dprintf(fd, in WriteArrayEncoder()
893 // |fd|.
894 bool WriteEncoders(int fd, CppSymbolTable* table) { in WriteEncoders() argument
908 dprintf(fd, "\n%s::%s::%s()\n", cpp_name.c_str(), dunion_cpp_name.c_str(), in WriteEncoders()
912 dprintf(fd, in WriteEncoders()
915 dprintf(fd, "\n%s::%s::~%s() {\n", cpp_name.c_str(), in WriteEncoders()
917 dprintf(fd, " switch (which) {\n"); in WriteEncoders()
921 dprintf(fd, " case Which::kUint64: break;\n"); in WriteEncoders()
924 dprintf(fd, " case Which::kString:\n"); in WriteEncoders()
925 dprintf(fd, " str.std::string::~basic_string();\n"); in WriteEncoders()
926 dprintf(fd, " break;\n"); in WriteEncoders()
929 dprintf(fd, " case Which::kBytes:\n"); in WriteEncoders()
930 dprintf(fd, " bytes.std::vector<uint8_t>::~vector();\n"); in WriteEncoders()
931 dprintf(fd, " break;\n"); in WriteEncoders()
937 dprintf(fd, " case Which::kUninitialized: break;\n"); in WriteEncoders()
938 dprintf(fd, " }\n"); in WriteEncoders()
939 dprintf(fd, "}\n"); in WriteEncoders()
976 dprintf(fd, vector_encode_function, cpp_name.c_str(), encoded_id.c_str()); in WriteEncoders()
977 dprintf(fd, "\nssize_t Encode%s(\n", cpp_name.c_str()); in WriteEncoders()
978 dprintf(fd, " const %s& data,\n", cpp_name.c_str()); in WriteEncoders()
979 dprintf(fd, " uint8_t* buffer,\n size_t length) {\n"); in WriteEncoders()
980 dprintf(fd, " CborEncoder encoder0;\n"); in WriteEncoders()
981 dprintf(fd, " cbor_encoder_init(&encoder0, buffer, length, 0);\n"); in WriteEncoders()
984 if (!WriteMapEncoder(fd, "data", real_type->struct_type.members, name)) in WriteEncoders()
987 if (!WriteArrayEncoder(fd, "data", real_type->struct_type.members, in WriteEncoders()
993 dprintf(fd, in WriteEncoders()
996 dprintf(fd, " if (extra_bytes_needed) {\n"); in WriteEncoders()
997 dprintf(fd, in WriteEncoders()
999 dprintf(fd, " } else {\n"); in WriteEncoders()
1000 dprintf(fd, in WriteEncoders()
1004 dprintf(fd, " }\n"); in WriteEncoders()
1005 dprintf(fd, "}\n"); in WriteEncoders()
1010 bool WriteMapDecoder(int fd,
1016 bool WriteArrayDecoder(int fd,
1024 // descriptor |fd|. |name| is the C++ variable name that needs to be encoded.
1030 bool WriteDecoder(int fd, in WriteDecoder() argument
1038 dprintf(fd, in WriteDecoder()
1041 dprintf(fd, " CBOR_RETURN_ON_ERROR(cbor_value_advance_fixed(&it%d));\n", in WriteDecoder()
1047 dprintf(fd, " size_t length%d = 0;", temp_length); in WriteDecoder()
1048 dprintf(fd, in WriteDecoder()
1052 dprintf(fd, " if (cbor_value_is_length_known(&it%d)) {\n", in WriteDecoder()
1054 dprintf(fd, in WriteDecoder()
1058 dprintf(fd, " } else {\n"); in WriteDecoder()
1060 fd, in WriteDecoder()
1064 dprintf(fd, " }\n"); in WriteDecoder()
1065 dprintf(fd, " %s%sresize(length%d);\n", name.c_str(), in WriteDecoder()
1067 dprintf(fd, in WriteDecoder()
1072 dprintf(fd, " CBOR_RETURN_ON_ERROR(cbor_value_advance(&it%d));\n", in WriteDecoder()
1078 dprintf(fd, " size_t length%d = 0;", temp_length); in WriteDecoder()
1079 dprintf(fd, " if (cbor_value_is_length_known(&it%d)) {\n", in WriteDecoder()
1081 dprintf(fd, in WriteDecoder()
1085 dprintf(fd, " } else {\n"); in WriteDecoder()
1087 fd, in WriteDecoder()
1091 dprintf(fd, " }\n"); in WriteDecoder()
1093 dprintf(fd, " %s%sresize(length%d);\n", name.c_str(), in WriteDecoder()
1096 dprintf(fd, " if (length%d < %d) {\n", temp_length, in WriteDecoder()
1098 dprintf(fd, " return -CborErrorTooFewItems;\n"); in WriteDecoder()
1099 dprintf(fd, " } else if (length%d > %d) {\n", temp_length, in WriteDecoder()
1101 dprintf(fd, " return -CborErrorTooManyItems;\n"); in WriteDecoder()
1102 dprintf(fd, " }\n"); in WriteDecoder()
1104 dprintf(fd, in WriteDecoder()
1109 dprintf(fd, " CBOR_RETURN_ON_ERROR(cbor_value_advance(&it%d));\n", in WriteDecoder()
1114 dprintf(fd, " if (cbor_value_get_type(&it%d) != CborArrayType) {\n", in WriteDecoder()
1116 dprintf(fd, " return -1;\n"); in WriteDecoder()
1117 dprintf(fd, " }\n"); in WriteDecoder()
1118 dprintf(fd, " {\n"); in WriteDecoder()
1119 dprintf(fd, " CborValue it%d;\n", decoder_depth + 1); in WriteDecoder()
1120 dprintf(fd, " size_t it%d_length = 0;\n", decoder_depth + 1); in WriteDecoder()
1121 dprintf(fd, in WriteDecoder()
1127 dprintf(fd, " if (it%d_length < %d) {\n", decoder_depth + 1, in WriteDecoder()
1129 dprintf(fd, " return -CborErrorTooFewItems;\n"); in WriteDecoder()
1130 dprintf(fd, " }\n"); in WriteDecoder()
1134 dprintf(fd, " if (it%d_length > %d) {\n", decoder_depth + 1, in WriteDecoder()
1136 dprintf(fd, " return -CborErrorTooManyItems;\n"); in WriteDecoder()
1137 dprintf(fd, " }\n"); in WriteDecoder()
1139 dprintf(fd, " %s%sresize(it%d_length);\n", name.c_str(), in WriteDecoder()
1142 fd, in WriteDecoder()
1145 dprintf(fd, " for (auto i = %s%sbegin(); i != %s%send(); ++i) {\n", in WriteDecoder()
1148 if (!WriteDecoder(fd, "(*i)", ".", *cpp_type.vector_type.element_type, in WriteDecoder()
1152 dprintf(fd, " }\n"); in WriteDecoder()
1154 fd, in WriteDecoder()
1157 dprintf(fd, " }\n"); in WriteDecoder()
1161 dprintf(fd, in WriteDecoder()
1165 dprintf(fd, " CBOR_RETURN_ON_ERROR(cbor_value_advance_fixed(&it%d));\n", in WriteDecoder()
1172 return WriteMapDecoder(fd, name, member_accessor, in WriteDecoder()
1177 return WriteArrayDecoder(fd, name, member_accessor, in WriteDecoder()
1184 dprintf(fd, " CborType type%d = cbor_value_get_type(&it%d);\n", in WriteDecoder()
1191 dprintf(fd, " else "); in WriteDecoder()
1194 dprintf(fd, in WriteDecoder()
1198 dprintf(fd, " %s.which = decltype(%s)::Which::kUint64;\n", in WriteDecoder()
1200 if (!WriteDecoder(fd, name + ".uint", ".", *x, decoder_depth, in WriteDecoder()
1206 dprintf(fd, " if (type%d == CborTextStringType) {\n", in WriteDecoder()
1208 dprintf(fd, " %s.which = decltype(%s)::Which::kString;\n", in WriteDecoder()
1211 dprintf(fd, " new (&%s) std::string();\n", str_name.c_str()); in WriteDecoder()
1212 if (!WriteDecoder(fd, str_name, ".", *x, decoder_depth, in WriteDecoder()
1218 dprintf(fd, " if (type%d == CborByteStringType) {\n", in WriteDecoder()
1221 dprintf(fd, " %s.which = decltype(%s)::Which::kBytes;\n", in WriteDecoder()
1223 dprintf(fd, " new (&%s) std::vector<uint8_t>();\n", in WriteDecoder()
1225 if (!WriteDecoder(fd, bytes_name, ".", *x, decoder_depth, in WriteDecoder()
1233 dprintf(fd, " }\n"); in WriteDecoder()
1235 dprintf(fd, " else { return -1; }\n"); in WriteDecoder()
1240 dprintf(fd, " uint64_t tag%d = 0;\n", temp_tag); in WriteDecoder()
1241 dprintf(fd, " cbor_value_get_tag(&it%d, &tag%d);\n", decoder_depth, in WriteDecoder()
1243 dprintf(fd, " if (tag%d != %" PRIu64 "ull) {\n", temp_tag, in WriteDecoder()
1245 dprintf(fd, " return -1;\n"); in WriteDecoder()
1246 dprintf(fd, " }\n"); in WriteDecoder()
1247 dprintf(fd, " CBOR_RETURN_ON_ERROR(cbor_value_advance_fixed(&it%d));\n", in WriteDecoder()
1249 if (!WriteDecoder(fd, name, member_accessor, in WriteDecoder()
1263 // the file descriptor |fd|. |name| is the C++ variable name that needs to be
1269 bool WriteMapDecoder(int fd, in WriteMapDecoder() argument
1275 dprintf(fd, " if (cbor_value_get_type(&it%d) != CborMapType) {\n", in WriteMapDecoder()
1277 dprintf(fd, " return -1;\n"); in WriteMapDecoder()
1278 dprintf(fd, " }\n"); in WriteMapDecoder()
1279 dprintf(fd, " CborValue it%d;\n", decoder_depth); in WriteMapDecoder()
1280 dprintf(fd, " size_t it%d_length = 0;\n", decoder_depth); in WriteMapDecoder()
1281 dprintf(fd, in WriteMapDecoder()
1291 dprintf(fd, " if (it%d_length != %d", decoder_depth, in WriteMapDecoder()
1294 dprintf(fd, " && it%d_length != %d", decoder_depth, in WriteMapDecoder()
1297 dprintf(fd, ") {\n"); in WriteMapDecoder()
1298 dprintf(fd, " return -1;\n"); in WriteMapDecoder()
1299 dprintf(fd, " }\n"); in WriteMapDecoder()
1300 dprintf(fd, in WriteMapDecoder()
1310 dprintf(fd, " if (it%d_length > %d) {\n", decoder_depth, member_pos); in WriteMapDecoder()
1313 dprintf(fd, in WriteMapDecoder()
1318 dprintf(fd, in WriteMapDecoder()
1322 dprintf(fd, " %s%shas_%s = true;\n", name.c_str(), in WriteMapDecoder()
1324 if (!WriteDecoder(fd, fullname, ".", *x.type->optional_type, in WriteMapDecoder()
1328 dprintf(fd, " } else {\n"); in WriteMapDecoder()
1329 dprintf(fd, " %s%shas_%s = false;\n", name.c_str(), in WriteMapDecoder()
1331 dprintf(fd, " }\n"); in WriteMapDecoder()
1334 dprintf(fd, in WriteMapDecoder()
1339 dprintf(fd, in WriteMapDecoder()
1343 if (!WriteDecoder(fd, fullname, ".", *x.type, decoder_depth, in WriteMapDecoder()
1350 dprintf(fd, in WriteMapDecoder()
1357 // the file descriptor |fd|. |name| is the C++ variable name that needs to be
1363 bool WriteArrayDecoder(int fd, in WriteArrayDecoder() argument
1369 dprintf(fd, " if (cbor_value_get_type(&it%d) != CborArrayType) {\n", in WriteArrayDecoder()
1371 dprintf(fd, " return -1;\n"); in WriteArrayDecoder()
1372 dprintf(fd, " }\n"); in WriteArrayDecoder()
1373 dprintf(fd, " CborValue it%d;\n", decoder_depth); in WriteArrayDecoder()
1374 dprintf(fd, " size_t it%d_length = 0;\n", decoder_depth); in WriteArrayDecoder()
1375 dprintf(fd, in WriteArrayDecoder()
1385 dprintf(fd, " if (it%d_length != %d", decoder_depth, in WriteArrayDecoder()
1388 dprintf(fd, " && it%d_length != %d", decoder_depth, in WriteArrayDecoder()
1391 dprintf(fd, ") {\n"); in WriteArrayDecoder()
1392 dprintf(fd, " return -1;\n"); in WriteArrayDecoder()
1393 dprintf(fd, " }\n"); in WriteArrayDecoder()
1394 dprintf(fd, in WriteArrayDecoder()
1408 dprintf(fd, " if (it%d_length > %d) {\n", decoder_depth, member_pos); in WriteArrayDecoder()
1409 dprintf(fd, " %s%shas_%s = true;\n", name.c_str(), in WriteArrayDecoder()
1411 if (!WriteDecoder(fd, fullname, ".", *x.type->optional_type, in WriteArrayDecoder()
1415 dprintf(fd, " } else {\n"); in WriteArrayDecoder()
1416 dprintf(fd, " %s%shas_%s = false;\n", name.c_str(), in WriteArrayDecoder()
1418 dprintf(fd, " }\n"); in WriteArrayDecoder()
1420 if (!WriteDecoder(fd, fullname, ".", *x.type, decoder_depth, in WriteArrayDecoder()
1427 dprintf(fd, in WriteArrayDecoder()
1434 bool WriteEqualityOperators(int fd, CppSymbolTable* table) { in WriteEqualityOperators() argument
1440 if (!WriteStructEqualityOperator(fd, *real_type)) { in WriteEqualityOperators()
1449 // descriptor |fd|.
1450 bool WriteDecoders(int fd, CppSymbolTable* table) { in WriteDecoders() argument
1451 if (!WriteTypeParserDefinition(fd, table)) { in WriteDecoders()
1463 dprintf(fd, "\nssize_t Decode%s(\n", cpp_name.c_str()); in WriteDecoders()
1464 dprintf(fd, " const uint8_t* buffer,\n size_t length,\n"); in WriteDecoders()
1465 dprintf(fd, " %s* data) {\n", cpp_name.c_str()); in WriteDecoders()
1466 dprintf(fd, " CborParser parser;\n"); in WriteDecoders()
1467 dprintf(fd, " CborValue it0;\n"); in WriteDecoders()
1469 fd, in WriteDecoders()
1473 if (!WriteMapDecoder(fd, "data", "->", real_type->struct_type.members, 1, in WriteDecoders()
1478 if (!WriteArrayDecoder(fd, "data", "->", real_type->struct_type.members, in WriteDecoders()
1484 fd, in WriteDecoders()
1487 dprintf(fd, " return result;\n"); in WriteDecoders()
1488 dprintf(fd, "}\n"); in WriteDecoders()
1507 bool WriteHeaderPrologue(int fd, const std::string& header_filename) { in WriteHeaderPrologue() argument
1530 dprintf(fd, prologue, header_guard.c_str(), header_guard.c_str()); in WriteHeaderPrologue()
1534 bool WriteHeaderEpilogue(int fd, const std::string& header_filename) { in WriteHeaderEpilogue() argument
1573 dprintf(fd, epilogue, header_guard.c_str()); in WriteHeaderEpilogue()
1577 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()