Skip to content

Commit

Permalink
rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
AsterDY committed Apr 29, 2024
1 parent 63294ef commit 24742ca
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,6 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
<<<<<<< HEAD
=======
github.com/thrift-iterator/go v0.0.0-20190402154806-9b5a67519118/go.mod h1:60PRwE/TCI1UqLvn8v2pwAf6+yzTPLP/Ji5xaesWDqk=
>>>>>>> downgrade testify
github.com/tidwall/gjson v1.9.3/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
Expand Down
2 changes: 1 addition & 1 deletion thrift/generic/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func ExampleNewTypedNode() {
// make a struct{1:map<string, binary>} node
ret = NewTypedNode(thrift.STRUCT, 0, 0, PathNode{
Path: NewPathFieldId(1),
Node: NewNodeMap(map[interface{}]interface{}{"1": []byte{1}}),
Node: NewNodeMap(map[interface{}]interface{}{"1": []byte{1}}, &Options{}),
})
// print interface
opts.CastStringAsBinary = true
Expand Down
11 changes: 9 additions & 2 deletions thrift/generic/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ func NewNodeBinary(val []byte) Node {
// NewNodeList creates a LIST node.
// The element thrift type depends on vals' concrete type,
// thus there must be at least one val.
//
// NOTICE: all recursive sub slice will be regard as LIST too
func NewNodeList(vals []interface{}) Node {
p := thrift.NewBinaryProtocol(make([]byte, 0, len(vals)*DefaultNodeBufferSize))
if _, err := p.WriteAny(vals, false); err != nil {
Expand All @@ -160,6 +162,8 @@ func NewNodeList(vals []interface{}) Node {
// NewNodeSet creates a SET node.
// The element thrift type depends on vals' concrete type,
// thus there must be at least one val.
//
// NOTICE: all recursive sub slice will be regard as SET too
func NewNodeSet(vals []interface{}) Node {
p := thrift.NewBinaryProtocol(make([]byte, 0, len(vals)*DefaultNodeBufferSize))
if _, err := p.WriteAny(vals, true); err != nil {
Expand All @@ -171,9 +175,12 @@ func NewNodeSet(vals []interface{}) Node {
// NewNodeMap creates a MAP node.
// The thrift type of key and element depends on kvs' concrete type,
// thus there must be at least one kv.
func NewNodeMap(kvs map[interface{}]interface{}) Node {
//
// opts provides options when making the node.
// Notice: only `Option.SliceAsSet` is effective now
func NewNodeMap(kvs map[interface{}]interface{}, opts *Options) Node {
p := thrift.NewBinaryProtocol(make([]byte, 0, len(kvs)*DefaultNodeBufferSize*2))
if _, err := p.WriteAny(kvs, false); err != nil {
if _, err := p.WriteAny(kvs, opts.SliceAsSet); err != nil {
panic(err)
}
return NewNode(thrift.MAP, p.Buf)
Expand Down
2 changes: 1 addition & 1 deletion thrift/generic/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestNewTypedNode(t *testing.T) {
{"int map", args{thrift.MAP, thrift.BYTE, thrift.BYTE, []PathNode{{Path: NewPathIntKey(1), Node: NewNodeByte(1)}}}, Options{}, map[int]interface{}{int(1): int(1)}},
{"string map", args{thrift.MAP, thrift.BYTE, thrift.STRING, []PathNode{{Path: NewPathStrKey("1"), Node: NewNodeByte(1)}}}, Options{}, map[string]interface{}{"1": int(1)}},
{"any map + key list", args{thrift.MAP, thrift.BYTE, thrift.LIST, []PathNode{{Path: NewPathBinKey(NewNodeList([]interface{}{1, 2}).Raw()), Node: NewNodeByte(1)}}}, Options{}, map[interface{}]interface{}{&[]interface{}{int(1), int(2)}: int(1)}},
{"any map + key map", args{thrift.MAP, thrift.BYTE, thrift.MAP, []PathNode{{Path: NewPathBinKey(NewNodeMap(map[interface{}]interface{}{1: 2}).Raw()), Node: NewNodeByte(1)}}}, Options{}, map[interface{}]interface{}{&map[int]interface{}{1: 2}: int(1)}},
{"any map + key map", args{thrift.MAP, thrift.BYTE, thrift.MAP, []PathNode{{Path: NewPathBinKey(NewNodeMap(map[interface{}]interface{}{1: 2}, &Options{}).Raw()), Node: NewNodeByte(1)}}}, Options{}, map[interface{}]interface{}{&map[int]interface{}{1: 2}: int(1)}},
{"struct", args{thrift.STRUCT, 0, 0, []PathNode{{Path: NewPathFieldId(1), Node: NewNodeByte(1)}}}, Options{MapStructById: true}, map[thrift.FieldID]interface{}{thrift.FieldID(1): int(1)}},
{"struct + struct", args{thrift.STRUCT, 0, 0, []PathNode{{Path: NewPathFieldId(1), Node: NewNodeStruct(map[thrift.FieldID]interface{}{1: 1}, &Options{})}}}, Options{MapStructById: true}, map[thrift.FieldID]interface{}{thrift.FieldID(1): map[thrift.FieldID]interface{}{thrift.FieldID(1): int(1)}}},
}
Expand Down

0 comments on commit 24742ca

Please sign in to comment.