diff --git a/thrift/generic/iter_test.go b/thrift/generic/iter_test.go index 45008b7e..43c49aad 100644 --- a/thrift/generic/iter_test.go +++ b/thrift/generic/iter_test.go @@ -24,7 +24,9 @@ import ( ) func TestForeach(t *testing.T) { - var iterOpts = &Options{} + var iterOpts = &Options{ + IterateStructByName: true, + } desc := getExampleDesc() data := getExampleData() @@ -98,16 +100,20 @@ func TestForeach(t *testing.T) { } require.NoError(t, root.Foreach(handler, iterOpts)) + handler2 := func(path Path, val Value) bool { + require.True(t, path.Type() == PathFieldName) + t.Logf("handler2: %v", path) + return true + } + vv := root.GetByPath(NewPathFieldName("InnerBase")) + require.Nil(t, vv.Check()) + require.NoError(t, vv.Foreach(handler2, iterOpts)) + cout := 0 handler3 := func(path Path, val Value) bool { cout += 1 return false } - vv := root.GetByPath(NewPathFieldName("InnerBase")) - require.Nil(t, vv.Check()) - require.NoError(t, vv.Foreach(handler3, iterOpts)) - require.Equal(t, 1, cout) - cout = 0 vv = root.GetByPath(PathExampleListInt32...) require.Nil(t, vv.Check()) diff --git a/thrift/generic/option.go b/thrift/generic/option.go index fc911f49..920b55d4 100644 --- a/thrift/generic/option.go +++ b/thrift/generic/option.go @@ -48,7 +48,7 @@ type Options struct { // WARNING: this will promote performance when thrift value to be skipped is large, but may decrease preformance when thrift value is small. UseNativeSkip bool - // MapStructById indicates to use field id as map key instead of when call Node.Interface() on STRUCT type. + // MapStructById indicates to use FieldId instead of int as map key instead of when call Node.Interface() on STRUCT type. MapStructById bool // CastStringAsBinary indicates to cast STRING type to []byte when call Node.Interface()/Map().