Merge pull request #158 from goccy/feature/fix-marshal-json-indent-num

Fix indent number for OpMarshalJSON
This commit is contained in:
Masaaki Goshima 2021-03-20 20:26:32 +09:00 committed by GitHub
commit dcd9023ac5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 19 deletions

View File

@ -468,7 +468,7 @@ func AppendMarshalJSONIndent(ctx *RuntimeContext, code *Opcode, b []byte, v inte
if err := Indent( if err := Indent(
&indentBuf, &indentBuf,
compactBuf.Bytes(), compactBuf.Bytes(),
string(ctx.Prefix)+strings.Repeat(string(ctx.IndentStr), ctx.BaseIndent+indent+1), string(ctx.Prefix)+strings.Repeat(string(ctx.IndentStr), ctx.BaseIndent+indent),
string(ctx.IndentStr), string(ctx.IndentStr),
); err != nil { ); err != nil {
return nil, &errors.MarshalerError{Type: reflect.TypeOf(v), Err: err} return nil, &errors.MarshalerError{Type: reflect.TypeOf(v), Err: err}

View File

@ -2853,7 +2853,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt
if p == 0 && code.Nilcheck { if p == 0 && code.Nilcheck {
b = appendNull(b) b = appendNull(b)
} else { } else {
bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent, true) bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent+1, true)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -2899,7 +2899,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt
if p == 0 && code.Nilcheck { if p == 0 && code.Nilcheck {
b = appendNull(b) b = appendNull(b)
} else { } else {
bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent, true) bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent+1, true)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -2946,7 +2946,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt
b = appendIndent(ctx, b, code.Indent+1) b = appendIndent(ctx, b, code.Indent+1)
b = append(b, code.EscapedKey...) b = append(b, code.EscapedKey...)
b = append(b, ' ') b = append(b, ' ')
bb, err := appendMarshalJSON(ctx, code, b, iface, code.Indent, true) bb, err := appendMarshalJSON(ctx, code, b, iface, code.Indent+1, true)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -2988,7 +2988,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt
if p == 0 { if p == 0 {
b = appendNull(b) b = appendNull(b)
} else { } else {
bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent, true) bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent+1, true)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -3030,7 +3030,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt
b = appendIndent(ctx, b, code.Indent+1) b = appendIndent(ctx, b, code.Indent+1)
b = append(b, code.EscapedKey...) b = append(b, code.EscapedKey...)
b = append(b, ' ') b = append(b, ' ')
bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent, true) bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent+1, true)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -3877,7 +3877,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt
if p == 0 && code.Nilcheck { if p == 0 && code.Nilcheck {
b = appendNull(b) b = appendNull(b)
} else { } else {
bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent, true) bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent+1, true)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -3898,7 +3898,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt
b = appendIndent(ctx, b, code.Indent) b = appendIndent(ctx, b, code.Indent)
b = append(b, code.EscapedKey...) b = append(b, code.EscapedKey...)
b = append(b, ' ') b = append(b, ' ')
bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent, true) bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent+1, true)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -3913,7 +3913,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt
if p == 0 { if p == 0 {
b = appendNull(b) b = appendNull(b)
} else { } else {
bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent, true) bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent+1, true)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -3928,7 +3928,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt
b = appendIndent(ctx, b, code.Indent) b = appendIndent(ctx, b, code.Indent)
b = append(b, code.EscapedKey...) b = append(b, code.EscapedKey...)
b = append(b, ' ') b = append(b, ' ')
bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent, true) bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent+1, true)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -2859,7 +2859,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt
if p == 0 && code.Nilcheck { if p == 0 && code.Nilcheck {
b = appendNull(b) b = appendNull(b)
} else { } else {
bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent, false) bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent+1, false)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -2905,7 +2905,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt
if p == 0 && code.Nilcheck { if p == 0 && code.Nilcheck {
b = appendNull(b) b = appendNull(b)
} else { } else {
bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent, false) bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent+1, false)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -2952,7 +2952,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt
b = appendIndent(ctx, b, code.Indent+1) b = appendIndent(ctx, b, code.Indent+1)
b = append(b, code.Key...) b = append(b, code.Key...)
b = append(b, ' ') b = append(b, ' ')
bb, err := appendMarshalJSON(ctx, code, b, iface, code.Indent, false) bb, err := appendMarshalJSON(ctx, code, b, iface, code.Indent+1, false)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -2994,7 +2994,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt
if p == 0 { if p == 0 {
b = appendNull(b) b = appendNull(b)
} else { } else {
bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent, false) bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent+1, false)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -3036,7 +3036,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt
b = appendIndent(ctx, b, code.Indent+1) b = appendIndent(ctx, b, code.Indent+1)
b = append(b, code.Key...) b = append(b, code.Key...)
b = append(b, ' ') b = append(b, ' ')
bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent, false) bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent+1, false)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -3883,7 +3883,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt
if p == 0 && code.Nilcheck { if p == 0 && code.Nilcheck {
b = appendNull(b) b = appendNull(b)
} else { } else {
bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent, false) bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent+1, false)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -3904,7 +3904,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt
b = appendIndent(ctx, b, code.Indent) b = appendIndent(ctx, b, code.Indent)
b = append(b, code.Key...) b = append(b, code.Key...)
b = append(b, ' ') b = append(b, ' ')
bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent, false) bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent+1, false)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -3919,7 +3919,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt
if p == 0 { if p == 0 {
b = appendNull(b) b = appendNull(b)
} else { } else {
bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent, false) bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent+1, false)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -3934,7 +3934,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt
b = appendIndent(ctx, b, code.Indent) b = appendIndent(ctx, b, code.Indent)
b = append(b, code.Key...) b = append(b, code.Key...)
b = append(b, ' ') b = append(b, ' ')
bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent, false) bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent+1, false)
if err != nil { if err != nil {
return nil, err return nil, err
} }