============================================================================ 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)
| 104 | // Serialize serializes a value with type T inferred, thread-safe. |
| 105 | // Takes pointer to avoid interface heap allocation and struct copy. |
| 106 | func 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. |