| 83 | } |
| 84 | |
| 85 | func (c *codecV2) Unmarshal(data mem.BufferSlice, v any) (err error) { |
| 86 | vv := messageV2Of(v) |
| 87 | if vv == nil { |
| 88 | return fmt.Errorf("failed to unmarshal, message is %T, want proto.Message", v) |
| 89 | } |
| 90 | |
| 91 | buf := data.MaterializeToBuffer(mem.DefaultBufferPool()) |
| 92 | defer buf.Free() |
| 93 | // TODO: Upgrade proto.Unmarshal to support mem.BufferSlice. Right now, it's not |
| 94 | // really possible without a major overhaul of the proto package, but the |
| 95 | // vtprotobuf library may be able to support this. |
| 96 | return proto.Unmarshal(buf.ReadOnlyData(), vv) |
| 97 | } |
| 98 | |
| 99 | func messageV2Of(v any) proto.Message { |
| 100 | switch v := v.(type) { |