Skip to content

Commit

Permalink
feat:(conv) separate String2Int64 and Int642String (#32)
Browse files Browse the repository at this point in the history
* feat:(conv) seprate `String2Int64` and `Int642String`

* fix: should support string->DOUBLE when option `String2Int64` is enabled
  • Loading branch information
AsterDY committed Aug 28, 2023
1 parent b3c7613 commit d811de5
Show file tree
Hide file tree
Showing 11 changed files with 40,673 additions and 39,526 deletions.
7 changes: 5 additions & 2 deletions conv/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,12 @@ type Options struct {
// EnableThriftBase indicates if thrift/base should be recognized and mapping to/from context
EnableThriftBase bool

// Int64AsString indicates if string value cane be read as **Int8/Int16/Int32/Int64/Float64**,
// or in response a **Int64** value can be written as string
// String2Int64 indicates if string value cane be read as **Int8/Int16/Int32/Int64/Float64**,
String2Int64 bool

// Int642Stringin indicates if a int64 value a **Int64** value can be written as string
Int642String bool

// NoBase64Binary indicates if base64 string should be Encode/Decode as []byte
NoBase64Binary bool
// ByteAsUint8 indicates if byte should be conv as uint8 (default is int8), this only works for t2j now
Expand Down
3 changes: 2 additions & 1 deletion conv/j2t/conv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ func TestString2Int(t *testing.T) {
})

t.Run("option Int64AsString", func(t *testing.T) {
data := []byte(`{"Int32":"222","Int64":"333"}`)
data := []byte(`{"Int32":"222","Int64":"333", "Float64":"1.1"}`)
cv.SetOptions(conv.Options{
String2Int64: true,
})
Expand All @@ -908,6 +908,7 @@ func TestString2Int(t *testing.T) {
exp := example3.NewExampleInt2Float()
exp.Int64 = 333
exp.Int32 = 222
exp.Float64 = 1.1
act := example3.NewExampleInt2Float()
_, err = act.FastRead(out)
require.Nil(t, err)
Expand Down
2 changes: 1 addition & 1 deletion conv/t2j/conv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ func TestInt2String(t *testing.T) {
require.NoError(t, err)
require.Equal(t, (`{"Int32":1,"Float64":3.14,"Int64":2,"Subfix":0.92653,"中文":"hello"}`), string(out))

cv.opts.String2Int64 = true
cv.opts.Int642String = true
out, err = cv.Do(ctx, desc, in)
require.NoError(t, err)
require.Equal(t, (`{"Int32":1,"Float64":3.14,"Int64":"2","Subfix":0.92653,"中文":"hello"}`), string(out))
Expand Down
2 changes: 1 addition & 1 deletion conv/t2j/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func (self *BinaryConv) doRecurse(ctx context.Context, desc *thrift.TypeDescript
if e != nil {
return wrapError(meta.ErrWrite, "", e)
}
if self.opts.String2Int64 {
if self.opts.Int642String {
*out = append(*out, '"')
*out = json.EncodeInt64(*out, int64(v))
*out = append(*out, '"')
Expand Down
36,536 changes: 18,889 additions & 17,647 deletions internal/native/avx/native_amd64.s

Large diffs are not rendered by default.

66 changes: 33 additions & 33 deletions internal/native/avx/native_subr_amd64.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d811de5

Please sign in to comment.