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

Function write_configured_value

cpp/fory/serialization/struct_serializer.h:1105–1164  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1103
1104template <typename ValueType, typename StructT, size_t Index, int8_t NodeIndex>
1105void write_configured_value(const ValueType &value, WriteContext &ctx,
1106 RefMode ref_mode, bool write_type,
1107 bool has_generics) {
1108 constexpr FieldNodeKind kind =
1109 configured_node_kind<StructT, Index, NodeIndex>();
1110 constexpr FieldScalarKind scalar_kind =
1111 configured_node_scalar<StructT, Index, NodeIndex>();
1112 static_assert(configured_scalar_kind_matches<ValueType, scalar_kind>(),
1113 "fory::T typed scalar spec does not match the C++ field type");
1114 if constexpr (is_optional_v<ValueType>) {
1115 using Inner = typename ValueType::value_type;
1116 if (!value.has_value()) {
1117 if (ref_mode != RefMode::None) {
1118 ctx.write_int8(NULL_FLAG);
1119 }
1120 return;
1121 }
1122 write_not_null_ref_flag(ctx, ref_mode);
1123 constexpr int8_t child =
1124 kind == FieldNodeKind::Inner
1125 ? configured_node_child<StructT, Index, NodeIndex, 0>()
1126 : NodeIndex;
1127 write_configured_value<Inner, StructT, Index, child>(
1128 *value, ctx, RefMode::None, false, has_generics);
1129 } else if constexpr ((is_vector_v<ValueType> || is_list_v<ValueType> ||
1130 is_deque_v<ValueType> || is_set_like_v<ValueType>) &&
1131 kind == FieldNodeKind::Array) {
1132 Serializer<ValueType>::write(value, ctx, ref_mode, false, has_generics);
1133 } else if constexpr ((is_vector_v<ValueType> || is_list_v<ValueType> ||
1134 is_deque_v<ValueType> || is_set_like_v<ValueType>) &&
1135 (kind == FieldNodeKind::List ||
1136 kind == FieldNodeKind::Set)) {
1137 if constexpr (configured_vector_primitive_array_spec<ValueType, StructT,
1138 Index, NodeIndex>()) {
1139 Serializer<ValueType>::write(value, ctx, ref_mode, false, has_generics);
1140 } else {
1141 write_not_null_ref_flag(ctx, ref_mode);
1142 constexpr int8_t child =
1143 configured_node_child<StructT, Index, NodeIndex, 0>();
1144 write_configured_list_data<ValueType, StructT, Index, NodeIndex, child>(
1145 value, ctx);
1146 }
1147 } else if constexpr (is_map_like_v<ValueType> && kind == FieldNodeKind::Map) {
1148 write_not_null_ref_flag(ctx, ref_mode);
1149 constexpr int8_t key_child =
1150 configured_node_child<StructT, Index, NodeIndex, 0>();
1151 constexpr int8_t value_child =
1152 configured_node_child<StructT, Index, NodeIndex, 1>();
1153 write_configured_map_data<ValueType, StructT, Index, key_child,
1154 value_child>(value, ctx);
1155 } else if constexpr (kind == FieldNodeKind::Scalar ||
1156 configured_node_encoding<StructT, Index, NodeIndex>() !=
1157 Encoding::Default) {
1158 write_not_null_ref_flag(ctx, ref_mode);
1159 write_configured_scalar<ValueType, StructT, Index, NodeIndex>(value, ctx);
1160 } else {
1161 Serializer<ValueType>::write(value, ctx, ref_mode, write_type,
1162 has_generics);

Callers

nothing calls this directly

Calls 4

write_not_null_ref_flagFunction · 0.85
writeFunction · 0.50
has_valueMethod · 0.45
write_int8Method · 0.45

Tested by

no test coverage detected