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

Function Serialize

go/fory/threadsafe/fory.go:106–118  ·  view source on GitHub ↗

============================================================================ Generic package-level functions ============================================================================ Serialize serializes a value with type T inferred, thread-safe. Takes pointer to avoid interface heap allocation a

(f *Fory, value *T)

Source from the content-addressed store, hash-verified

104// Serialize serializes a value with type T inferred, thread-safe.
105// Takes pointer to avoid interface heap allocation and struct copy.
106func Serialize[T any](f *Fory, value *T) ([]byte, error) {
107 inner := f.acquire()
108 data, err := fory.Serialize(inner, value)
109 if err != nil {
110 f.release(inner)
111 return nil, err
112 }
113 // Copy the data before releasing since the buffer will be reused
114 result := make([]byte, len(data))
115 copy(result, data)
116 f.release(inner)
117 return result, nil
118}
119
120// Deserialize deserializes data directly into the provided target, thread-safe.
121// Takes pointer to avoid interface heap allocation and enable direct writes.

Callers 3

TestForyFunction · 0.70
TestDeserializeFunction · 0.70
MarshalFunction · 0.70

Calls 3

acquireMethod · 0.45
SerializeMethod · 0.45
releaseMethod · 0.45

Tested by 2

TestForyFunction · 0.56
TestDeserializeFunction · 0.56