DeserializeFromStream reads the next object from the stream into the provided value. It preserves the stream buffer while clearing root-scoped read metadata between calls.
(is *InputStream, v any)
| 94 | // DeserializeFromStream reads the next object from the stream into the provided value. |
| 95 | // It preserves the stream buffer while clearing root-scoped read metadata between calls. |
| 96 | func (f *Fory) DeserializeFromStream(is *InputStream, v any) error { |
| 97 | origBuffer := f.readCtx.buffer |
| 98 | f.readCtx.buffer = is.buffer |
| 99 | defer func() { |
| 100 | f.readCtx.buffer = origBuffer |
| 101 | f.resetReadState() |
| 102 | }() |
| 103 | |
| 104 | readHeader(f.readCtx) |
| 105 | if f.readCtx.HasError() { |
| 106 | return f.readCtx.TakeError() |
| 107 | } |
| 108 | |
| 109 | target := reflect.ValueOf(v).Elem() |
| 110 | f.readCtx.ReadValue(target, RefModeTracking, true) |
| 111 | if f.readCtx.HasError() { |
| 112 | return f.readCtx.TakeError() |
| 113 | } |
| 114 | |
| 115 | return nil |
| 116 | } |
| 117 | |
| 118 | // DeserializeFromReader deserializes a single object from a stream. |
| 119 | // It is strictly stateless: the buffer and all read state are always reset before |