DeserializeWithCallbackBuffers deserializes from buffer into the provided value (for streaming/cross-language use). The third parameter is optional external buffers for out-of-band data (can be nil).
(buffer *ByteBuffer, v any, buffers []*ByteBuffer)
| 733 | // DeserializeWithCallbackBuffers deserializes from buffer into the provided value (for streaming/cross-language use). |
| 734 | // The third parameter is optional external buffers for out-of-band data (can be nil). |
| 735 | func (f *Fory) DeserializeWithCallbackBuffers(buffer *ByteBuffer, v any, buffers []*ByteBuffer) error { |
| 736 | // Reset context and use the provided buffer |
| 737 | f.readCtx.buffer = buffer |
| 738 | defer func() { |
| 739 | f.readCtx.Reset() |
| 740 | if f.metaContext != nil { |
| 741 | f.metaContext.Reset() |
| 742 | } |
| 743 | f.readCtx.buffer = nil |
| 744 | f.readCtx.outOfBandBuffers = nil |
| 745 | }() |
| 746 | // Set up out-of-band buffers if provided |
| 747 | if buffers != nil { |
| 748 | f.readCtx.outOfBandBuffers = buffers |
| 749 | } |
| 750 | |
| 751 | // ReadData and validate header |
| 752 | readHeader(f.readCtx) |
| 753 | if f.readCtx.HasError() { |
| 754 | return f.readCtx.TakeError() |
| 755 | } |
| 756 | |
| 757 | // v must be a pointer so we can deserialize into it |
| 758 | if v == nil { |
| 759 | return fmt.Errorf("v cannot be nil") |
| 760 | } |
| 761 | rv := reflect.ValueOf(v) |
| 762 | if rv.Kind() != reflect.Ptr { |
| 763 | return fmt.Errorf("v must be a pointer, got %v", rv.Kind()) |
| 764 | } |
| 765 | if rv.IsNil() { |
| 766 | return fmt.Errorf("v must be a non-nil pointer") |
| 767 | } |
| 768 | |
| 769 | // Deserialize the value - TypeMeta is read inline using streaming protocol |
| 770 | f.readCtx.ReadValue(rv.Elem(), RefModeTracking, true) |
| 771 | if f.readCtx.HasError() { |
| 772 | return f.readCtx.TakeError() |
| 773 | } |
| 774 | |
| 775 | return nil |
| 776 | } |
| 777 | |
| 778 | // serializeReflectValue serializes a reflect.Value directly, avoiding boxing overhead. |
| 779 | // This is used by Serialize[T] fallback path to avoid struct copy. |