Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
AsterDY committed Sep 23, 2024
1 parent 3c00b4d commit 252a53d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
16 changes: 16 additions & 0 deletions conv/j2t/conv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1552,3 +1552,19 @@ func TestSimpleArgs(t *testing.T) {
require.Equal(t, exp, out)
})
}

func TestEmptyStruct(t *testing.T) {
desc, err := thrift.NewDescritorFromContent(context.Background(), "a/b/main.thrift", `
struct Req {}
service Svc {
void Method(1: Req req)
}
`, nil, true)
require.NoError(t, err)
reqDesc := desc.Functions()["Method"].Request().Struct().FieldById(1).Type()
cv := NewBinaryConv(conv.Options{})
out, err := cv.Do(context.Background(), reqDesc, []byte(`{"UNKNOWN":1}`))
require.NoError(t, err)
fmt.Printf("%+v", out)
}
8 changes: 4 additions & 4 deletions conv/j2t/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ func isJsonString(val string) bool {
if len(val) < 2 {
return false
}
c := json.SkipBlank(val, 0)

c := json.SkipBlank(val, 0)
if c < 0 {
return false
}
Expand Down Expand Up @@ -171,7 +171,7 @@ func (self *BinaryConv) writeStringValue(ctx context.Context, buf *[]byte, f *th
if err := self.doNative(ctx, rt.Str2Mem(val), f.Type(), &p.Buf, req, false); err != nil {
return newError(meta.ErrConvert, fmt.Sprintf("failed to convert value of field '%s'", f.Name()), err)
}
// try text encoding, see thrift.EncodeText
// try text encoding, see thrift.EncodeText
} else {
return newError(meta.ErrConvert, fmt.Sprintf("unsupported http-mapping encoding %v for '%s'", enc, f.Name()), nil)
}
Expand All @@ -181,7 +181,7 @@ BACK:
return nil
}

func (self *BinaryConv)writeRequestBaseToThrift(ctx context.Context, buf *[]byte, field *thrift.FieldDescriptor) error {
func (self *BinaryConv) writeRequestBaseToThrift(ctx context.Context, buf *[]byte, field *thrift.FieldDescriptor) error {
var b *base.Base
if bobj := ctx.Value(conv.CtxKeyThriftReqBase); bobj != nil {
if v, ok := bobj.(*base.Base); ok && v != nil {
Expand Down

0 comments on commit 252a53d

Please sign in to comment.