Skip to content

Commit f3a2210

Browse files
author
Achille
authored
thrift: allow reusing struct fields (#117)
* thrift: allow reusing struct fields * update documentation
1 parent 04dfa1a commit f3a2210

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

thrift/decode.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ import (
1616
// The function errors if the data in b does not match the type of v.
1717
//
1818
// The function panics if v cannot be converted to a thrift representation.
19+
//
20+
// As an optimization, the value passed in v may be reused across multiple calls
21+
// to Unmarshal, allowing the function to reuse objects referenced by pointer
22+
// fields of struct values. When reusing objects, the application is responsible
23+
// for resetting the state of v before calling Unmarshal again.
1924
func Unmarshal(p Protocol, b []byte, v interface{}) error {
2025
br := bytes.NewReader(b)
2126
pr := p.NewReader(br)
@@ -347,7 +352,6 @@ type structDecoder struct {
347352
}
348353

349354
func (dec *structDecoder) decode(r Reader, v reflect.Value, flags flags) error {
350-
v.Set(dec.zero)
351355
flags = flags.only(decodeFlags)
352356
coalesceBoolFields := flags.have(coalesceBoolFields)
353357

0 commit comments

Comments
 (0)