Compare commits

...

5 Commits

Author SHA1 Message Date
guoguangwu 4d1202359b
Merge 3a5cec6e36 into 3e9769d637 2024-11-22 06:54:38 +00:00
Masaaki Goshima 3e9769d637
Update go.yml 2024-11-11 12:13:39 +09:00
Andrey Grazhdankov 65c8b28ca1
Fix encode []*time.Time - check nil (#524) 2024-11-11 11:10:21 +09:00
guoguangwu 3a5cec6e36 fix : vm.go.tmpl 2023-05-29 17:31:09 +08:00
guoguangwu 89c61b5424 fix: code optimization
Signed-off-by: guoguangwu <guoguangwu@magic-shield.com>
2023-05-29 17:03:34 +08:00
8 changed files with 21 additions and 11 deletions

View File

@ -12,7 +12,7 @@ jobs:
- name: checkout
uses: actions/checkout@v3
- name: build
run: docker-compose run go-json
run: docker compose run go-json
test:
name: Test

View File

@ -426,6 +426,11 @@ func Test_Marshal(t *testing.T) {
assertErr(t, err)
assertEq(t, "[]interface{}", `[1,2.1,"hello"]`, string(bytes))
})
t.Run("[]*time.Time", func(t *testing.T) {
bytes, err := json.Marshal([]*time.Time{nil})
assertErr(t, err)
assertEq(t, "[]*time.Time", `[null]`, string(bytes))
})
})
t.Run("array", func(t *testing.T) {

View File

@ -437,7 +437,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
code = code.End.Next
}
} else {
mapCtx.Slice.Items[mapCtx.Idx].Value = b[mapCtx.Start:len(b)]
mapCtx.Slice.Items[mapCtx.Idx].Value = b[mapCtx.Start:]
if idx < mapCtx.Len {
mapCtx.Idx = int(idx)
mapCtx.Start = len(b)
@ -453,7 +453,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
if (ctx.Option.Flag & encoder.UnorderedMapOption) != 0 {
b = appendColon(ctx, b)
} else {
mapCtx.Slice.Items[mapCtx.Idx].Key = b[mapCtx.Start:len(b)]
mapCtx.Slice.Items[mapCtx.Idx].Key = b[mapCtx.Start:]
mapCtx.Start = len(b)
}
value := mapitervalue(&mapCtx.Iter)

View File

@ -406,6 +406,11 @@ func AppendMarshalJSON(ctx *RuntimeContext, code *Opcode, b []byte, v interface{
rv = newV
}
}
if rv.Kind() == reflect.Ptr && rv.IsNil() {
return AppendNull(ctx, b), nil
}
v = rv.Interface()
var bb []byte
if (code.Flags & MarshalerContextFlags) != 0 {

View File

@ -437,7 +437,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
code = code.End.Next
}
} else {
mapCtx.Slice.Items[mapCtx.Idx].Value = b[mapCtx.Start:len(b)]
mapCtx.Slice.Items[mapCtx.Idx].Value = b[mapCtx.Start:]
if idx < mapCtx.Len {
mapCtx.Idx = int(idx)
mapCtx.Start = len(b)
@ -453,7 +453,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
if (ctx.Option.Flag & encoder.UnorderedMapOption) != 0 {
b = appendColon(ctx, b)
} else {
mapCtx.Slice.Items[mapCtx.Idx].Key = b[mapCtx.Start:len(b)]
mapCtx.Slice.Items[mapCtx.Idx].Key = b[mapCtx.Start:]
mapCtx.Start = len(b)
}
value := mapitervalue(&mapCtx.Iter)

View File

@ -437,7 +437,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
code = code.End.Next
}
} else {
mapCtx.Slice.Items[mapCtx.Idx].Value = b[mapCtx.Start:len(b)]
mapCtx.Slice.Items[mapCtx.Idx].Value = b[mapCtx.Start:]
if idx < mapCtx.Len {
mapCtx.Idx = int(idx)
mapCtx.Start = len(b)
@ -453,7 +453,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
if (ctx.Option.Flag & encoder.UnorderedMapOption) != 0 {
b = appendColon(ctx, b)
} else {
mapCtx.Slice.Items[mapCtx.Idx].Key = b[mapCtx.Start:len(b)]
mapCtx.Slice.Items[mapCtx.Idx].Key = b[mapCtx.Start:]
mapCtx.Start = len(b)
}
value := mapitervalue(&mapCtx.Iter)

View File

@ -437,7 +437,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
code = code.End.Next
}
} else {
mapCtx.Slice.Items[mapCtx.Idx].Value = b[mapCtx.Start:len(b)]
mapCtx.Slice.Items[mapCtx.Idx].Value = b[mapCtx.Start:]
if idx < mapCtx.Len {
mapCtx.Idx = int(idx)
mapCtx.Start = len(b)
@ -453,7 +453,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
if (ctx.Option.Flag & encoder.UnorderedMapOption) != 0 {
b = appendColon(ctx, b)
} else {
mapCtx.Slice.Items[mapCtx.Idx].Key = b[mapCtx.Start:len(b)]
mapCtx.Slice.Items[mapCtx.Idx].Key = b[mapCtx.Start:]
mapCtx.Start = len(b)
}
value := mapitervalue(&mapCtx.Iter)

View File

@ -437,7 +437,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
code = code.End.Next
}
} else {
mapCtx.Slice.Items[mapCtx.Idx].Value = b[mapCtx.Start:len(b)]
mapCtx.Slice.Items[mapCtx.Idx].Value = b[mapCtx.Start:]
if idx < mapCtx.Len {
mapCtx.Idx = int(idx)
mapCtx.Start = len(b)
@ -453,7 +453,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
if (ctx.Option.Flag & encoder.UnorderedMapOption) != 0 {
b = appendColon(ctx, b)
} else {
mapCtx.Slice.Items[mapCtx.Idx].Key = b[mapCtx.Start:len(b)]
mapCtx.Slice.Items[mapCtx.Idx].Key = b[mapCtx.Start:]
mapCtx.Start = len(b)
}
value := mapitervalue(&mapCtx.Iter)