DeserializeFromReader deserializes a single object from a stream. It is strictly stateless: the buffer and all read state are always reset before each call, discarding any prefetched data and type metadata. For sequential multi-object reads on the same stream, use NewInputStream instead.
(r io.Reader, v any)
| 120 | // each call, discarding any prefetched data and type metadata. |
| 121 | // For sequential multi-object reads on the same stream, use NewInputStream instead. |
| 122 | func (f *Fory) DeserializeFromReader(r io.Reader, v any) error { |
| 123 | defer f.resetReadState() |
| 124 | // Always reset to enforce stateless semantics. |
| 125 | f.readCtx.buffer.ResetWithReader(r, 0) |
| 126 | |
| 127 | readHeader(f.readCtx) |
| 128 | if f.readCtx.HasError() { |
| 129 | return f.readCtx.TakeError() |
| 130 | } |
| 131 | |
| 132 | target := reflect.ValueOf(v).Elem() |
| 133 | f.readCtx.ReadValue(target, RefModeTracking, true) |
| 134 | if f.readCtx.HasError() { |
| 135 | return f.readCtx.TakeError() |
| 136 | } |
| 137 | |
| 138 | return nil |
| 139 | } |