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

Method serializeReflectValue

go/fory/fory.go:783–796  ·  view source on GitHub ↗

serializeReflectValue serializes a reflect.Value directly, avoiding boxing overhead. This is used by Serialize[T] fallback path to avoid struct copy. For structs, the value must be a pointer to struct, not struct value. go:noinline

(value reflect.Value)

Source from the content-addressed store, hash-verified

781//
782//go:noinline
783func (f *Fory) serializeReflectValue(value reflect.Value) ([]byte, error) {
784 // Check that structs are passed as pointers
785 if value.Kind() == reflect.Struct {
786 return nil, fmt.Errorf("cannot serialize struct %s directly, use pointer to struct (*%s) instead", value.Type(), value.Type())
787 }
788
789 // Serialize the value - TypeMeta is written inline using streaming protocol
790 f.writeCtx.WriteValue(value, RefModeTracking, true)
791 if f.writeCtx.HasError() {
792 return nil, f.writeCtx.TakeError()
793 }
794
795 return f.writeCtx.buffer.GetByteSlice(0, f.writeCtx.buffer.writerIndex), nil
796}
797
798// ============================================================================
799// Protocol Header

Callers 1

SerializeFunction · 0.80

Calls 6

KindMethod · 0.80
WriteValueMethod · 0.80
GetByteSliceMethod · 0.80
TypeMethod · 0.45
HasErrorMethod · 0.45
TakeErrorMethod · 0.45

Tested by

no test coverage detected