Source File
encode_embedded_json.go
Belonging Package
github.com/francoispqt/gojay
package gojay// EncodeEmbeddedJSON encodes an embedded JSON.// is basically sets the internal buf as the value pointed by v and calls the io.Writer.Write()func ( *Encoder) ( *EmbeddedJSON) error {if .isPooled == 1 {panic(InvalidUsagePooledEncoderError("Invalid usage of pooled encoder"))}.buf = *, := .Write()if != nil {return}return nil}func ( *Encoder) ( *EmbeddedJSON) ([]byte, error) {.writeBytes(*)return .buf, nil}// AddEmbeddedJSON adds an EmbeddedJSON to be encoded.//// It basically blindly writes the bytes to the final buffer. Therefore,// it expects the JSON to be of proper format.func ( *Encoder) ( *EmbeddedJSON) {.grow(len(*) + 4):= .getPreviousRune()if != '[' {.writeByte(',')}.writeBytes(*)}// AddEmbeddedJSONOmitEmpty adds an EmbeddedJSON to be encoded or skips it if nil pointer or empty.//// It basically blindly writes the bytes to the final buffer. Therefore,// it expects the JSON to be of proper format.func ( *Encoder) ( *EmbeddedJSON) {if == nil || len(*) == 0 {return}:= .getPreviousRune()if != '[' {.writeByte(',')}.writeBytes(*)}// AddEmbeddedJSONKey adds an EmbeddedJSON and a key to be encoded.//// It basically blindly writes the bytes to the final buffer. Therefore,// it expects the JSON to be of proper format.func ( *Encoder) ( string, *EmbeddedJSON) {if .hasKeys {if !.keyExists() {return}}.grow(len() + len(*) + 5):= .getPreviousRune()if != '{' {.writeByte(',')}.writeByte('"').writeStringEscape().writeBytes(objKey).writeBytes(*)}// AddEmbeddedJSONKeyOmitEmpty adds an EmbeddedJSON and a key to be encoded or skips it if nil pointer or empty.//// It basically blindly writes the bytes to the final buffer. Therefore,// it expects the JSON to be of proper format.func ( *Encoder) ( string, *EmbeddedJSON) {if .hasKeys {if !.keyExists() {return}}if == nil || len(*) == 0 {return}.grow(len() + len(*) + 5):= .getPreviousRune()if != '{' {.writeByte(',')}.writeByte('"').writeStringEscape().writeBytes(objKey).writeBytes(*)}
![]() |
The pages are generated with Golds v0.8.2. (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. |