MCPcopy Create free account
hub / github.com/apache/fory / read_configured_map_data

Function read_configured_map_data

cpp/fory/serialization/struct_serializer.h:1048–1102  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1046template <typename MapType, typename StructT, size_t Index, int8_t KeyNode,
1047 int8_t ValueNode>
1048MapType read_configured_map_data(ReadContext &ctx) {
1049 using Key = key_type_t<MapType>;
1050 using Value = mapped_type_t<MapType>;
1051 uint32_t length = ctx.read_var_uint32(ctx.error());
1052 MapType result;
1053 if (length == 0) {
1054 return result;
1055 }
1056 if (FORY_PREDICT_FALSE(!reserve_map(result, ctx, length))) {
1057 return result;
1058 }
1059 uint32_t read_count = 0;
1060 while (read_count < length && !ctx.has_error()) {
1061 uint8_t header = ctx.read_uint8(ctx.error());
1062 uint8_t chunk_size = ctx.read_uint8(ctx.error());
1063 if (FORY_PREDICT_FALSE(ctx.has_error())) {
1064 return result;
1065 }
1066 const bool key_decl = (header & DECL_KEY_TYPE) != 0;
1067 const bool value_decl = (header & DECL_VALUE_TYPE) != 0;
1068 if (!key_decl) {
1069 (void)ctx.read_any_type_info(ctx.error());
1070 }
1071 if (!value_decl) {
1072 (void)ctx.read_any_type_info(ctx.error());
1073 }
1074 for (uint8_t i = 0; i < chunk_size && read_count < length; ++i) {
1075 Key key = [&]() {
1076 if constexpr (KeyNode >= 0) {
1077 return read_configured_value<Key, StructT, Index, KeyNode>(
1078 ctx, RefMode::None, false);
1079 } else {
1080 return Serializer<Key>::read_data(ctx);
1081 }
1082 }();
1083 if (FORY_PREDICT_FALSE(ctx.has_error())) {
1084 return result;
1085 }
1086 Value value = [&]() {
1087 if constexpr (ValueNode >= 0) {
1088 return read_configured_value<Value, StructT, Index, ValueNode>(
1089 ctx, RefMode::None, false);
1090 } else {
1091 return Serializer<Value>::read_data(ctx);
1092 }
1093 }();
1094 if (FORY_PREDICT_FALSE(ctx.has_error())) {
1095 return result;
1096 }
1097 result.emplace(std::move(key), std::move(value));
1098 ++read_count;
1099 }
1100 }
1101 return result;
1102}
1103
1104template <typename ValueType, typename StructT, size_t Index, int8_t NodeIndex>
1105void write_configured_value(const ValueType &value, WriteContext &ctx,

Callers

nothing calls this directly

Calls 7

reserve_mapFunction · 0.85
read_dataFunction · 0.85
errorMethod · 0.65
read_var_uint32Method · 0.45
has_errorMethod · 0.45
read_uint8Method · 0.45
read_any_type_infoMethod · 0.45

Tested by

no test coverage detected