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

Function write_union_configured_value

cpp/fory/serialization/union_serializer.h:601–659  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

599
600template <typename ValueType, typename SpecProvider, int8_t NodeIndex>
601void write_union_configured_value(const ValueType &value, WriteContext &ctx,
602 RefMode ref_mode, bool write_type,
603 bool has_generics) {
604 constexpr FieldNodeKind kind = union_node_kind<SpecProvider, NodeIndex>();
605 constexpr FieldScalarKind scalar_kind =
606 union_node_scalar<SpecProvider, NodeIndex>();
607 static_assert(configured_scalar_kind_matches<ValueType, scalar_kind>(),
608 "fory::T typed scalar spec does not match the C++ union case "
609 "type");
610 if constexpr (is_optional_v<ValueType>) {
611 using Inner = typename ValueType::value_type;
612 if (!value.has_value()) {
613 if (ref_mode != RefMode::None) {
614 ctx.write_int8(NULL_FLAG);
615 }
616 return;
617 }
618 write_not_null_ref_flag(ctx, ref_mode);
619 constexpr int8_t child =
620 kind == FieldNodeKind::Inner
621 ? union_node_child<SpecProvider, NodeIndex, 0>()
622 : NodeIndex;
623 write_union_configured_value<Inner, SpecProvider, child>(
624 *value, ctx, RefMode::None, false, has_generics);
625 } else if constexpr ((is_vector_v<ValueType> || is_list_v<ValueType> ||
626 is_deque_v<ValueType> || is_set_like_v<ValueType>) &&
627 kind == FieldNodeKind::Array) {
628 Serializer<ValueType>::write(value, ctx, ref_mode, false, has_generics);
629 } else if constexpr ((is_vector_v<ValueType> || is_list_v<ValueType> ||
630 is_deque_v<ValueType> || is_set_like_v<ValueType>) &&
631 (kind == FieldNodeKind::List ||
632 kind == FieldNodeKind::Set)) {
633 if constexpr (union_vector_primitive_array_spec<ValueType, SpecProvider,
634 NodeIndex>()) {
635 Serializer<ValueType>::write(value, ctx, ref_mode, false, has_generics);
636 } else {
637 write_not_null_ref_flag(ctx, ref_mode);
638 constexpr int8_t child = union_node_child<SpecProvider, NodeIndex, 0>();
639 write_union_configured_list_data<ValueType, SpecProvider, child>(value,
640 ctx);
641 }
642 } else if constexpr (is_map_like_v<ValueType> && kind == FieldNodeKind::Map) {
643 write_not_null_ref_flag(ctx, ref_mode);
644 constexpr int8_t key_child = union_node_child<SpecProvider, NodeIndex, 0>();
645 constexpr int8_t value_child =
646 union_node_child<SpecProvider, NodeIndex, 1>();
647 write_union_configured_map_data<ValueType, SpecProvider, key_child,
648 value_child>(value, ctx);
649 } else if constexpr (kind == FieldNodeKind::Scalar ||
650 union_node_encoding<SpecProvider, NodeIndex>() !=
651 Encoding::Default) {
652 write_not_null_ref_flag(ctx, ref_mode);
653 write_union_configured_scalar<ValueType, SpecProvider, NodeIndex>(value,
654 ctx);
655 } else {
656 Serializer<ValueType>::write(value, ctx, ref_mode, write_type,
657 has_generics);
658 }

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