package vm
import (
"reflect"
"unsafe"
"github.com/goccy/go-json/internal/encoder"
"github.com/goccy/go-json/internal/jsonstring"
)
func Run (ctx *encoder .RuntimeContext , b []byte , codeSet *encoder .OpcodeSet ) ([]byte , error ) {
ctxptr := ctx .Ptr ()
code := codeSet .KeyCodes [ctx .Option .Flag &encoder .KeyEscapeOptions ]
for {
switch code .Op {
default :
return b , errUnimplementedOp (code .Op )
case encoder .OpInterfacePtr :
p := ptrToNPtr (load (ctxptr , code .Idx ), code .PtrNum )
if p == nil {
b = appendNullComma (ctx , b )
code = code .Next
break
}
store (ctxptr , code .Idx , p )
fallthrough
case encoder .OpInterface :
p := load (ctxptr , code .Idx )
if p == nil || (*(*unsafe .Pointer )(p ) == nil && code .Flags &encoder .StaticTypeFlags == 0 ) {
b = appendNullComma (ctx , b )
code = code .Next
break
}
first , base , scalar , err := ctx .EnterInterface (code , p )
if err != nil {
return b , err
}
if first == nil {
b = appendNullComma (ctx , b )
code = code .Next
break
}
if scalar {
bb , err := appendScalar (ctx , b , first , base )
if err != nil {
return b , err
}
b = bb
code = code .Next
break
}
code = first
ctxptr = base
case encoder .OpInterfaceEnd :
code , ctxptr = ctx .LeaveFrame (code )
case encoder .OpStructFieldInterface :
p := unsafe .Add (load (ctxptr , code .Idx ), code .Offset )
b = appendStructKey (ctx , code , b )
if *(*unsafe .Pointer )(p ) == nil && code .Flags &encoder .StaticTypeFlags == 0 {
b = appendNullComma (ctx , b )
code = code .Next
break
}
first , base , scalar , err := ctx .EnterInterface (code , p )
if err != nil {
return b , err
}
if first == nil {
b = appendNullComma (ctx , b )
code = code .Next
break
}
if scalar {
bb , err := appendScalar (ctx , b , first , base )
if err != nil {
return b , err
}
b = bb
code = code .Next
break
}
code = first
ctxptr = base
case encoder .OpStructFieldOmitEmptyInterface :
p := unsafe .Add (load (ctxptr , code .Idx ), code .Offset )
if *(*unsafe .Pointer )(p ) == nil {
code = code .NextField
break
}
b = appendStructKey (ctx , code , b )
first , base , scalar , err := ctx .EnterInterface (code , p )
if err != nil {
return b , err
}
if first == nil {
b = appendNullComma (ctx , b )
code = code .Next
break
}
if scalar {
bb , err := appendScalar (ctx , b , first , base )
if err != nil {
return b , err
}
b = bb
code = code .Next
break
}
code = first
ctxptr = base
case encoder .OpMapPtr :
p := ptrToNPtr (load (ctxptr , code .Idx ), code .PtrNum )
if p == nil {
if encoder .NilMapIsEmpty (ctx ) {
b = appendEmptyObject (ctx , b )
} else {
b = appendNullComma (ctx , b )
}
code = code .End .Next
break
}
store (ctxptr , code .Idx , p )
fallthrough
case encoder .OpMap :
p := load (ctxptr , code .Idx )
if p == nil {
if encoder .NilMapIsEmpty (ctx ) {
b = appendEmptyObject (ctx , b )
} else {
b = appendNullComma (ctx , b )
}
code = code .End .Next
break
}
mapCtx := encoder .NewMapContext (ctx )
if ctx .RecursiveLevel > encoder .StartDetectingMapCyclesAfter && code .Map .Cyclic {
if err := ctx .RecordMap (code , p , mapCtx ); err != nil {
return b , err
}
}
if code .Flags &encoder .MapStringKeyFlags != 0 && (code .Map .ScalarValue || code .Map .InterfaceValue ) && ctx .Option .Flag &encoder .UnorderedMapOption != 0 {
if encoder .MapLen (p ) == 0 {
encoder .ReleaseMapContext (ctx , mapCtx )
b = appendEmptyObject (ctx , b )
code = code .End .Next
break
}
bb , err := appendMapAsRead (ctx , code , appendStructHead (ctx , b ), p , mapCtx )
if err != nil {
return bb , err
}
b = bb
} else if code .Map .Collect (p , mapCtx ) == 0 {
encoder .ReleaseMapContext (ctx , mapCtx )
b = appendEmptyObject (ctx , b )
code = code .End .Next
break
} else {
b = appendStructHead (ctx , b )
if (ctx .Option .Flag & encoder .UnorderedMapOption ) == 0 {
if code .Flags &encoder .MapStringKeyFlags != 0 {
mapCtx .SortKeys ()
mapCtx .Sorted = true
mapCtx .DirectEntries = code .Map .ScalarValue || code .Map .InterfaceValue
} else {
mapCtx .SortByEncodedKeys ()
mapCtx .First = len (b )
}
}
}
store (ctxptr , code .Idx , unsafe .Pointer (mapCtx ))
mapCtx .Idx = -1
fallthrough
case encoder .OpMapKey :
mapCtx := (*encoder .MapContext )(load (ctxptr , code .Idx ))
byEncodedKeys := mapCtx .Slice .Items != nil
idx := mapCtx .Idx + 1
if byEncodedKeys && !mapCtx .Sorted {
if idx < mapCtx .Len {
mapCtx .Idx = idx
store (ctxptr , code .Next .Idx , mapCtx .KeyAt (idx ))
code = code .Next
break
}
b = mapCtx .SortEncodedKeys (ctx , b , mapKeyFooterLen (ctx , code .Next ))
idx = 0
}
if mapCtx .DirectEntries && idx < mapCtx .Len {
bb , next , err := appendSortedMapEntries (ctx , code , b , mapCtx , idx )
if err != nil {
return bb , err
}
b , idx = bb , next
}
if idx == mapCtx .Len {
b = appendObjectEnd (ctx , code , b )
encoder .ReleaseMapContext (ctx , mapCtx )
code = code .End .Next
break
}
mapCtx .Idx = idx
if byEncodedKeys {
item := &mapCtx .Slice .Items [idx ]
if idx > 0 && code .End .Op == encoder .OpMapEndMayRepeatNames && encoder .SameMapName (ctx , item .Key , mapCtx .Slice .Items [idx -1 ].Key ) {
err := encoder .DuplicateMapNameError (item .Key , b )
encoder .ReleaseMapContext (ctx , mapCtx )
return b , err
}
b = appendSortedMapKey (ctx , code , b , item .Key )
code = code .NextField .Next
store (ctxptr , code .Idx , mapCtx .ValueAt (item .Entry ))
break
}
b = appendMapKeyIndent (ctx , code , b )
if code .Flags &encoder .MapStringKeyFlags == 0 {
store (ctxptr , code .Next .Idx , mapCtx .KeyAt (idx ))
code = code .Next
break
}
if mapCtx .Sorted {
idx = int (mapCtx .Order [idx ])
}
b , _ = jsonstring .AppendQuoted (encoder .StringEscaper (ctx ), b , mapCtx .Keys [idx ])
b = appendComma (ctx , b )
b = appendColon (ctx , b )
store (ctxptr , code .Next .Idx , mapCtx .ValueAt (idx ))
code = code .Next
case encoder .OpMapValue :
mapCtx := (*encoder .MapContext )(load (ctxptr , code .Idx ))
if mapCtx .Slice .Items != nil {
mapCtx .Slice .Items [mapCtx .Idx ] = encoder .MapItem {Key : b [mapCtx .First :], Entry : mapCtx .Idx }
code = code .NextField
if idx := mapCtx .Idx + 1 ; idx < mapCtx .Len {
mapCtx .Idx = idx
code = code .Next
store (ctxptr , code .Idx , mapCtx .KeyAt (idx ))
}
break
}
b = appendColon (ctx , b )
store (ctxptr , code .Next .Idx , mapCtx .ValueAt (mapCtx .Idx ))
code = code .Next
case encoder .OpIntPtr :
p := ptrToNPtr (load (ctxptr , code .Idx ), code .PtrNum )
if p == nil {
b = appendNullComma (ctx , b )
code = code .Next
break
}
store (ctxptr , code .Idx , p )
fallthrough
case encoder .OpInt :
b = encoder .AppendInt (ctx , b , load (ctxptr , code .Idx ), code )
b = appendComma (ctx , b )
code = code .Next
case encoder .OpUintPtr :
p := ptrToNPtr (load (ctxptr , code .Idx ), code .PtrNum )
if p == nil {
b = appendNullComma (ctx , b )
code = code .Next
break
}
store (ctxptr , code .Idx , p )
fallthrough
case encoder .OpUint :
b = encoder .AppendUint (ctx , b , load (ctxptr , code .Idx ), code )
b = appendComma (ctx , b )
code = code .Next
case encoder .OpIntPtrString :
p := ptrToNPtr (load (ctxptr , code .Idx ), code .PtrNum )
if p == nil {
if code .Flags &encoder .MapKeyFlags != 0 {
return b , encoder .ErrNilMapKey (code )
}
b = appendNullComma (ctx , b )
code = code .Next
break
}
store (ctxptr , code .Idx , p )
fallthrough
case encoder .OpIntString :
b = append (b , '"' )
b = encoder .AppendInt (ctx , b , load (ctxptr , code .Idx ), code )
b = append (b , '"' )
b = appendComma (ctx , b )
code = code .Next
case encoder .OpUintPtrString :
p := ptrToNPtr (load (ctxptr , code .Idx ), code .PtrNum )
if p == nil {
if code .Flags &encoder .MapKeyFlags != 0 {
return b , encoder .ErrNilMapKey (code )
}
b = appendNullComma (ctx , b )
code = code .Next
break
}
store (ctxptr , code .Idx , p )
fallthrough
case encoder .OpUintString :
b = append (b , '"' )
b = encoder .AppendUint (ctx , b , load (ctxptr , code .Idx ), code )
b = append (b , '"' )
b = appendComma (ctx , b )
code = code .Next
case encoder .OpFloat32PtrString :
p := ptrToNPtr (load (ctxptr , code .Idx ), code .PtrNum )
if p == nil {
b = appendNullComma (ctx , b )
code = code .Next
break
}
store (ctxptr , code .Idx , p )
fallthrough
case encoder .OpFloat32String :
b = append (b , '"' )
bb , err := appendFloat32 (ctx , code , b , ptrToFloat32 (load (ctxptr , code .Idx )))
if err != nil {
return b , err
}
b = bb
b = append (b , '"' )
b = appendComma (ctx , b )
code = code .Next
case encoder .OpFloat64PtrString :
p := ptrToNPtr (load (ctxptr , code .Idx ), code .PtrNum )
if p == nil {
b = appendNullComma (ctx , b )
code = code .Next
break
}
store (ctxptr , code .Idx , p )
fallthrough
case encoder .OpFloat64String :
v := ptrToFloat64 (load (ctxptr , code .Idx ))
if isInfOrNaN (v ) {
return b , errUnsupportedFloat (ctx , code , v )
}
b = append (b , '"' )
b = encoder .AppendFloat64 (ctx , b , v )
b = append (b , '"' )
b = appendComma (ctx , b )
code = code .Next
case encoder .OpBoolPtrString :
p := ptrToNPtr (load (ctxptr , code .Idx ), code .PtrNum )
if p == nil {
b = appendNullComma (ctx , b )
code = code .Next
break
}
store (ctxptr , code .Idx , p )
fallthrough
case encoder .OpBoolString :
b = append (b , '"' )
b = appendBool (ctx , b , ptrToBool (load (ctxptr , code .Idx )))
b = append (b , '"' )
b = appendComma (ctx , b )
code = code .Next
case encoder .OpStringPtrString :
p := ptrToNPtr (load (ctxptr , code .Idx ), code .PtrNum )
if p == nil {
b = appendNullComma (ctx , b )
code = code .Next
break
}
store (ctxptr , code .Idx , p )
fallthrough
case encoder .OpStringString :
quoted , _ := jsonstring .AppendQuoted (encoder .StringEscaper (ctx ), []byte {}, ptrToString (load (ctxptr , code .Idx )))
b , _ = jsonstring .AppendQuoted (encoder .StringEscaper (ctx ), b , string (quoted ))
b = appendComma (ctx , b )
code = code .Next
case encoder .OpNumberPtrString :
p := ptrToNPtr (load (ctxptr , code .Idx ), code .PtrNum )
if p == nil {
b = appendNullComma (ctx , b )
code = code .Next
break
}
store (ctxptr , code .Idx , p )
fallthrough
case encoder .OpNumberString :
b = append (b , '"' )
bb , err := appendNumberString (ctx , b , ptrToNumber (load (ctxptr , code .Idx )))
if err != nil {
return b , err
}
b = append (bb , '"' )
b = appendComma (ctx , b )
code = code .Next
case encoder .OpFloat32Ptr :
p := ptrToNPtr (load (ctxptr , code .Idx ), code .PtrNum )
if p == nil {
b = appendNull (ctx , b )
b = appendComma (ctx , b )
code = code .Next
break
}
store (ctxptr , code .Idx , p )
fallthrough
case encoder .OpFloat32 :
bb , err := appendFloat32 (ctx , code , b , ptrToFloat32 (load (ctxptr , code .Idx )))
if err != nil {
return b , err
}
b = bb
b = appendComma (ctx , b )
code = code .Next
case encoder .OpFloat64Ptr :
p := ptrToNPtr (load (ctxptr , code .Idx ), code .PtrNum )
if p == nil {
b = appendNullComma (ctx , b )
code = code .Next
break
}
store (ctxptr , code .Idx , p )
fallthrough
case encoder .OpFloat64 :
v := ptrToFloat64 (load (ctxptr , code .Idx ))
if isInfOrNaN (v ) {
return b , errUnsupportedFloat (ctx , code , v )
}
b = encoder .AppendFloat64 (ctx , b , v )
b = appendComma (ctx , b )
code = code .Next
case encoder .OpStringPtr :
p := ptrToNPtr (load (ctxptr , code .Idx ), code .PtrNum )
if p == nil {
if code .Flags &encoder .MapKeyFlags != 0 {
return b , encoder .ErrNilMapKey (code )
}
b = appendNullComma (ctx , b )
code = code .Next
break
}
store (ctxptr , code .Idx , p )
fallthrough
case encoder .OpString :
b , _ = jsonstring .AppendQuoted (encoder .StringEscaper (ctx ), b , ptrToString (load (ctxptr , code .Idx )))
b = appendComma (ctx , b )
code = code .Next
case encoder .OpBoolPtr :
p := ptrToNPtr (load (ctxptr , code .Idx ), code .PtrNum )
if p == nil {
b = appendNullComma (ctx , b )
code = code .Next
break
}
store (ctxptr , code .Idx , p )
fallthrough
case encoder .OpBool :
b = appendBool (ctx , b , ptrToBool (load (ctxptr , code .Idx )))
b = appendComma (ctx , b )
code = code .Next
case encoder .OpBytesPtr :
p := ptrToNPtr (load (ctxptr , code .Idx ), code .PtrNum )
if p == nil {
b = appendNullComma (ctx , b )
code = code .Next
break
}
store (ctxptr , code .Idx , p )
fallthrough
case encoder .OpBytes :
b = encoder .AppendByteSlice (ctx , b , ptrToBytes (load (ctxptr , code .Idx )))
b = appendComma (ctx , b )
code = code .Next
case encoder .OpNumberPtr :
p := ptrToNPtr (load (ctxptr , code .Idx ), code .PtrNum )
if p == nil {
b = appendNullComma (ctx , b )
code = code .Next
break
}
store (ctxptr , code .Idx , p )
fallthrough
case encoder .OpNumber :
bb , err := encoder .AppendNumber (ctx , b , ptrToNumber (load (ctxptr , code .Idx )))
if err != nil {
return b , err
}
b = appendComma (ctx , bb )
code = code .Next
case encoder .OpMarshalJSONPtr :
p := load (ctxptr , code .Idx )
if p == nil {
b = appendNullComma (ctx , b )
code = code .Next
break
}
store (ctxptr , code .Idx , ptrToNPtr (p , code .PtrNum ))
fallthrough
case encoder .OpMarshalJSON :
p := load (ctxptr , code .Idx )
if p == nil {
b = appendNullComma (ctx , b )
code = code .Next
break
}
if (code .Flags &encoder .IsNilableTypeFlags ) != 0 && (code .Flags &encoder .IndirectFlags ) != 0 {
p = ptrToPtr (p )
}
bb , err := appendMarshalJSON (ctx , code , b , p )
if err != nil {
return b , err
}
b = appendComma (ctx , bb )
code = code .Next
case encoder .OpMarshalTextPtr :
p := load (ctxptr , code .Idx )
if p == nil {
b = appendNullComma (ctx , b )
code = code .Next
break
}
store (ctxptr , code .Idx , ptrToNPtr (p , code .PtrNum ))
fallthrough
case encoder .OpMarshalText :
p := load (ctxptr , code .Idx )
if p == nil {
if (code .Flags & encoder .InterfaceMapKeyFlags ) != 0 {
return b , encoder .NilMapKeyError (code )
}
if (code .Flags & encoder .MapKeyFlags ) != 0 {
b = appendComma (ctx , append (b , `""` ...))
} else {
b = appendNullComma (ctx , b )
}
code = code .Next
break
}
if (code .Flags &encoder .IsNilableTypeFlags ) != 0 && (code .Flags &encoder .IndirectFlags ) != 0 {
p = ptrToPtr (p )
}
bb , err := appendMarshalText (ctx , code , b , p )
if err != nil {
return b , err
}
b = appendComma (ctx , bb )
code = code .Next
case encoder .OpSlicePtr :
p := ptrToNPtr (load (ctxptr , code .Idx ), code .PtrNum )
if p == nil {
b = appendNullComma (ctx , b )
code = code .End .Next
break
}
store (ctxptr , code .Idx , p )
fallthrough
case encoder .OpSlice :
p := load (ctxptr , code .Idx )
slice := ptrToSlice (p )
if p == nil || slice .Data == nil {
if p != nil && encoder .NilSliceIsEmpty (ctx ) {
b = appendEmptyArray (ctx , b )
} else {
b = appendNullComma (ctx , b )
}
code = code .End .Next
break
}
storeInt (ctxptr , code .ElemIdx , 0 )
storeInt (ctxptr , code .Length , uintptr (slice .Len ))
store (ctxptr , code .Idx , slice .Data )
if slice .Len > 0 {
b = appendArrayHead (ctx , code , b )
code = code .Next
store (ctxptr , code .Idx , slice .Data )
} else {
b = appendEmptyArray (ctx , b )
code = code .End .Next
}
case encoder .OpSliceElem :
idx := loadInt (ctxptr , code .ElemIdx )
length := loadInt (ctxptr , code .Length )
idx ++
if idx < length {
b = appendArrayElemIndent (ctx , code , b )
storeInt (ctxptr , code .ElemIdx , idx )
data := load (ctxptr , code .Idx )
size := uintptr (code .Size )
code = code .Next
store (ctxptr , code .Idx , unsafe .Add (data , idx *size ))
} else {
b = appendArrayEnd (ctx , code , b )
code = code .End .Next
}
case encoder .OpArrayPtr :
p := ptrToNPtr (load (ctxptr , code .Idx ), code .PtrNum )
if p == nil {
b = appendNullComma (ctx , b )
code = code .End .Next
break
}
store (ctxptr , code .Idx , p )
fallthrough
case encoder .OpArray :
p := load (ctxptr , code .Idx )
if p == nil {
b = appendNullComma (ctx , b )
code = code .End .Next
break
}
if code .Length > 0 {
b = appendArrayHead (ctx , code , b )
storeInt (ctxptr , code .ElemIdx , 0 )
code = code .Next
store (ctxptr , code .Idx , p )
} else {
b = appendEmptyArray (ctx , b )
code = code .End .Next
}
case encoder .OpArrayElem :
idx := loadInt (ctxptr , code .ElemIdx )
idx ++
if idx < uintptr (code .Length ) {
b = appendArrayElemIndent (ctx , code , b )
storeInt (ctxptr , code .ElemIdx , idx )
p := load (ctxptr , code .Idx )
size := uintptr (code .Size )
code = code .Next
store (ctxptr , code .Idx , unsafe .Add (p , idx *size ))
} else {
b = appendArrayEnd (ctx , code , b )
code = code .End .Next
}
case encoder .OpRecursivePtr :
p := load (ctxptr , code .Idx )
if p == nil {
code = code .Next
break
}
store (ctxptr , code .Idx , ptrToNPtr (p , code .PtrNum ))
fallthrough
case encoder .OpRecursive :
if code .Flags &encoder .TailRecursiveFlags != 0 {
p := load (ctxptr , code .Idx )
if ctx .RecursiveLevel > encoder .StartDetectingCyclesAfter {
if err := ctx .RecordSeen (code , p ); err != nil {
return b , err
}
}
first := code .Jmp .Code
store (ctxptr , first .Idx , p )
ctx .BaseIndent += code .Next .Next .Indent
if ctx .BaseIndent +code .Jmp .Levels > encoder .MaxDepth && p != nil {
return b , encoder .ErrMaxDepth (ctx )
}
ctx .TailLevels ++
ctx .RecursiveLevel ++
code = first
break
}
first , base , err := ctx .EnterRecursive (code , load (ctxptr , code .Idx ))
if err != nil {
return b , err
}
code = first
ctxptr = base
case encoder .OpStructFieldOmitEmptyStringPtrOrEmpty :
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
if p != nil {
if s := ptrToString (p ); s != "" {
b = appendStructKey (ctx , code , b )
b , _ = jsonstring .AppendQuoted (encoder .StringEscaper (ctx ), b , s )
b = appendComma (ctx , b )
}
}
code = code .Next
case encoder .OpUnwriteEmpty :
b = encoder .UnwriteEmptyMember (ctx , b , len (code .Key ))
code = code .Next
case encoder .OpRecursiveEnd :
for ; ctx .TailLevels > 0 ; ctx .TailLevels -- {
ctx .RecursiveLevel --
if ctx .RecursiveLevel > encoder .StartDetectingCyclesAfter {
ctx .SeenPtr = ctx .SeenPtr [:len (ctx .SeenPtr )-1 ]
}
ctx .BaseIndent -= code .Indent
b = appendStructEndSkipLast (ctx , code .Next , b )
}
code , ctxptr = ctx .LeaveFrame (code )
case encoder .OpStructPtrHead :
p := load (ctxptr , code .Idx )
if p == nil {
if code .Flags &encoder .AnonymousHeadFlags == 0 {
b = appendNullComma (ctx , b )
}
code = code .End .Next
break
}
store (ctxptr , code .Idx , ptrToNPtr (p , code .PtrNum ))
fallthrough
case encoder .OpStructHead :
p := load (ctxptr , code .Idx )
if p == nil && ((code .Flags &encoder .IndirectFlags ) != 0 || code .Next .Op == encoder .OpStructEnd ) {
if code .Flags &encoder .AnonymousHeadFlags == 0 {
b = appendNullComma (ctx , b )
}
code = code .End .Next
break
}
if code .Flags &encoder .AnonymousHeadFlags == 0 {
b = appendStructHead (ctx , b )
}
code = code .Next
case encoder .OpStructField :
if code .Flags &encoder .IsTaggedKeyFlags != 0 || code .Flags &encoder .AnonymousKeyFlags == 0 {
if len (code .Key ) <= encoder .KeyChunkSize {
b = appendStructKey (ctx , code , b )
} else {
b = appendLongStructKey (ctx , code , b )
}
}
p := unsafe .Add (load (ctxptr , code .Idx ), code .Offset )
code = code .Next
store (ctxptr , code .Idx , p )
case encoder .OpStructFieldOmitEmpty :
p := load (ctxptr , code .Idx )
p = unsafe .Add (p , code .Offset )
if encoder .IsEmptyField (code .EmptyKind , code .NumBitSize , p ) || (code .ZeroKind != encoder .ZeroNever && encoder .IsZeroField (code , p )) {
code = code .NextField
} else {
if len (code .Key ) <= encoder .KeyChunkSize {
b = appendStructKey (ctx , code , b )
} else {
b = appendLongStructKey (ctx , code , b )
}
code = code .Next
store (ctxptr , code .Idx , p )
}
case encoder .OpStructFieldInt3 :
p := load (ctxptr , code .Idx )
b = appendStructKey (ctx , code , b )
b = encoder .AppendInt (ctx , b , unsafe .Add (p , code .Offset ), code )
b = appendComma (ctx , b )
code = code .Next
fallthrough
case encoder .OpStructFieldInt2 :
p := load (ctxptr , code .Idx )
b = appendStructKey (ctx , code , b )
b = encoder .AppendInt (ctx , b , unsafe .Add (p , code .Offset ), code )
b = appendComma (ctx , b )
code = code .Next
fallthrough
case encoder .OpStructFieldInt :
p := load (ctxptr , code .Idx )
b = appendStructKey (ctx , code , b )
b = encoder .AppendInt (ctx , b , unsafe .Add (p , code .Offset ), code )
b = appendComma (ctx , b )
code = code .Next
case encoder .OpStructFieldOmitEmptyInt :
p := load (ctxptr , code .Idx )
u64 := ptrToUint64 (unsafe .Add (p , code .Offset ), code .NumBitSize )
v := u64 & ((1 << code .NumBitSize ) - 1 )
if v != 0 {
b = appendStructKey (ctx , code , b )
b = encoder .AppendInt (ctx , b , unsafe .Add (p , code .Offset ), code )
b = appendComma (ctx , b )
}
code = code .Next
case encoder .OpStructFieldIntString :
p := load (ctxptr , code .Idx )
b = appendStructKey (ctx , code , b )
b = append (b , '"' )
b = encoder .AppendInt (ctx , b , unsafe .Add (p , code .Offset ), code )
b = append (b , '"' )
b = appendComma (ctx , b )
code = code .Next
case encoder .OpStructFieldOmitEmptyIntString :
p := load (ctxptr , code .Idx )
u64 := ptrToUint64 (unsafe .Add (p , code .Offset ), code .NumBitSize )
v := u64 & ((1 << code .NumBitSize ) - 1 )
if v != 0 {
b = appendStructKey (ctx , code , b )
b = append (b , '"' )
b = encoder .AppendInt (ctx , b , unsafe .Add (p , code .Offset ), code )
b = append (b , '"' )
b = appendComma (ctx , b )
}
code = code .Next
case encoder .OpStructFieldIntPtr :
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
b = appendStructKey (ctx , code , b )
if p == nil {
b = appendNull (ctx , b )
} else {
b = encoder .AppendInt (ctx , b , p , code )
}
b = appendComma (ctx , b )
code = code .Next
case encoder .OpStructFieldOmitEmptyIntPtr :
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
if p != nil {
b = appendStructKey (ctx , code , b )
b = encoder .AppendInt (ctx , b , p , code )
b = appendComma (ctx , b )
code = code .Next
} else {
code = code .NextField
}
case encoder .OpStructFieldIntPtrString :
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
b = appendStructKey (ctx , code , b )
if p == nil {
b = appendNull (ctx , b )
} else {
b = append (b , '"' )
b = encoder .AppendInt (ctx , b , p , code )
b = append (b , '"' )
}
b = appendComma (ctx , b )
code = code .Next
case encoder .OpStructFieldOmitEmptyIntPtrString :
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
if p != nil {
b = appendStructKey (ctx , code , b )
b = append (b , '"' )
b = encoder .AppendInt (ctx , b , p , code )
b = append (b , '"' )
b = appendComma (ctx , b )
code = code .Next
} else {
code = code .NextField
}
case encoder .OpStructFieldUint3 :
p := load (ctxptr , code .Idx )
b = appendStructKey (ctx , code , b )
b = encoder .AppendUint (ctx , b , unsafe .Add (p , code .Offset ), code )
b = appendComma (ctx , b )
code = code .Next
fallthrough
case encoder .OpStructFieldUint2 :
p := load (ctxptr , code .Idx )
b = appendStructKey (ctx , code , b )
b = encoder .AppendUint (ctx , b , unsafe .Add (p , code .Offset ), code )
b = appendComma (ctx , b )
code = code .Next
fallthrough
case encoder .OpStructFieldUint :
p := load (ctxptr , code .Idx )
b = appendStructKey (ctx , code , b )
b = encoder .AppendUint (ctx , b , unsafe .Add (p , code .Offset ), code )
b = appendComma (ctx , b )
code = code .Next
case encoder .OpStructFieldOmitEmptyUint :
p := load (ctxptr , code .Idx )
u64 := ptrToUint64 (unsafe .Add (p , code .Offset ), code .NumBitSize )
v := u64 & ((1 << code .NumBitSize ) - 1 )
if v != 0 {
b = appendStructKey (ctx , code , b )
b = encoder .AppendUint (ctx , b , unsafe .Add (p , code .Offset ), code )
b = appendComma (ctx , b )
}
code = code .Next
case encoder .OpStructFieldUintString :
p := load (ctxptr , code .Idx )
b = appendStructKey (ctx , code , b )
b = append (b , '"' )
b = encoder .AppendUint (ctx , b , unsafe .Add (p , code .Offset ), code )
b = append (b , '"' )
b = appendComma (ctx , b )
code = code .Next
case encoder .OpStructFieldOmitEmptyUintString :
p := load (ctxptr , code .Idx )
u64 := ptrToUint64 (unsafe .Add (p , code .Offset ), code .NumBitSize )
v := u64 & ((1 << code .NumBitSize ) - 1 )
if v != 0 {
b = appendStructKey (ctx , code , b )
b = append (b , '"' )
b = encoder .AppendUint (ctx , b , unsafe .Add (p , code .Offset ), code )
b = append (b , '"' )
b = appendComma (ctx , b )
}
code = code .Next
case encoder .OpStructFieldUintPtr :
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
b = appendStructKey (ctx , code , b )
if p == nil {
b = appendNull (ctx , b )
} else {
b = encoder .AppendUint (ctx , b , p , code )
}
b = appendComma (ctx , b )
code = code .Next
case encoder .OpStructFieldOmitEmptyUintPtr :
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
if p != nil {
b = appendStructKey (ctx , code , b )
b = encoder .AppendUint (ctx , b , p , code )
b = appendComma (ctx , b )
code = code .Next
} else {
code = code .NextField
}
case encoder .OpStructFieldUintPtrString :
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
b = appendStructKey (ctx , code , b )
if p == nil {
b = appendNull (ctx , b )
} else {
b = append (b , '"' )
b = encoder .AppendUint (ctx , b , p , code )
b = append (b , '"' )
}
b = appendComma (ctx , b )
code = code .Next
case encoder .OpStructFieldOmitEmptyUintPtrString :
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
if p != nil {
b = appendStructKey (ctx , code , b )
b = append (b , '"' )
b = encoder .AppendUint (ctx , b , p , code )
b = append (b , '"' )
b = appendComma (ctx , b )
code = code .Next
} else {
code = code .NextField
}
case encoder .OpStructFieldFloat32 :
p := load (ctxptr , code .Idx )
b = appendStructKey (ctx , code , b )
bb , err := appendFloat32 (ctx , code , b , ptrToFloat32 (unsafe .Add (p , code .Offset )))
if err != nil {
return b , err
}
b = bb
b = appendComma (ctx , b )
code = code .Next
case encoder .OpStructFieldOmitEmptyFloat32 :
p := load (ctxptr , code .Idx )
v := ptrToFloat32 (unsafe .Add (p , code .Offset ))
if v != 0 {
b = appendStructKey (ctx , code , b )
bb , err := appendFloat32 (ctx , code , b , v )
if err != nil {
return b , err
}
b = bb
b = appendComma (ctx , b )
}
code = code .Next
case encoder .OpStructFieldFloat32String :
p := load (ctxptr , code .Idx )
b = appendStructKey (ctx , code , b )
b = append (b , '"' )
bb , err := appendFloat32 (ctx , code , b , ptrToFloat32 (unsafe .Add (p , code .Offset )))
if err != nil {
return b , err
}
b = bb
b = append (b , '"' )
b = appendComma (ctx , b )
code = code .Next
case encoder .OpStructFieldOmitEmptyFloat32String :
p := load (ctxptr , code .Idx )
v := ptrToFloat32 (unsafe .Add (p , code .Offset ))
if v != 0 {
b = appendStructKey (ctx , code , b )
b = append (b , '"' )
bb , err := appendFloat32 (ctx , code , b , v )
if err != nil {
return b , err
}
b = bb
b = append (b , '"' )
b = appendComma (ctx , b )
}
code = code .Next
case encoder .OpStructFieldFloat32Ptr :
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
b = appendStructKey (ctx , code , b )
if p == nil {
b = appendNull (ctx , b )
} else {
bb , err := appendFloat32 (ctx , code , b , ptrToFloat32 (p ))
if err != nil {
return b , err
}
b = bb
}
b = appendComma (ctx , b )
code = code .Next
case encoder .OpStructFieldOmitEmptyFloat32Ptr :
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
if p != nil {
b = appendStructKey (ctx , code , b )
bb , err := appendFloat32 (ctx , code , b , ptrToFloat32 (p ))
if err != nil {
return b , err
}
b = bb
b = appendComma (ctx , b )
code = code .Next
} else {
code = code .NextField
}
case encoder .OpStructFieldFloat32PtrString :
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
b = appendStructKey (ctx , code , b )
if p == nil {
b = appendNull (ctx , b )
} else {
b = append (b , '"' )
bb , err := appendFloat32 (ctx , code , b , ptrToFloat32 (p ))
if err != nil {
return b , err
}
b = bb
b = append (b , '"' )
}
b = appendComma (ctx , b )
code = code .Next
case encoder .OpStructFieldOmitEmptyFloat32PtrString :
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
if p != nil {
b = appendStructKey (ctx , code , b )
b = append (b , '"' )
bb , err := appendFloat32 (ctx , code , b , ptrToFloat32 (p ))
if err != nil {
return b , err
}
b = bb
b = append (b , '"' )
b = appendComma (ctx , b )
code = code .Next
} else {
code = code .NextField
}
case encoder .OpStructFieldFloat643 :
p := load (ctxptr , code .Idx )
b = appendStructKey (ctx , code , b )
v := ptrToFloat64 (unsafe .Add (p , code .Offset ))
if isInfOrNaN (v ) {
return b , errUnsupportedFloat (ctx , code , v )
}
b = encoder .AppendFloat64 (ctx , b , v )
b = appendComma (ctx , b )
code = code .Next
fallthrough
case encoder .OpStructFieldFloat642 :
p := load (ctxptr , code .Idx )
b = appendStructKey (ctx , code , b )
v := ptrToFloat64 (unsafe .Add (p , code .Offset ))
if isInfOrNaN (v ) {
return b , errUnsupportedFloat (ctx , code , v )
}
b = encoder .AppendFloat64 (ctx , b , v )
b = appendComma (ctx , b )
code = code .Next
fallthrough
case encoder .OpStructFieldFloat64 :
p := load (ctxptr , code .Idx )
b = appendStructKey (ctx , code , b )
v := ptrToFloat64 (unsafe .Add (p , code .Offset ))
if isInfOrNaN (v ) {
return b , errUnsupportedFloat (ctx , code , v )
}
b = encoder .AppendFloat64 (ctx , b , v )
b = appendComma (ctx , b )
code = code .Next
case encoder .OpStructFieldOmitEmptyFloat64 :
p := load (ctxptr , code .Idx )
v := ptrToFloat64 (unsafe .Add (p , code .Offset ))
if v != 0 {
if isInfOrNaN (v ) {
return b , errUnsupportedFloat (ctx , code , v )
}
b = appendStructKey (ctx , code , b )
b = encoder .AppendFloat64 (ctx , b , v )
b = appendComma (ctx , b )
}
code = code .Next
case encoder .OpStructFieldFloat64String :
p := load (ctxptr , code .Idx )
v := ptrToFloat64 (unsafe .Add (p , code .Offset ))
if isInfOrNaN (v ) {
return b , errUnsupportedFloat (ctx , code , v )
}
b = appendStructKey (ctx , code , b )
b = append (b , '"' )
b = encoder .AppendFloat64 (ctx , b , v )
b = append (b , '"' )
b = appendComma (ctx , b )
code = code .Next
case encoder .OpStructFieldOmitEmptyFloat64String :
p := load (ctxptr , code .Idx )
v := ptrToFloat64 (unsafe .Add (p , code .Offset ))
if v != 0 {
if isInfOrNaN (v ) {
return b , errUnsupportedFloat (ctx , code , v )
}
b = appendStructKey (ctx , code , b )
b = append (b , '"' )
b = encoder .AppendFloat64 (ctx , b , v )
b = append (b , '"' )
b = appendComma (ctx , b )
}
code = code .Next
case encoder .OpStructFieldFloat64Ptr :
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
b = appendStructKey (ctx , code , b )
if p == nil {
b = appendNullComma (ctx , b )
code = code .Next
break
}
v := ptrToFloat64 (p )
if isInfOrNaN (v ) {
return b , errUnsupportedFloat (ctx , code , v )
}
b = encoder .AppendFloat64 (ctx , b , v )
b = appendComma (ctx , b )
code = code .Next
case encoder .OpStructFieldOmitEmptyFloat64Ptr :
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
if p != nil {
b = appendStructKey (ctx , code , b )
v := ptrToFloat64 (p )
if isInfOrNaN (v ) {
return b , errUnsupportedFloat (ctx , code , v )
}
b = encoder .AppendFloat64 (ctx , b , v )
b = appendComma (ctx , b )
code = code .Next
} else {
code = code .NextField
}
case encoder .OpStructFieldFloat64PtrString :
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
b = appendStructKey (ctx , code , b )
if p == nil {
b = appendNull (ctx , b )
} else {
v := ptrToFloat64 (p )
if isInfOrNaN (v ) {
return b , errUnsupportedFloat (ctx , code , v )
}
b = append (b , '"' )
b = encoder .AppendFloat64 (ctx , b , v )
b = append (b , '"' )
}
b = appendComma (ctx , b )
code = code .Next
case encoder .OpStructFieldOmitEmptyFloat64PtrString :
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
if p != nil {
b = appendStructKey (ctx , code , b )
b = append (b , '"' )
v := ptrToFloat64 (p )
if isInfOrNaN (v ) {
return b , errUnsupportedFloat (ctx , code , v )
}
b = encoder .AppendFloat64 (ctx , b , v )
b = append (b , '"' )
b = appendComma (ctx , b )
code = code .Next
} else {
code = code .NextField
}
case encoder .OpStructFieldString3 :
p := load (ctxptr , code .Idx )
b = appendStructKey (ctx , code , b )
b , _ = jsonstring .AppendQuoted (encoder .StringEscaper (ctx ), b , ptrToString (unsafe .Add (p , code .Offset )))
b = appendComma (ctx , b )
code = code .Next
fallthrough
case encoder .OpStructFieldString2 :
p := load (ctxptr , code .Idx )
b = appendStructKey (ctx , code , b )
b , _ = jsonstring .AppendQuoted (encoder .StringEscaper (ctx ), b , ptrToString (unsafe .Add (p , code .Offset )))
b = appendComma (ctx , b )
code = code .Next
fallthrough
case encoder .OpStructFieldString :
p := load (ctxptr , code .Idx )
b = appendStructKey (ctx , code , b )
b , _ = jsonstring .AppendQuoted (encoder .StringEscaper (ctx ), b , ptrToString (unsafe .Add (p , code .Offset )))
b = appendComma (ctx , b )
code = code .Next
case encoder .OpStructFieldOmitEmptyString :
p := load (ctxptr , code .Idx )
v := ptrToString (unsafe .Add (p , code .Offset ))
if v != "" {
b = appendStructKey (ctx , code , b )
b , _ = jsonstring .AppendQuoted (encoder .StringEscaper (ctx ), b , v )
b = appendComma (ctx , b )
}
code = code .Next
case encoder .OpStructFieldStringString :
p := load (ctxptr , code .Idx )
s := ptrToString (unsafe .Add (p , code .Offset ))
b = appendStructKey (ctx , code , b )
quoted , _ := jsonstring .AppendQuoted (encoder .StringEscaper (ctx ), []byte {}, s )
b , _ = jsonstring .AppendQuoted (encoder .StringEscaper (ctx ), b , string (quoted ))
b = appendComma (ctx , b )
code = code .Next
case encoder .OpStructFieldOmitEmptyStringString :
p := load (ctxptr , code .Idx )
v := ptrToString (unsafe .Add (p , code .Offset ))
if v != "" {
b = appendStructKey (ctx , code , b )
quoted , _ := jsonstring .AppendQuoted (encoder .StringEscaper (ctx ), []byte {}, v )
b , _ = jsonstring .AppendQuoted (encoder .StringEscaper (ctx ), b , string (quoted ))
b = appendComma (ctx , b )
}
code = code .Next
case encoder .OpStructFieldStringPtr :
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
b = appendStructKey (ctx , code , b )
if p == nil {
b = appendNull (ctx , b )
} else {
b , _ = jsonstring .AppendQuoted (encoder .StringEscaper (ctx ), b , ptrToString (p ))
}
b = appendComma (ctx , b )
code = code .Next
case encoder .OpStructFieldOmitEmptyStringPtr :
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
if p != nil {
b = appendStructKey (ctx , code , b )
b , _ = jsonstring .AppendQuoted (encoder .StringEscaper (ctx ), b , ptrToString (p ))
b = appendComma (ctx , b )
code = code .Next
} else {
code = code .NextField
}
case encoder .OpStructFieldStringPtrString :
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
b = appendStructKey (ctx , code , b )
if p == nil {
b = appendNull (ctx , b )
} else {
quoted , _ := jsonstring .AppendQuoted (encoder .StringEscaper (ctx ), []byte {}, ptrToString (p ))
b , _ = jsonstring .AppendQuoted (encoder .StringEscaper (ctx ), b , string (quoted ))
}
b = appendComma (ctx , b )
code = code .Next
case encoder .OpStructFieldOmitEmptyStringPtrString :
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
if p != nil {
b = appendStructKey (ctx , code , b )
quoted , _ := jsonstring .AppendQuoted (encoder .StringEscaper (ctx ), []byte {}, ptrToString (p ))
b , _ = jsonstring .AppendQuoted (encoder .StringEscaper (ctx ), b , string (quoted ))
b = appendComma (ctx , b )
code = code .Next
} else {
code = code .NextField
}
case encoder .OpStructFieldBool3 :
p := load (ctxptr , code .Idx )
b = appendStructKey (ctx , code , b )
b = appendBool (ctx , b , ptrToBool (unsafe .Add (p , code .Offset )))
b = appendComma (ctx , b )
code = code .Next
fallthrough
case encoder .OpStructFieldBool2 :
p := load (ctxptr , code .Idx )
b = appendStructKey (ctx , code , b )
b = appendBool (ctx , b , ptrToBool (unsafe .Add (p , code .Offset )))
b = appendComma (ctx , b )
code = code .Next
fallthrough
case encoder .OpStructFieldBool :
p := load (ctxptr , code .Idx )
b = appendStructKey (ctx , code , b )
b = appendBool (ctx , b , ptrToBool (unsafe .Add (p , code .Offset )))
b = appendComma (ctx , b )
code = code .Next
case encoder .OpStructFieldOmitEmptyBool :
p := load (ctxptr , code .Idx )
v := ptrToBool (unsafe .Add (p , code .Offset ))
if v {
b = appendStructKey (ctx , code , b )
b = appendBool (ctx , b , v )
b = appendComma (ctx , b )
}
code = code .Next
case encoder .OpStructFieldBoolString :
p := load (ctxptr , code .Idx )
b = appendStructKey (ctx , code , b )
b = append (b , '"' )
b = appendBool (ctx , b , ptrToBool (unsafe .Add (p , code .Offset )))
b = append (b , '"' )
b = appendComma (ctx , b )
code = code .Next
case encoder .OpStructFieldOmitEmptyBoolString :
p := load (ctxptr , code .Idx )
v := ptrToBool (unsafe .Add (p , code .Offset ))
if v {
b = appendStructKey (ctx , code , b )
b = append (b , '"' )
b = appendBool (ctx , b , v )
b = append (b , '"' )
b = appendComma (ctx , b )
}
code = code .Next
case encoder .OpStructFieldBoolPtr :
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
b = appendStructKey (ctx , code , b )
if p == nil {
b = appendNull (ctx , b )
} else {
b = appendBool (ctx , b , ptrToBool (p ))
}
b = appendComma (ctx , b )
code = code .Next
case encoder .OpStructFieldOmitEmptyBoolPtr :
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
if p != nil {
b = appendStructKey (ctx , code , b )
b = appendBool (ctx , b , ptrToBool (p ))
b = appendComma (ctx , b )
code = code .Next
} else {
code = code .NextField
}
case encoder .OpStructFieldBoolPtrString :
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
b = appendStructKey (ctx , code , b )
if p == nil {
b = appendNull (ctx , b )
} else {
b = append (b , '"' )
b = appendBool (ctx , b , ptrToBool (p ))
b = append (b , '"' )
}
b = appendComma (ctx , b )
code = code .Next
case encoder .OpStructFieldOmitEmptyBoolPtrString :
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
if p != nil {
b = appendStructKey (ctx , code , b )
b = append (b , '"' )
b = appendBool (ctx , b , ptrToBool (p ))
b = append (b , '"' )
b = appendComma (ctx , b )
code = code .Next
} else {
code = code .NextField
}
case encoder .OpStructFieldBytes :
p := load (ctxptr , code .Idx )
b = appendStructKey (ctx , code , b )
b = encoder .AppendByteSlice (ctx , b , ptrToBytes (unsafe .Add (p , code .Offset )))
b = appendComma (ctx , b )
code = code .Next
case encoder .OpStructFieldOmitEmptyBytes :
p := load (ctxptr , code .Idx )
v := ptrToBytes (unsafe .Add (p , code .Offset ))
if len (v ) > 0 {
b = appendStructKey (ctx , code , b )
b = encoder .AppendByteSlice (ctx , b , v )
b = appendComma (ctx , b )
}
code = code .Next
case encoder .OpStructFieldBytesPtr :
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
b = appendStructKey (ctx , code , b )
if p == nil {
b = appendNull (ctx , b )
} else {
b = encoder .AppendByteSlice (ctx , b , ptrToBytes (p ))
}
b = appendComma (ctx , b )
code = code .Next
case encoder .OpStructFieldOmitEmptyBytesPtr :
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
if p != nil {
b = appendStructKey (ctx , code , b )
b = encoder .AppendByteSlice (ctx , b , ptrToBytes (p ))
b = appendComma (ctx , b )
code = code .Next
} else {
code = code .NextField
}
case encoder .OpStructFieldNumber :
p := load (ctxptr , code .Idx )
b = appendStructKey (ctx , code , b )
bb , err := encoder .AppendNumber (ctx , b , ptrToNumber (unsafe .Add (p , code .Offset )))
if err != nil {
return b , err
}
b = appendComma (ctx , bb )
code = code .Next
case encoder .OpStructFieldOmitEmptyNumber :
p := load (ctxptr , code .Idx )
v := ptrToNumber (unsafe .Add (p , code .Offset ))
if v != "" {
b = appendStructKey (ctx , code , b )
bb , err := encoder .AppendNumber (ctx , b , v )
if err != nil {
return b , err
}
b = appendComma (ctx , bb )
}
code = code .Next
case encoder .OpStructFieldNumberString :
p := load (ctxptr , code .Idx )
b = appendStructKey (ctx , code , b )
b = append (b , '"' )
bb , err := appendNumberString (ctx , b , ptrToNumber (unsafe .Add (p , code .Offset )))
if err != nil {
return b , err
}
b = append (bb , '"' )
b = appendComma (ctx , b )
code = code .Next
case encoder .OpStructFieldOmitEmptyNumberString :
p := load (ctxptr , code .Idx )
v := ptrToNumber (unsafe .Add (p , code .Offset ))
if v != "" {
b = appendStructKey (ctx , code , b )
b = append (b , '"' )
bb , err := appendNumberString (ctx , b , v )
if err != nil {
return b , err
}
b = append (bb , '"' )
b = appendComma (ctx , b )
}
code = code .Next
case encoder .OpStructFieldNumberPtr :
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
b = appendStructKey (ctx , code , b )
if p == nil {
b = appendNull (ctx , b )
} else {
bb , err := encoder .AppendNumber (ctx , b , ptrToNumber (p ))
if err != nil {
return b , err
}
b = bb
}
b = appendComma (ctx , b )
code = code .Next
case encoder .OpStructFieldOmitEmptyNumberPtr :
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
if p != nil {
b = appendStructKey (ctx , code , b )
bb , err := encoder .AppendNumber (ctx , b , ptrToNumber (p ))
if err != nil {
return b , err
}
b = appendComma (ctx , bb )
code = code .Next
} else {
code = code .NextField
}
case encoder .OpStructFieldNumberPtrString :
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
b = appendStructKey (ctx , code , b )
if p == nil {
b = appendNull (ctx , b )
} else {
b = append (b , '"' )
bb , err := appendNumberString (ctx , b , ptrToNumber (p ))
if err != nil {
return b , err
}
b = append (bb , '"' )
}
b = appendComma (ctx , b )
code = code .Next
case encoder .OpStructFieldOmitEmptyNumberPtrString :
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
if p != nil {
b = appendStructKey (ctx , code , b )
b = append (b , '"' )
bb , err := appendNumberString (ctx , b , ptrToNumber (p ))
if err != nil {
return b , err
}
b = append (bb , '"' )
b = appendComma (ctx , b )
code = code .Next
} else {
code = code .NextField
}
case encoder .OpStructFieldMarshalJSON :
p := load (ctxptr , code .Idx )
b = appendStructKey (ctx , code , b )
p = unsafe .Add (p , code .Offset )
if (code .Flags & encoder .IsNilableTypeFlags ) != 0 {
p = ptrToPtr (p )
}
if p == nil && (code .Flags &encoder .NilCheckFlags ) != 0 {
b = appendNull (ctx , b )
} else {
bb , err := appendMarshalJSON (ctx , code , b , p )
if err != nil {
return b , err
}
b = bb
}
b = appendComma (ctx , b )
code = code .Next
case encoder .OpStructFieldOmitEmptyMarshalJSON :
p := load (ctxptr , code .Idx )
p = unsafe .Add (p , code .Offset )
if encoder .IsEmptyField (code .EmptyKind , code .NumBitSize , p ) {
code = code .NextField
break
}
if (code .Flags & encoder .IsNilableTypeFlags ) != 0 {
p = ptrToPtr (p )
}
b = appendStructKey (ctx , code , b )
bb , err := appendMarshalJSON (ctx , code , b , p )
if err != nil {
return b , err
}
b = appendComma (ctx , bb )
code = code .Next
case encoder .OpStructFieldMarshalJSONPtr :
p := load (ctxptr , code .Idx )
b = appendStructKey (ctx , code , b )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
if p == nil {
b = appendNull (ctx , b )
} else {
bb , err := appendMarshalJSON (ctx , code , b , p )
if err != nil {
return b , err
}
b = bb
}
b = appendComma (ctx , b )
code = code .Next
case encoder .OpStructFieldOmitEmptyMarshalJSONPtr :
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
if p != nil {
b = appendStructKey (ctx , code , b )
bb , err := appendMarshalJSON (ctx , code , b , p )
if err != nil {
return b , err
}
b = appendComma (ctx , bb )
code = code .Next
} else {
code = code .NextField
}
case encoder .OpStructFieldMarshalText :
p := load (ctxptr , code .Idx )
b = appendStructKey (ctx , code , b )
p = unsafe .Add (p , code .Offset )
if (code .Flags & encoder .IsNilableTypeFlags ) != 0 {
p = ptrToPtr (p )
}
if p == nil && (code .Flags &encoder .NilCheckFlags ) != 0 {
b = appendNull (ctx , b )
} else {
bb , err := appendMarshalText (ctx , code , b , p )
if err != nil {
return b , err
}
b = bb
}
b = appendComma (ctx , b )
code = code .Next
case encoder .OpStructFieldOmitEmptyMarshalText :
p := load (ctxptr , code .Idx )
p = unsafe .Add (p , code .Offset )
if encoder .IsEmptyField (code .EmptyKind , code .NumBitSize , p ) {
code = code .NextField
break
}
if (code .Flags & encoder .IsNilableTypeFlags ) != 0 {
p = ptrToPtr (p )
}
b = appendStructKey (ctx , code , b )
bb , err := appendMarshalText (ctx , code , b , p )
if err != nil {
return b , err
}
b = appendComma (ctx , bb )
code = code .Next
case encoder .OpStructFieldMarshalTextPtr :
p := load (ctxptr , code .Idx )
b = appendStructKey (ctx , code , b )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
if p == nil {
b = appendNull (ctx , b )
} else {
bb , err := appendMarshalText (ctx , code , b , p )
if err != nil {
return b , err
}
b = bb
}
b = appendComma (ctx , b )
code = code .Next
case encoder .OpStructFieldOmitEmptyMarshalTextPtr :
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
if p != nil {
b = appendStructKey (ctx , code , b )
bb , err := appendMarshalText (ctx , code , b , p )
if err != nil {
return b , err
}
b = appendComma (ctx , bb )
code = code .Next
} else {
code = code .NextField
}
case encoder .OpStructFieldArray :
b = appendStructKey (ctx , code , b )
p := load (ctxptr , code .Idx )
p = unsafe .Add (p , code .Offset )
code = code .Next
store (ctxptr , code .Idx , p )
case encoder .OpStructFieldOmitEmptyArray :
b = appendStructKey (ctx , code , b )
p := load (ctxptr , code .Idx )
p = unsafe .Add (p , code .Offset )
code = code .Next
store (ctxptr , code .Idx , p )
case encoder .OpStructFieldArrayPtr :
b = appendStructKey (ctx , code , b )
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
code = code .Next
store (ctxptr , code .Idx , p )
case encoder .OpStructFieldOmitEmptyArrayPtr :
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
if p != nil {
b = appendStructKey (ctx , code , b )
code = code .Next
store (ctxptr , code .Idx , p )
} else {
code = code .NextField
}
case encoder .OpStructFieldSlice :
b = appendStructKey (ctx , code , b )
p := load (ctxptr , code .Idx )
p = unsafe .Add (p , code .Offset )
code = code .Next
store (ctxptr , code .Idx , p )
case encoder .OpStructFieldOmitEmptySlice :
p := load (ctxptr , code .Idx )
p = unsafe .Add (p , code .Offset )
slice := ptrToSlice (p )
if slice .Len == 0 {
code = code .NextField
} else {
b = appendStructKey (ctx , code , b )
code = code .Next
store (ctxptr , code .Idx , p )
}
case encoder .OpStructFieldSlicePtr :
b = appendStructKey (ctx , code , b )
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
code = code .Next
store (ctxptr , code .Idx , p )
case encoder .OpStructFieldOmitEmptySlicePtr :
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
if p != nil {
b = appendStructKey (ctx , code , b )
code = code .Next
store (ctxptr , code .Idx , p )
} else {
code = code .NextField
}
case encoder .OpStructFieldMap :
b = appendStructKey (ctx , code , b )
p := load (ctxptr , code .Idx )
p = ptrToPtr (unsafe .Add (p , code .Offset ))
code = code .Next
store (ctxptr , code .Idx , p )
case encoder .OpStructFieldOmitEmptyMap :
p := load (ctxptr , code .Idx )
p = ptrToPtr (unsafe .Add (p , code .Offset ))
if p == nil || encoder .MapLen (p ) == 0 {
code = code .NextField
} else {
b = appendStructKey (ctx , code , b )
code = code .Next
store (ctxptr , code .Idx , p )
}
case encoder .OpStructFieldMapPtr :
b = appendStructKey (ctx , code , b )
p := load (ctxptr , code .Idx )
p = ptrToPtr (unsafe .Add (p , code .Offset ))
if p != nil {
p = ptrToNPtr (p , code .PtrNum )
}
code = code .Next
store (ctxptr , code .Idx , p )
case encoder .OpStructEnd :
b = appendStructEndSkipLast (ctx , code , b )
code = code .Next
case encoder .OpStructEndInt :
p := load (ctxptr , code .Idx )
b = appendStructKey (ctx , code , b )
b = encoder .AppendInt (ctx , b , unsafe .Add (p , code .Offset ), code )
b = appendStructEnd (ctx , code , b )
code = code .Next
case encoder .OpStructEndOmitEmptyInt :
p := load (ctxptr , code .Idx )
u64 := ptrToUint64 (unsafe .Add (p , code .Offset ), code .NumBitSize )
v := u64 & ((1 << code .NumBitSize ) - 1 )
if v != 0 {
b = appendStructKey (ctx , code , b )
b = encoder .AppendInt (ctx , b , unsafe .Add (p , code .Offset ), code )
b = appendStructEnd (ctx , code , b )
} else {
b = appendStructEndSkipLast (ctx , code , b )
}
code = code .Next
case encoder .OpStructEndIntString :
p := load (ctxptr , code .Idx )
b = appendStructKey (ctx , code , b )
b = append (b , '"' )
b = encoder .AppendInt (ctx , b , unsafe .Add (p , code .Offset ), code )
b = append (b , '"' )
b = appendStructEnd (ctx , code , b )
code = code .Next
case encoder .OpStructEndOmitEmptyIntString :
p := load (ctxptr , code .Idx )
u64 := ptrToUint64 (unsafe .Add (p , code .Offset ), code .NumBitSize )
v := u64 & ((1 << code .NumBitSize ) - 1 )
if v != 0 {
b = appendStructKey (ctx , code , b )
b = append (b , '"' )
b = encoder .AppendInt (ctx , b , unsafe .Add (p , code .Offset ), code )
b = append (b , '"' )
b = appendStructEnd (ctx , code , b )
} else {
b = appendStructEndSkipLast (ctx , code , b )
}
code = code .Next
case encoder .OpStructEndIntPtr :
b = appendStructKey (ctx , code , b )
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
if p == nil {
b = appendNull (ctx , b )
} else {
b = encoder .AppendInt (ctx , b , p , code )
}
b = appendStructEnd (ctx , code , b )
code = code .Next
case encoder .OpStructEndOmitEmptyIntPtr :
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
if p != nil {
b = appendStructKey (ctx , code , b )
b = encoder .AppendInt (ctx , b , p , code )
b = appendStructEnd (ctx , code , b )
} else {
b = appendStructEndSkipLast (ctx , code , b )
}
code = code .Next
case encoder .OpStructEndIntPtrString :
b = appendStructKey (ctx , code , b )
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
if p == nil {
b = appendNull (ctx , b )
} else {
b = append (b , '"' )
b = encoder .AppendInt (ctx , b , p , code )
b = append (b , '"' )
}
b = appendStructEnd (ctx , code , b )
code = code .Next
case encoder .OpStructEndOmitEmptyIntPtrString :
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
if p != nil {
b = appendStructKey (ctx , code , b )
b = append (b , '"' )
b = encoder .AppendInt (ctx , b , p , code )
b = append (b , '"' )
b = appendStructEnd (ctx , code , b )
} else {
b = appendStructEndSkipLast (ctx , code , b )
}
code = code .Next
case encoder .OpStructEndUint :
p := load (ctxptr , code .Idx )
b = appendStructKey (ctx , code , b )
b = encoder .AppendUint (ctx , b , unsafe .Add (p , code .Offset ), code )
b = appendStructEnd (ctx , code , b )
code = code .Next
case encoder .OpStructEndOmitEmptyUint :
p := load (ctxptr , code .Idx )
u64 := ptrToUint64 (unsafe .Add (p , code .Offset ), code .NumBitSize )
v := u64 & ((1 << code .NumBitSize ) - 1 )
if v != 0 {
b = appendStructKey (ctx , code , b )
b = encoder .AppendUint (ctx , b , unsafe .Add (p , code .Offset ), code )
b = appendStructEnd (ctx , code , b )
} else {
b = appendStructEndSkipLast (ctx , code , b )
}
code = code .Next
case encoder .OpStructEndUintString :
p := load (ctxptr , code .Idx )
b = appendStructKey (ctx , code , b )
b = append (b , '"' )
b = encoder .AppendUint (ctx , b , unsafe .Add (p , code .Offset ), code )
b = append (b , '"' )
b = appendStructEnd (ctx , code , b )
code = code .Next
case encoder .OpStructEndOmitEmptyUintString :
p := load (ctxptr , code .Idx )
u64 := ptrToUint64 (unsafe .Add (p , code .Offset ), code .NumBitSize )
v := u64 & ((1 << code .NumBitSize ) - 1 )
if v != 0 {
b = appendStructKey (ctx , code , b )
b = append (b , '"' )
b = encoder .AppendUint (ctx , b , unsafe .Add (p , code .Offset ), code )
b = append (b , '"' )
b = appendStructEnd (ctx , code , b )
} else {
b = appendStructEndSkipLast (ctx , code , b )
}
code = code .Next
case encoder .OpStructEndUintPtr :
b = appendStructKey (ctx , code , b )
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
if p == nil {
b = appendNull (ctx , b )
} else {
b = encoder .AppendUint (ctx , b , p , code )
}
b = appendStructEnd (ctx , code , b )
code = code .Next
case encoder .OpStructEndOmitEmptyUintPtr :
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
if p != nil {
b = appendStructKey (ctx , code , b )
b = encoder .AppendUint (ctx , b , p , code )
b = appendStructEnd (ctx , code , b )
} else {
b = appendStructEndSkipLast (ctx , code , b )
}
code = code .Next
case encoder .OpStructEndUintPtrString :
b = appendStructKey (ctx , code , b )
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
if p == nil {
b = appendNull (ctx , b )
} else {
b = append (b , '"' )
b = encoder .AppendUint (ctx , b , p , code )
b = append (b , '"' )
}
b = appendStructEnd (ctx , code , b )
code = code .Next
case encoder .OpStructEndOmitEmptyUintPtrString :
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
if p != nil {
b = appendStructKey (ctx , code , b )
b = append (b , '"' )
b = encoder .AppendUint (ctx , b , p , code )
b = append (b , '"' )
b = appendStructEnd (ctx , code , b )
} else {
b = appendStructEndSkipLast (ctx , code , b )
}
code = code .Next
case encoder .OpStructEndFloat32 :
p := load (ctxptr , code .Idx )
b = appendStructKey (ctx , code , b )
bb , err := appendFloat32 (ctx , code , b , ptrToFloat32 (unsafe .Add (p , code .Offset )))
if err != nil {
return b , err
}
b = bb
b = appendStructEnd (ctx , code , b )
code = code .Next
case encoder .OpStructEndOmitEmptyFloat32 :
p := load (ctxptr , code .Idx )
v := ptrToFloat32 (unsafe .Add (p , code .Offset ))
if v != 0 {
b = appendStructKey (ctx , code , b )
bb , err := appendFloat32 (ctx , code , b , v )
if err != nil {
return b , err
}
b = bb
b = appendStructEnd (ctx , code , b )
} else {
b = appendStructEndSkipLast (ctx , code , b )
}
code = code .Next
case encoder .OpStructEndFloat32String :
p := load (ctxptr , code .Idx )
b = appendStructKey (ctx , code , b )
b = append (b , '"' )
bb , err := appendFloat32 (ctx , code , b , ptrToFloat32 (unsafe .Add (p , code .Offset )))
if err != nil {
return b , err
}
b = bb
b = append (b , '"' )
b = appendStructEnd (ctx , code , b )
code = code .Next
case encoder .OpStructEndOmitEmptyFloat32String :
p := load (ctxptr , code .Idx )
v := ptrToFloat32 (unsafe .Add (p , code .Offset ))
if v != 0 {
b = appendStructKey (ctx , code , b )
b = append (b , '"' )
bb , err := appendFloat32 (ctx , code , b , v )
if err != nil {
return b , err
}
b = bb
b = append (b , '"' )
b = appendStructEnd (ctx , code , b )
} else {
b = appendStructEndSkipLast (ctx , code , b )
}
code = code .Next
case encoder .OpStructEndFloat32Ptr :
b = appendStructKey (ctx , code , b )
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
if p == nil {
b = appendNull (ctx , b )
} else {
bb , err := appendFloat32 (ctx , code , b , ptrToFloat32 (p ))
if err != nil {
return b , err
}
b = bb
}
b = appendStructEnd (ctx , code , b )
code = code .Next
case encoder .OpStructEndOmitEmptyFloat32Ptr :
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
if p != nil {
b = appendStructKey (ctx , code , b )
bb , err := appendFloat32 (ctx , code , b , ptrToFloat32 (p ))
if err != nil {
return b , err
}
b = bb
b = appendStructEnd (ctx , code , b )
} else {
b = appendStructEndSkipLast (ctx , code , b )
}
code = code .Next
case encoder .OpStructEndFloat32PtrString :
b = appendStructKey (ctx , code , b )
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
if p == nil {
b = appendNull (ctx , b )
} else {
b = append (b , '"' )
bb , err := appendFloat32 (ctx , code , b , ptrToFloat32 (p ))
if err != nil {
return b , err
}
b = bb
b = append (b , '"' )
}
b = appendStructEnd (ctx , code , b )
code = code .Next
case encoder .OpStructEndOmitEmptyFloat32PtrString :
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
if p != nil {
b = appendStructKey (ctx , code , b )
b = append (b , '"' )
bb , err := appendFloat32 (ctx , code , b , ptrToFloat32 (p ))
if err != nil {
return b , err
}
b = bb
b = append (b , '"' )
b = appendStructEnd (ctx , code , b )
} else {
b = appendStructEndSkipLast (ctx , code , b )
}
code = code .Next
case encoder .OpStructEndFloat64 :
p := load (ctxptr , code .Idx )
v := ptrToFloat64 (unsafe .Add (p , code .Offset ))
if isInfOrNaN (v ) {
return b , errUnsupportedFloat (ctx , code , v )
}
b = appendStructKey (ctx , code , b )
b = encoder .AppendFloat64 (ctx , b , v )
b = appendStructEnd (ctx , code , b )
code = code .Next
case encoder .OpStructEndOmitEmptyFloat64 :
p := load (ctxptr , code .Idx )
v := ptrToFloat64 (unsafe .Add (p , code .Offset ))
if v != 0 {
if isInfOrNaN (v ) {
return b , errUnsupportedFloat (ctx , code , v )
}
b = appendStructKey (ctx , code , b )
b = encoder .AppendFloat64 (ctx , b , v )
b = appendStructEnd (ctx , code , b )
} else {
b = appendStructEndSkipLast (ctx , code , b )
}
code = code .Next
case encoder .OpStructEndFloat64String :
p := load (ctxptr , code .Idx )
v := ptrToFloat64 (unsafe .Add (p , code .Offset ))
if isInfOrNaN (v ) {
return b , errUnsupportedFloat (ctx , code , v )
}
b = appendStructKey (ctx , code , b )
b = append (b , '"' )
b = encoder .AppendFloat64 (ctx , b , v )
b = append (b , '"' )
b = appendStructEnd (ctx , code , b )
code = code .Next
case encoder .OpStructEndOmitEmptyFloat64String :
p := load (ctxptr , code .Idx )
v := ptrToFloat64 (unsafe .Add (p , code .Offset ))
if v != 0 {
if isInfOrNaN (v ) {
return b , errUnsupportedFloat (ctx , code , v )
}
b = appendStructKey (ctx , code , b )
b = append (b , '"' )
b = encoder .AppendFloat64 (ctx , b , v )
b = append (b , '"' )
b = appendStructEnd (ctx , code , b )
} else {
b = appendStructEndSkipLast (ctx , code , b )
}
code = code .Next
case encoder .OpStructEndFloat64Ptr :
b = appendStructKey (ctx , code , b )
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
if p == nil {
b = appendNull (ctx , b )
b = appendStructEnd (ctx , code , b )
code = code .Next
break
}
v := ptrToFloat64 (p )
if isInfOrNaN (v ) {
return b , errUnsupportedFloat (ctx , code , v )
}
b = encoder .AppendFloat64 (ctx , b , v )
b = appendStructEnd (ctx , code , b )
code = code .Next
case encoder .OpStructEndOmitEmptyFloat64Ptr :
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
if p != nil {
b = appendStructKey (ctx , code , b )
v := ptrToFloat64 (p )
if isInfOrNaN (v ) {
return b , errUnsupportedFloat (ctx , code , v )
}
b = encoder .AppendFloat64 (ctx , b , v )
b = appendStructEnd (ctx , code , b )
} else {
b = appendStructEndSkipLast (ctx , code , b )
}
code = code .Next
case encoder .OpStructEndFloat64PtrString :
b = appendStructKey (ctx , code , b )
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
if p == nil {
b = appendNull (ctx , b )
} else {
b = append (b , '"' )
v := ptrToFloat64 (p )
if isInfOrNaN (v ) {
return b , errUnsupportedFloat (ctx , code , v )
}
b = encoder .AppendFloat64 (ctx , b , v )
b = append (b , '"' )
}
b = appendStructEnd (ctx , code , b )
code = code .Next
case encoder .OpStructEndOmitEmptyFloat64PtrString :
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
if p != nil {
b = appendStructKey (ctx , code , b )
v := ptrToFloat64 (p )
if isInfOrNaN (v ) {
return b , errUnsupportedFloat (ctx , code , v )
}
b = append (b , '"' )
b = encoder .AppendFloat64 (ctx , b , v )
b = append (b , '"' )
b = appendStructEnd (ctx , code , b )
} else {
b = appendStructEndSkipLast (ctx , code , b )
}
code = code .Next
case encoder .OpStructEndString :
p := load (ctxptr , code .Idx )
b = appendStructKey (ctx , code , b )
b , _ = jsonstring .AppendQuoted (encoder .StringEscaper (ctx ), b , ptrToString (unsafe .Add (p , code .Offset )))
b = appendStructEnd (ctx , code , b )
code = code .Next
case encoder .OpStructEndOmitEmptyString :
p := load (ctxptr , code .Idx )
v := ptrToString (unsafe .Add (p , code .Offset ))
if v != "" {
b = appendStructKey (ctx , code , b )
b , _ = jsonstring .AppendQuoted (encoder .StringEscaper (ctx ), b , v )
b = appendStructEnd (ctx , code , b )
} else {
b = appendStructEndSkipLast (ctx , code , b )
}
code = code .Next
case encoder .OpStructEndStringString :
p := load (ctxptr , code .Idx )
b = appendStructKey (ctx , code , b )
s := ptrToString (unsafe .Add (p , code .Offset ))
quoted , _ := jsonstring .AppendQuoted (encoder .StringEscaper (ctx ), []byte {}, s )
b , _ = jsonstring .AppendQuoted (encoder .StringEscaper (ctx ), b , string (quoted ))
b = appendStructEnd (ctx , code , b )
code = code .Next
case encoder .OpStructEndOmitEmptyStringString :
p := load (ctxptr , code .Idx )
v := ptrToString (unsafe .Add (p , code .Offset ))
if v != "" {
b = appendStructKey (ctx , code , b )
quoted , _ := jsonstring .AppendQuoted (encoder .StringEscaper (ctx ), []byte {}, v )
b , _ = jsonstring .AppendQuoted (encoder .StringEscaper (ctx ), b , string (quoted ))
b = appendStructEnd (ctx , code , b )
} else {
b = appendStructEndSkipLast (ctx , code , b )
}
code = code .Next
case encoder .OpStructEndStringPtr :
b = appendStructKey (ctx , code , b )
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
if p == nil {
b = appendNull (ctx , b )
} else {
b , _ = jsonstring .AppendQuoted (encoder .StringEscaper (ctx ), b , ptrToString (p ))
}
b = appendStructEnd (ctx , code , b )
code = code .Next
case encoder .OpStructEndOmitEmptyStringPtr :
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
if p != nil {
b = appendStructKey (ctx , code , b )
b , _ = jsonstring .AppendQuoted (encoder .StringEscaper (ctx ), b , ptrToString (p ))
b = appendStructEnd (ctx , code , b )
} else {
b = appendStructEndSkipLast (ctx , code , b )
}
code = code .Next
case encoder .OpStructEndStringPtrString :
b = appendStructKey (ctx , code , b )
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
if p == nil {
b = appendNull (ctx , b )
} else {
quoted , _ := jsonstring .AppendQuoted (encoder .StringEscaper (ctx ), []byte {}, ptrToString (p ))
b , _ = jsonstring .AppendQuoted (encoder .StringEscaper (ctx ), b , string (quoted ))
}
b = appendStructEnd (ctx , code , b )
code = code .Next
case encoder .OpStructEndOmitEmptyStringPtrString :
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
if p != nil {
b = appendStructKey (ctx , code , b )
quoted , _ := jsonstring .AppendQuoted (encoder .StringEscaper (ctx ), []byte {}, ptrToString (p ))
b , _ = jsonstring .AppendQuoted (encoder .StringEscaper (ctx ), b , string (quoted ))
b = appendStructEnd (ctx , code , b )
} else {
b = appendStructEndSkipLast (ctx , code , b )
}
code = code .Next
case encoder .OpStructEndBool :
p := load (ctxptr , code .Idx )
b = appendStructKey (ctx , code , b )
b = appendBool (ctx , b , ptrToBool (unsafe .Add (p , code .Offset )))
b = appendStructEnd (ctx , code , b )
code = code .Next
case encoder .OpStructEndOmitEmptyBool :
p := load (ctxptr , code .Idx )
v := ptrToBool (unsafe .Add (p , code .Offset ))
if v {
b = appendStructKey (ctx , code , b )
b = appendBool (ctx , b , v )
b = appendStructEnd (ctx , code , b )
} else {
b = appendStructEndSkipLast (ctx , code , b )
}
code = code .Next
case encoder .OpStructEndBoolString :
p := load (ctxptr , code .Idx )
b = appendStructKey (ctx , code , b )
b = append (b , '"' )
b = appendBool (ctx , b , ptrToBool (unsafe .Add (p , code .Offset )))
b = append (b , '"' )
b = appendStructEnd (ctx , code , b )
code = code .Next
case encoder .OpStructEndOmitEmptyBoolString :
p := load (ctxptr , code .Idx )
v := ptrToBool (unsafe .Add (p , code .Offset ))
if v {
b = appendStructKey (ctx , code , b )
b = append (b , '"' )
b = appendBool (ctx , b , v )
b = append (b , '"' )
b = appendStructEnd (ctx , code , b )
} else {
b = appendStructEndSkipLast (ctx , code , b )
}
code = code .Next
case encoder .OpStructEndBoolPtr :
b = appendStructKey (ctx , code , b )
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
if p == nil {
b = appendNull (ctx , b )
} else {
b = appendBool (ctx , b , ptrToBool (p ))
}
b = appendStructEnd (ctx , code , b )
code = code .Next
case encoder .OpStructEndOmitEmptyBoolPtr :
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
if p != nil {
b = appendStructKey (ctx , code , b )
b = appendBool (ctx , b , ptrToBool (p ))
b = appendStructEnd (ctx , code , b )
} else {
b = appendStructEndSkipLast (ctx , code , b )
}
code = code .Next
case encoder .OpStructEndBoolPtrString :
b = appendStructKey (ctx , code , b )
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
if p == nil {
b = appendNull (ctx , b )
} else {
b = append (b , '"' )
b = appendBool (ctx , b , ptrToBool (p ))
b = append (b , '"' )
}
b = appendStructEnd (ctx , code , b )
code = code .Next
case encoder .OpStructEndOmitEmptyBoolPtrString :
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
if p != nil {
b = appendStructKey (ctx , code , b )
b = append (b , '"' )
b = appendBool (ctx , b , ptrToBool (p ))
b = append (b , '"' )
b = appendStructEnd (ctx , code , b )
} else {
b = appendStructEndSkipLast (ctx , code , b )
}
code = code .Next
case encoder .OpStructEndBytes :
p := load (ctxptr , code .Idx )
b = appendStructKey (ctx , code , b )
b = encoder .AppendByteSlice (ctx , b , ptrToBytes (unsafe .Add (p , code .Offset )))
b = appendStructEnd (ctx , code , b )
code = code .Next
case encoder .OpStructEndOmitEmptyBytes :
p := load (ctxptr , code .Idx )
v := ptrToBytes (unsafe .Add (p , code .Offset ))
if len (v ) > 0 {
b = appendStructKey (ctx , code , b )
b = encoder .AppendByteSlice (ctx , b , v )
b = appendStructEnd (ctx , code , b )
} else {
b = appendStructEndSkipLast (ctx , code , b )
}
code = code .Next
case encoder .OpStructEndBytesPtr :
b = appendStructKey (ctx , code , b )
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
if p == nil {
b = appendNull (ctx , b )
} else {
b = encoder .AppendByteSlice (ctx , b , ptrToBytes (p ))
}
b = appendStructEnd (ctx , code , b )
code = code .Next
case encoder .OpStructEndOmitEmptyBytesPtr :
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
if p != nil {
b = appendStructKey (ctx , code , b )
b = encoder .AppendByteSlice (ctx , b , ptrToBytes (p ))
b = appendStructEnd (ctx , code , b )
} else {
b = appendStructEndSkipLast (ctx , code , b )
}
code = code .Next
case encoder .OpStructEndNumber :
p := load (ctxptr , code .Idx )
b = appendStructKey (ctx , code , b )
bb , err := encoder .AppendNumber (ctx , b , ptrToNumber (unsafe .Add (p , code .Offset )))
if err != nil {
return b , err
}
b = appendStructEnd (ctx , code , bb )
code = code .Next
case encoder .OpStructEndOmitEmptyNumber :
p := load (ctxptr , code .Idx )
v := ptrToNumber (unsafe .Add (p , code .Offset ))
if v != "" {
b = appendStructKey (ctx , code , b )
bb , err := encoder .AppendNumber (ctx , b , v )
if err != nil {
return b , err
}
b = appendStructEnd (ctx , code , bb )
} else {
b = appendStructEndSkipLast (ctx , code , b )
}
code = code .Next
case encoder .OpStructEndNumberString :
p := load (ctxptr , code .Idx )
b = appendStructKey (ctx , code , b )
b = append (b , '"' )
bb , err := appendNumberString (ctx , b , ptrToNumber (unsafe .Add (p , code .Offset )))
if err != nil {
return b , err
}
b = append (bb , '"' )
b = appendStructEnd (ctx , code , b )
code = code .Next
case encoder .OpStructEndOmitEmptyNumberString :
p := load (ctxptr , code .Idx )
v := ptrToNumber (unsafe .Add (p , code .Offset ))
if v != "" {
b = appendStructKey (ctx , code , b )
b = append (b , '"' )
bb , err := appendNumberString (ctx , b , v )
if err != nil {
return b , err
}
b = append (bb , '"' )
b = appendStructEnd (ctx , code , b )
} else {
b = appendStructEndSkipLast (ctx , code , b )
}
code = code .Next
case encoder .OpStructEndNumberPtr :
b = appendStructKey (ctx , code , b )
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
if p == nil {
b = appendNull (ctx , b )
} else {
bb , err := encoder .AppendNumber (ctx , b , ptrToNumber (p ))
if err != nil {
return b , err
}
b = bb
}
b = appendStructEnd (ctx , code , b )
code = code .Next
case encoder .OpStructEndOmitEmptyNumberPtr :
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
if p != nil {
b = appendStructKey (ctx , code , b )
bb , err := encoder .AppendNumber (ctx , b , ptrToNumber (p ))
if err != nil {
return b , err
}
b = appendStructEnd (ctx , code , bb )
} else {
b = appendStructEndSkipLast (ctx , code , b )
}
code = code .Next
case encoder .OpStructEndNumberPtrString :
b = appendStructKey (ctx , code , b )
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
if p == nil {
b = appendNull (ctx , b )
} else {
b = append (b , '"' )
bb , err := appendNumberString (ctx , b , ptrToNumber (p ))
if err != nil {
return b , err
}
b = append (bb , '"' )
}
b = appendStructEnd (ctx , code , b )
code = code .Next
case encoder .OpStructEndOmitEmptyNumberPtrString :
p := load (ctxptr , code .Idx )
p = ptrToNPtr (unsafe .Add (p , code .Offset ), code .PtrNum )
if p != nil {
b = appendStructKey (ctx , code , b )
b = append (b , '"' )
bb , err := appendNumberString (ctx , b , ptrToNumber (p ))
if err != nil {
return b , err
}
b = append (bb , '"' )
b = appendStructEnd (ctx , code , b )
} else {
b = appendStructEndSkipLast (ctx , code , b )
}
code = code .Next
case encoder .OpEnd :
goto END
}
}
END :
return b , nil
}
func appendMapAsRead(ctx *encoder .RuntimeContext , code *encoder .Opcode , b []byte , p unsafe .Pointer , mapCtx *encoder .MapContext ) ([]byte , error ) {
code .Map .Reset (mapCtx )
if code .Map .ScalarValue {
mapCtx .Len = 0
return mapScalarValueWriters [code .Map .ValueKind ](ctx , code , b , p )
}
for k , v := range *(*map [string ]any )(unsafe .Pointer (&p )) {
iface := (*emptyInterface )(unsafe .Pointer (&v ))
var scalar *encoder .Opcode
if iface .typ != nil && iface .ptr != nil {
codeSet := ctx .RecentCodeSet (uintptr (iface .typ ))
if codeSet == nil {
if ctx .Option .Flag &encoder .UncachedOption == 0 {
codeSet = ctx .SharedCodeSets ().LoadFirst (uintptr (iface .typ ))
}
if codeSet != nil {
ctx .RememberCodeSet (uintptr (iface .typ ), codeSet )
} else {
var err error
codeSet , err = encoder .CompileToGetCodeSet (ctx , uintptr (iface .typ ))
if err != nil {
return b , err
}
}
}
scalar = codeSet .Scalar
}
if iface .typ != nil && scalar == nil {
mapCtx .Keys = append (mapCtx .Keys , k )
mapCtx .Values = append (mapCtx .Values , unsafe .Slice ((*byte )(unsafe .Pointer (&v )), unsafe .Sizeof (v ))...)
continue
}
b = appendMapKey (ctx , code , b , k )
if scalar == nil {
b = appendNullComma (ctx , b )
continue
}
bb , err := appendScalar (ctx , b , scalar , iface .ptr )
if err != nil {
return b , err
}
b = bb
}
mapCtx .Len = len (mapCtx .Keys )
return b , nil
}
func appendSortedMapEntries(ctx *encoder .RuntimeContext , code *encoder .Opcode , b []byte , mapCtx *encoder .MapContext , idx int ) ([]byte , int , error ) {
scalarValue := mapCtx .ScalarValue ()
for ; idx < mapCtx .Len ; idx ++ {
i := int (mapCtx .Order [idx ])
p := mapCtx .ValueAt (i )
scalar := code .Next
if !scalarValue {
iface := (*emptyInterface )(p )
if iface .typ == nil {
b = appendMapKey (ctx , code , b , mapCtx .Keys [i ])
b = appendNullComma (ctx , b )
continue
}
if iface .ptr == nil {
return b , idx , nil
}
codeSet := ctx .RecentCodeSet (uintptr (iface .typ ))
if codeSet == nil {
if ctx .Option .Flag &encoder .UncachedOption == 0 {
codeSet = ctx .SharedCodeSets ().LoadFirst (uintptr (iface .typ ))
}
if codeSet != nil {
ctx .RememberCodeSet (uintptr (iface .typ ), codeSet )
} else {
var err error
codeSet , err = encoder .CompileToGetCodeSet (ctx , uintptr (iface .typ ))
if err != nil {
return b , 0 , err
}
}
}
if codeSet .Scalar == nil {
return b , idx , nil
}
scalar = codeSet .Scalar
p = iface .ptr
}
b = appendMapKey (ctx , code , b , mapCtx .Keys [i ])
bb , err := appendScalar (ctx , b , scalar , p )
if err != nil {
return b , 0 , err
}
b = bb
}
return b , idx , nil
}
func appendMapKey(ctx *encoder .RuntimeContext , code *encoder .Opcode , b []byte , k string ) []byte {
b = appendMapKeyIndent (ctx , code , b )
b , _ = jsonstring .AppendQuoted (encoder .StringEscaper (ctx ), b , k )
b = appendComma (ctx , b )
return appendColon (ctx , b )
}
func appendMapScalarValues[V any ](ctx *encoder .RuntimeContext , code *encoder .Opcode , b []byte , p unsafe .Pointer ) ([]byte , error ) {
value := code .Next
var (
k string
v V
)
for k , v = range *(*map [string ]V )(unsafe .Pointer (&p )) {
b = appendMapKey (ctx , code , b , k )
bb , err := appendScalar (ctx , b , value , unsafe .Pointer (&v ))
if err != nil {
return b , err
}
b = bb
}
return b , nil
}
var mapScalarValueWriters = [...]func (*encoder .RuntimeContext , *encoder .Opcode , []byte , unsafe .Pointer ) ([]byte , error ){
reflect .Bool : appendMapScalarValues [bool ],
reflect .Int : appendMapScalarValues [int ],
reflect .Int8 : appendMapScalarValues [int8 ],
reflect .Int16 : appendMapScalarValues [int16 ],
reflect .Int32 : appendMapScalarValues [int32 ],
reflect .Int64 : appendMapScalarValues [int64 ],
reflect .Uint : appendMapScalarValues [uint ],
reflect .Uint8 : appendMapScalarValues [uint8 ],
reflect .Uint16 : appendMapScalarValues [uint16 ],
reflect .Uint32 : appendMapScalarValues [uint32 ],
reflect .Uint64 : appendMapScalarValues [uint64 ],
reflect .Uintptr : appendMapScalarValues [uintptr ],
reflect .Float32 : appendMapScalarValues [float32 ],
reflect .Float64 : appendMapScalarValues [float64 ],
reflect .String : appendMapScalarValues [[2 ]uintptr ],
reflect .Slice : appendMapScalarValues [[3 ]uintptr ],
}
The pages are generated with Golds v0.8.7 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .