From 9888b6584618cf0d9e1cab3104c22c8a3517e260 Mon Sep 17 00:00:00 2001 From: Wit Riewrangboonya Date: Thu, 24 Jun 2021 19:08:57 -0500 Subject: [PATCH] Review comments --- gen/field.go | 4 ++-- gen/list.go | 2 +- gen/map.go | 2 +- gen/quick_test.go | 1 + gen/set.go | 2 +- gen/stream.go | 6 +++--- 6 files changed, 9 insertions(+), 8 deletions(-) diff --git a/gen/field.go b/gen/field.go index ff17fa1f..b2050181 100644 --- a/gen/field.go +++ b/gen/field.go @@ -309,8 +309,8 @@ func (f fieldGroupGenerator) ToWire(g Generator) error { // return err // } func (<$v> *<.Name>) ToWire() (<$wire>.Value, error) { - <$fields := newVar "fields" -> - <- $i := newVar "i" -> + <$fields := newVar "fields" -> + <- $i := newVar "i" -> <- $wVal := newVar "w" -> var ( diff --git a/gen/list.go b/gen/list.go index b5679258..fcd07cb6 100644 --- a/gen/list.go +++ b/gen/list.go @@ -147,7 +147,7 @@ func (l *listGenerator) Reader(g Generator, spec *compile.ListSpec) (string, err // } // // And returns its name. -func (l *listGenerator) Encode(g Generator, spec *compile.ListSpec) (string, error) { +func (l *listGenerator) Encoder(g Generator, spec *compile.ListSpec) (string, error) { name := encoderFuncName(g, spec) err := g.EnsureDeclared( ` diff --git a/gen/map.go b/gen/map.go index 14a68d0c..51d7a42f 100644 --- a/gen/map.go +++ b/gen/map.go @@ -186,7 +186,7 @@ func (m *mapGenerator) Reader(g Generator, spec *compile.MapSpec) (string, error // } // // And returns its name. -func (m *mapGenerator) Encode(g Generator, spec *compile.MapSpec) (string, error) { +func (m *mapGenerator) Encoder(g Generator, spec *compile.MapSpec) (string, error) { name := encoderFuncName(g, spec) err := g.EnsureDeclared( ` diff --git a/gen/quick_test.go b/gen/quick_test.go index 19efaa65..bfdd0b7a 100644 --- a/gen/quick_test.go +++ b/gen/quick_test.go @@ -764,6 +764,7 @@ func (q *quickSuite) testThriftRoundTripStreaming(t *testing.T, give, defaults t sw := binary.BorrowStreamWriter(&buf) require.NoError(t, sGive.Encode(sw), "failed to streaming encode %v", sGive) + binary.ReturnStreamWriter(sw) gType := reflect.TypeOf(sGive) if gType.Kind() == reflect.Ptr { diff --git a/gen/set.go b/gen/set.go index a06691ef..abce3c50 100644 --- a/gen/set.go +++ b/gen/set.go @@ -142,7 +142,7 @@ func (s *setGenerator) Reader(g Generator, spec *compile.SetSpec) (string, error return name, wrapGenerateError(spec.ThriftName(), err) } -func (s *setGenerator) Encode(g Generator, spec *compile.SetSpec) (string, error) { +func (s *setGenerator) Encoder(g Generator, spec *compile.SetSpec) (string, error) { name := encoderFuncName(g, spec) err := g.EnsureDeclared( ` diff --git a/gen/stream.go b/gen/stream.go index 0475708b..f369a551 100644 --- a/gen/stream.go +++ b/gen/stream.go @@ -58,13 +58,13 @@ func (sg *StreamGenerator) Encode(g Generator, spec compile.TypeSpec, varName st case *compile.BinarySpec: return fmt.Sprintf("%s.WriteBinary(%s)", sw, varName), nil case *compile.MapSpec: - encoder, err := sg.mapG.Encode(g, s) + encoder, err := sg.mapG.Encoder(g, s) return fmt.Sprintf("%s(%s, %s)", encoder, varName, sw), err case *compile.ListSpec: - encoder, err := sg.listG.Encode(g, s) + encoder, err := sg.listG.Encoder(g, s) return fmt.Sprintf("%s(%s, %s)", encoder, varName, sw), err case *compile.SetSpec: - encoder, err := sg.setG.Encode(g, s) + encoder, err := sg.setG.Encoder(g, s) return fmt.Sprintf("%s(%s, %s)", encoder, varName, sw), err default: return fmt.Sprintf("%s.Encode(%s)", varName, sw), nil