Source File
unwrite_empty_v2.go
Belonging Package
github.com/goccy/go-json/internal/encoder
package encoder// The opcode after the value of a member of omitempty ( OpUnwriteEmpty ) unwrites the member if the value is empty,// for the semantics of encoding/json/v2, which omit a member by what its value writes. The output is compact, a// value followed by a comma.// newUnwriteEmptyCode returns the opcode after the value of a member of omitempty, whose key is key, which// unwrites the member if the value is empty ( see UnwriteEmptyMember ).func newUnwriteEmptyCode( *compileContext, string) *Opcode {:= &Opcode{Op: OpUnwriteEmpty,Idx: opcodeOffset(.ptrIndex),Key: ,DisplayIdx: .opcodeIndex,Indent: .indent,}.incOpcodeIndex()return}// UnwriteEmptyMember unwrites the member which ends the output b, whose key has keyLen bytes, if its value is// empty, as the v2 semantics define it: null, "", {} or []. The opcode runs only right after the opcodes of its// field wrote the member, the key followed by the value and a comma: a field which is omitted goes to NextField,// past the opcode, so the member starts keyLen bytes before its value.//// The value is empty if it is one of them right after the colon of the key: a longer value can end with the bytes// of one, as "\"" ends with "", but doesn't start there.func ( *RuntimeContext, []byte, int) []byte {:= len() - 1 // the comma:= 2if < {return}switch [-1] {case '"':if [-2] != '"' {return}case '}':if [-2] != '{' {return}case ']':if [-2] != '[' {return}case 'l':= 4if < || string([-:]) != "null" {return}default:return}if --1 < 0 || [--1] != ':' {return}:= - -if < 0 {return}.Rewrote()return [:]}
![]() |
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. |