jx
packagemoduleThis package is not in the latest version of its module.
Details
Validgo.mod file
The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.
Redistributable license
Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.
Tagged version
Modules with tagged versions give importers more predictable builds.
Stable version
When a project reaches major version v1 it is considered stable.
- Learn more about best practices
Repository
Links
README¶
jx


Package jx implements encoding and decoding of json [RFC 7159].Lightweight fork ofjsoniter.
go get github.com/go-faster/jxFeatures
- Mostly zero-allocation and highly optimized
- Directly encode and decode json values
- No reflect or
interface{} - Pools and direct buffer access for less (or none) allocations
- Multi-pass decoding
- Validation
Seeusage for examples. Mostly suitable for fast low-level json manipulationwith high control, for dynamic parsing and encoding of unstructured data. Used inogen project forjson (un)marshaling code generation based on json and OpenAPI schemas.
For example, we have following OpenTelemetry log entry:
{ "Timestamp": "1586960586000000000", "Attributes": { "http.status_code": 500, "http.url": "http://example.com", "my.custom.application.tag": "hello" }, "Resource": { "service.name": "donut_shop", "service.version": "2.0.0", "k8s.pod.uid": "1138528c-c36e-11e9-a1a7-42010a800198" }, "TraceId": "13e2a0921288b3ff80df0a0482d4fc46", "SpanId": "43222c2d51a7abe3", "SeverityText": "INFO", "SeverityNumber": 9, "Body": "20200415T072306-0700 INFO I like donuts"}Flexibility ofjx enables highly efficient semantic-aware encoding and decoding,e.g. using[16]byte forTraceId with zero-allocationhex encoding in json:
| Name | Speed | Allocations |
|---|---|---|
| Decode | 1279 MB/s | 0 allocs/op |
| Validate | 1914 MB/s | 0 allocs/op |
| Encode | 1202 MB/s | 0 allocs/op |
| Write | 2055 MB/s | 0 allocs/op |
cpu: AMD Ryzen 9 7950X
Seeotel_test.go for example.
Why
Most ofjsoniter issues are caused by necessityto be drop-in replacement for standardencoding/json. Removing such constrains greatlysimplified implementation and reduced scope, allowing to focus on json stream processing.
- Commas are handled automatically while encoding
- Raw json, Number and Base64 support
- Reduced scope
- No reflection
- No
encoding/jsonadapter - 3.5x less code (8.5K to 2.4K SLOC)
- Fuzzing, improved test coverage
- Drastically refactored and simplified
- Explicit error returns
- No
ConfigorAPI
Usage
Decode
Usejx.Decoder. Zero value is valid,but constructors are available for convenience:
- jx.Decode(reader io.Reader, bufSize int) for
io.Reader - jx.DecodeBytes([]byte) for byte slices
- jx.DecodeStr(string) for strings
To reuse decoders and their buffers, usejx.GetDecoderandjx.PutDecoder alongside with reset functions:
- jx.Decoder.Reset(io.Reader) to reset to new
io.Reader - jx.Decoder.ResetBytes([]byte) to decode another byte slice
Decoder is reset onPutDecoder.
d := jx.DecodeStr(`{"values":[4,8,15,16,23,42]}`)// Save all integers from "values" array to slice.var values []int// Iterate over each object field.if err := d.Obj(func(d *jx.Decoder, key string) error { switch key { case "values": // Iterate over each array element. return d.Arr(func(d *jx.Decoder) error { v, err := d.Int() if err != nil { return err } values = append(values, v) return nil }) default: // Skip unknown fields if any. return d.Skip() }}); err != nil { panic(err)}fmt.Println(values)// Output: [4 8 15 16 23 42]Encode
Usejx.Encoder. Zero value is valid, reuse withjx.GetEncoder,jx.PutEncoder andjx.Encoder.Reset(). Encoder is reset onPutEncoder.
var e jx.Encodere.ObjStart() // {e.FieldStart("values") // "values":e.ArrStart() // [for _, v := range []int{4, 8, 15, 16, 23, 42} { e.Int(v)}e.ArrEnd() // ]e.ObjEnd() // }fmt.Println(e)fmt.Println("Buffer len:", len(e.Bytes()))// Output: {"values":[4,8,15,16,23,42]}// Buffer len: 28Writer
Usejx.Writer for low level json writing.
No automatic commas or indentation for lowest possible overhead, useful for code generated json encoding.
Raw
Usejx.Decoder.Raw to read raw json values, similar tojson.RawMessage.
d := jx.DecodeStr(`{"foo": [1, 2, 3]}`)var raw jx.Rawif err := d.Obj(func(d *jx.Decoder, key string) error { v, err := d.Raw() if err != nil { return err } raw = v return nil}); err != nil { panic(err)}fmt.Println(raw.Type(), raw)// Output:// array [1, 2, 3]Number
Usejx.Decoder.Num to read numbers, similar tojson.Number.Also supports number strings, like"12345", which is common compatible way to representuint64.
d := jx.DecodeStr(`{"foo": "10531.0"}`)var n jx.Numif err := d.Obj(func(d *jx.Decoder, key string) error { v, err := d.Num() if err != nil { return err } n = v return nil}); err != nil { panic(err)}fmt.Println(n)fmt.Println("positive:", n.Positive())// Can decode floats with zero fractional part as integers:v, err := n.Int64()if err != nil { panic(err)}fmt.Println("int64:", v)// Output:// "10531.0"// positive: true// int64: 10531Base64
Usejx.Encoder.Base64 andjx.Decoder.Base64 orjx.Decoder.Base64Append.
Same as encoding/json, base64.StdEncoding or [RFC 4648].
var e jx.Encodere.Base64([]byte("Hello"))fmt.Println(e)data, _ := jx.DecodeBytes(e.Bytes()).Base64()fmt.Printf("%s", data)// Output:// "SGVsbG8="// HelloValidate
Check that byte slice is valid json withjx.Valid:
fmt.Println(jx.Valid([]byte(`{"field": "value"}`))) // truefmt.Println(jx.Valid([]byte(`"Hello, world!"`))) // truefmt.Println(jx.Valid([]byte(`["foo"}`))) // falseCapture
Thejx.Decoder.Capture method allows to unread everything is read in callback.Useful for multi-pass parsing:
d := jx.DecodeStr(`["foo", "bar", "baz"]`)var elems int// NB: Currently Capture does not support io.Reader, only buffers.if err := d.Capture(func(d *jx.Decoder) error {// Everything decoded in this callback will be rolled back.return d.Arr(func(d *jx.Decoder) error {elems++return d.Skip()})}); err != nil {panic(err)}// Decoder is rolled back to state before "Capture" call.fmt.Println("Read", elems, "elements on first pass")fmt.Println("Next element is", d.Next(), "again")// Output:// Read 3 elements on first pass// Next element is array againObjBytes
TheDecoder.ObjBytes method tries not to allocate memory for keys, reusing existing buffer.
d := DecodeStr(`{"id":1,"randomNumber":10}`)d.ObjBytes(func(d *Decoder, key []byte) error { switch string(key) { case "id": case "randomNumber": } return d.Skip()})Roadmap
- Rework and export
Any - Support
Rawfor io.Reader - Support
Capturefor io.Reader - Improve Num
- Better validation on decoding
- Support BigFloat and BigInt
- Support equivalence check, like
eq(1.0, 1) == true
- Add non-callback decoding of objects
Non-goals
- Code generation for decoding or encoding
- Replacement for
encoding/json - Reflection or
interface{}based encoding or decoding - Support for json path or similar
This package should be kept as simple as possible and be used aslow-level foundation for high-level projects like code generator.
License
MIT, same as jsoniter
Documentation¶
Overview¶
Package jx implementsRFC 7159 json encoding and decoding.
Example¶
package mainimport ("fmt""github.com/go-faster/jx")func main() {var e jx.Encodere.Obj(func(e *jx.Encoder) {e.FieldStart("data")e.Base64([]byte("hello"))})fmt.Println(e)if err := jx.DecodeBytes(e.Bytes()).Obj(func(d *jx.Decoder, key string) error {v, err := d.Base64()fmt.Printf("%s: %s\n", key, v)return err}); err != nil {panic(err)}}Output:{"data":"aGVsbG8="}data: hello
Index¶
- func PutDecoder(d *Decoder)
- func PutEncoder(e *Encoder)
- func PutWriter(e *Writer)
- func Valid(data []byte) bool
- type ArrIter
- type Decoder
- func (d *Decoder) Arr(f func(d *Decoder) error) error
- func (d *Decoder) ArrIter() (ArrIter, error)
- func (d *Decoder) Base64() ([]byte, error)
- func (d *Decoder) Base64Append(b []byte) ([]byte, error)
- func (d *Decoder) BigFloat() (*big.Float, error)
- func (d *Decoder) BigInt() (*big.Int, error)
- func (d *Decoder) Bool() (bool, error)
- func (d *Decoder) Capture(f func(d *Decoder) error) error
- func (d *Decoder) Elem() (ok bool, err error)
- func (d *Decoder) Float32() (float32, error)
- func (d *Decoder) Float64() (float64, error)
- func (d *Decoder) Int() (int, error)
- func (d *Decoder) Int16() (int16, error)
- func (d *Decoder) Int32() (int32, error)
- func (d *Decoder) Int64() (int64, error)
- func (d *Decoder) Int8() (int8, error)
- func (d *Decoder) Next() Type
- func (d *Decoder) Null() error
- func (d *Decoder) Num() (Num, error)
- func (d *Decoder) NumAppend(v Num) (Num, error)
- func (d *Decoder) Obj(f func(d *Decoder, key string) error) error
- func (d *Decoder) ObjBytes(f func(d *Decoder, key []byte) error) error
- func (d *Decoder) ObjIter() (ObjIter, error)
- func (d *Decoder) Raw() (Raw, error)
- func (d *Decoder) RawAppend(buf Raw) (Raw, error)
- func (d *Decoder) Reset(reader io.Reader)
- func (d *Decoder) ResetBytes(input []byte)
- func (d *Decoder) Skip() error
- func (d *Decoder) Str() (string, error)
- func (d *Decoder) StrAppend(b []byte) ([]byte, error)
- func (d *Decoder) StrBytes() ([]byte, error)
- func (d *Decoder) UInt() (uint, error)
- func (d *Decoder) UInt16() (uint16, error)
- func (d *Decoder) UInt32() (uint32, error)
- func (d *Decoder) UInt64() (uint64, error)
- func (d *Decoder) UInt8() (uint8, error)
- func (d *Decoder) Validate() error
- type Encoder
- func (e *Encoder) Arr(f func(e *Encoder)) (fail bool)
- func (e *Encoder) ArrEmpty() bool
- func (e *Encoder) ArrEnd() bool
- func (e *Encoder) ArrStart() (fail bool)
- func (e *Encoder) Base64(data []byte) bool
- func (e *Encoder) Bool(v bool) bool
- func (e *Encoder) ByteStr(v []byte) bool
- func (e *Encoder) ByteStrEscape(v []byte) bool
- func (e Encoder) Bytes() []byte
- func (e *Encoder) Close() error
- func (e *Encoder) Field(name string, f func(e *Encoder)) (fail bool)
- func (e *Encoder) FieldStart(field string) (fail bool)
- func (e *Encoder) Float32(v float32) bool
- func (e *Encoder) Float64(v float64) bool
- func (e *Encoder) Grow(n int)
- func (e *Encoder) Int(v int) bool
- func (e *Encoder) Int16(v int16) bool
- func (e *Encoder) Int32(v int32) bool
- func (e *Encoder) Int64(v int64) bool
- func (e *Encoder) Int8(v int8) bool
- func (e *Encoder) Null() bool
- func (e *Encoder) Num(v Num) bool
- func (e *Encoder) Obj(f func(e *Encoder)) (fail bool)
- func (e *Encoder) ObjEmpty() bool
- func (e *Encoder) ObjEnd() bool
- func (e *Encoder) ObjStart() (fail bool)
- func (e *Encoder) Raw(b []byte) bool
- func (e *Encoder) RawStr(v string) bool
- func (e *Encoder) Reset()
- func (e *Encoder) ResetWriter(out io.Writer)
- func (e *Encoder) SetBytes(buf []byte)
- func (e *Encoder) SetIdent(n int)
- func (e *Encoder) Str(v string) bool
- func (e *Encoder) StrEscape(v string) bool
- func (e Encoder) String() string
- func (e *Encoder) UInt(v uint) bool
- func (e *Encoder) UInt16(v uint16) bool
- func (e *Encoder) UInt32(v uint32) bool
- func (e *Encoder) UInt64(v uint64) bool
- func (e *Encoder) UInt8(v uint8) bool
- func (e *Encoder) Write(p []byte) (n int, err error)
- func (e *Encoder) WriteTo(w io.Writer) (n int64, err error)
- type Num
- func (n Num) Equal(v Num) bool
- func (n Num) Float64() (float64, error)
- func (n Num) Format(f fmt.State, verb rune)
- func (n Num) Int64() (int64, error)
- func (n Num) IsInt() bool
- func (n Num) Negative() bool
- func (n Num) Positive() bool
- func (n Num) Sign() int
- func (n Num) Str() bool
- func (n Num) String() string
- func (n Num) Uint64() (uint64, error)
- func (n Num) Zero() bool
- type ObjIter
- type Raw
- type Type
- type Writer
- func (w *Writer) ArrEnd() bool
- func (w *Writer) ArrStart() bool
- func (w *Writer) Base64(data []byte) bool
- func (w *Writer) Bool(v bool) bool
- func (w *Writer) ByteStr(v []byte) bool
- func (w *Writer) ByteStrEscape(v []byte) bool
- func (w *Writer) Close() error
- func (w *Writer) Comma() bool
- func (w *Writer) False() bool
- func (w *Writer) FieldStart(field string) bool
- func (w *Writer) Float(v float64, bits int) bool
- func (w *Writer) Float32(v float32) bool
- func (w *Writer) Float64(v float64) bool
- func (w *Writer) Grow(n int)
- func (w *Writer) Int(v int) bool
- func (w *Writer) Int16(v int16) (fail bool)
- func (w *Writer) Int32(v int32) (fail bool)
- func (w *Writer) Int64(v int64) (fail bool)
- func (w *Writer) Int8(v int8) (fail bool)
- func (w *Writer) Null() bool
- func (w *Writer) Num(v Num) bool
- func (w *Writer) ObjEnd() bool
- func (w *Writer) ObjStart() bool
- func (w *Writer) Raw(b []byte) bool
- func (w *Writer) RawStr(v string) bool
- func (w *Writer) Reset()
- func (w *Writer) ResetWriter(out io.Writer)
- func (w *Writer) Str(v string) bool
- func (w *Writer) StrEscape(v string) bool
- func (w Writer) String() string
- func (w *Writer) True() bool
- func (w *Writer) UInt(v uint) bool
- func (w *Writer) UInt16(v uint16) (fail bool)
- func (w *Writer) UInt32(v uint32) (fail bool)
- func (w *Writer) UInt64(v uint64) (fail bool)
- func (w *Writer) UInt8(v uint8) bool
- func (w *Writer) Write(p []byte) (n int, err error)
- func (w *Writer) WriteTo(t io.Writer) (n int64, err error)
Examples¶
Constants¶
This section is empty.
Variables¶
This section is empty.
Functions¶
Types¶
typeArrIter¶added inv0.33.0
type ArrIter struct {// contains filtered or unexported fields}ArrIter is decoding array iterator.
typeDecoder¶
type Decoder struct {// contains filtered or unexported fields}Decoder decodes json.
Can decode from io.Reader or byte slice directly.
funcDecodeBytes¶
DecodeBytes creates a Decoder that reads json from byte slice.
funcDecodeStr¶
DecodeStr creates a Decoder that reads string as json.
Example¶
package mainimport ("fmt""github.com/go-faster/jx")func main() {d := jx.DecodeStr(`{"values":[4,8,15,16,23,42]}`)// Save all integers from "values" array to slice.var values []int// Iterate over each object field.if err := d.Obj(func(d *jx.Decoder, key string) error {switch key {case "values":// Iterate over each array element.return d.Arr(func(d *jx.Decoder) error {v, err := d.Int()if err != nil {return err}values = append(values, v)return nil})default:// Skip unknown fields if any.return d.Skip()}}); err != nil {panic(err)}fmt.Println(values)}Output:[4 8 15 16 23 42]
func (*Decoder)Base64¶
Base64 decodes base64 encoded data from string.
Same as encoding/json, base64.StdEncoding orRFC 4648.
Example¶
package mainimport ("fmt""github.com/go-faster/jx")func main() {data, _ := jx.DecodeStr(`"SGVsbG8="`).Base64()fmt.Printf("%s", data)}Output:Hello
func (*Decoder)Base64Append¶
Base64Append appends base64 encoded data from string.
Same as encoding/json, base64.StdEncoding orRFC 4648.
func (*Decoder)Capture¶
Capture calls f and then rolls back to state before call.
Example¶
package mainimport ("fmt""github.com/go-faster/jx")func main() {d := jx.DecodeStr(`["foo", "bar", "baz"]`)var elems int// NB: Currently Capture does not support io.Reader, only buffers.if err := d.Capture(func(d *jx.Decoder) error {// Everything decoded in this callback will be rolled back.return d.Arr(func(d *jx.Decoder) error {elems++return d.Skip()})}); err != nil {panic(err)}// Decoder is rolled back to state before "Capture" call.fmt.Println("Read", elems, "elements on first pass")fmt.Println("Next element is", d.Next(), "again")}Output:Read 3 elements on first passNext element is array again
func (*Decoder)Elem¶
Elem skips to the start of next array element, returning true booleanif element exists.
Can be called before or in Array.
func (*Decoder)Num¶
Num decodes number.
Do not retain returned value, it references underlying buffer.
Example¶
package mainimport ("fmt""github.com/go-faster/jx")func main() {// Can decode numbers and number strings.d := jx.DecodeStr(`{"foo": "10531.0"}`)var n jx.Numif err := d.Obj(func(d *jx.Decoder, key string) error {v, err := d.Num()if err != nil {return err}n = vreturn nil}); err != nil {panic(err)}fmt.Println(n)fmt.Println("positive:", n.Positive())// Can decode floats with zero fractional part as integers:v, err := n.Int64()if err != nil {panic(err)}fmt.Println("int64:", v)}Output:"10531.0"positive: trueint64: 10531
func (*Decoder)Obj¶
Obj reads json object, calling f on each field.
Use ObjBytes to reduce heap allocations for keys.
func (*Decoder)ObjBytes¶
ObjBytes calls f for every key in object, using byte slice as key.
The key value is valid only until f is not returned.
func (*Decoder)Raw¶
Raw is like Skip(), but saves and returns skipped value as raw json.
Do not retain returned value, it references underlying buffer.
Example¶
package mainimport ("fmt""github.com/go-faster/jx")func main() {d := jx.DecodeStr(`{"foo": [1, 2, 3]}`)var raw jx.Rawif err := d.Obj(func(d *jx.Decoder, key string) error {v, err := d.Raw()if err != nil {return err}raw = vreturn nil}); err != nil {panic(err)}fmt.Println(raw.Type(), raw)}Output:array [1, 2, 3]
func (*Decoder)Reset¶
Reset resets reader and underlying state, next reads will use provided io.Reader.
func (*Decoder)ResetBytes¶
ResetBytes resets underlying state, next reads will use provided buffer.
typeEncoder¶
type Encoder struct {// contains filtered or unexported fields}Encoder encodes json to underlying buffer.
Zero value is valid.
funcNewStreamingEncoder¶added inv1.0.0
NewStreamingEncoder creates new streaming encoder.
func (*Encoder)Arr¶added inv0.21.0
Arr writes start of array, invokes callback and writes end of array.
If callback is nil, writes empty array.
func (*Encoder)ArrEnd¶
ArrEnd writes end of array, performing indentation if needed.
Use Arr as convenience helper for writing arrays.
func (*Encoder)ArrStart¶
ArrStart writes start of array, performing indentation if needed.
Use Arr as convenience helper for writing arrays.
func (*Encoder)Base64¶
Base64 encodes data as standard base64 encoded string.
Same as encoding/json, base64.StdEncoding orRFC 4648.
Example¶
package mainimport ("fmt""github.com/go-faster/jx")func main() {var e jx.Encodere.Base64([]byte("Hello"))fmt.Println(e)data, _ := jx.DecodeBytes(e.Bytes()).Base64()fmt.Printf("%s", data)}Output:"SGVsbG8="Hello
func (*Encoder)ByteStr¶added inv0.34.0
ByteStr encodes byte slice without html escaping.
Use ByteStrEscape to escape html, this is default for encoding/json andshould be used by default for untrusted strings.
func (*Encoder)ByteStrEscape¶added inv0.34.0
ByteStrEscape encodes string with html special characters escaping.
func (*Encoder)Close¶added inv1.0.0
Close flushes underlying buffer to writer in streaming mode.Otherwise, it does nothing.
func (*Encoder)Field¶added inv0.19.0
Field encodes field start and then invokes callback.
Has ~5ns overhead over FieldStart.
func (*Encoder)FieldStart¶added inv0.22.0
FieldStart encodes field name and writes colon.
For non-zero indentation also writes single space after colon.
Use Field as convenience helper for encoding fields.
func (*Encoder)Obj¶added inv0.21.0
Obj writes start of object, invokes callback and writes end of object.
If callback is nil, writes empty object.
func (*Encoder)ObjEnd¶
ObjEnd writes end of object token, performing indentation if needed.
Use Obj as convenience helper for writing objects.
func (*Encoder)ObjStart¶
ObjStart writes object start, performing indentation if needed.
Use Obj as convenience helper for writing objects.
func (*Encoder)Reset¶
func (e *Encoder) Reset()
Reset resets underlying buffer.
If e is in streaming mode, it is reset to non-streaming mode.
func (*Encoder)ResetWriter¶added inv1.0.0
ResetWriter resets underlying buffer and sets output writer.
func (*Encoder)SetIdent¶
SetIdent sets length of single indentation step.
Example¶
package mainimport ("fmt""github.com/go-faster/jx")func main() {var e jx.Encodere.SetIdent(2)e.ObjStart()e.FieldStart("data")e.ArrStart()e.Int(1)e.Int(2)e.ArrEnd()e.ObjEnd()fmt.Println(e)}Output:{ "data": [ 1, 2 ]}
func (*Encoder)Str¶
Str encodes string without html escaping.
Use StrEscape to escape html, this is default for encoding/json andshould be used by default for untrusted strings.
func (Encoder)String¶
String returns string of underlying buffer.
Example¶
package mainimport ("fmt""github.com/go-faster/jx")func main() {var e jx.Encodere.ObjStart() // {e.FieldStart("values") // "values":e.ArrStart() // [for _, v := range []int{4, 8, 15, 16, 23, 42} {e.Int(v)}e.ArrEnd() // ]e.ObjEnd() // }fmt.Println(e)fmt.Println("Buffer len:", len(e.Bytes()))}Output:{"values":[4,8,15,16,23,42]}Buffer len: 28
typeNum¶
type Num []byte
Num represents number, which can be raw json number or number string.
Same as Raw, but with number invariants.
Examples:
123.45 // Str: false, IsInt: false"123.45" // Str: true, IsInt: false"12345" // Str: true, IsInt: true12345 // Str: false, IsInt: true
func (Num)Int64¶
Int64 decodes number as a signed 64-bit integer.Works on floats with zero fractional part.
typeObjIter¶added inv0.35.0
type ObjIter struct {// contains filtered or unexported fields}ObjIter is decoding object iterator.
func (*ObjIter)Err¶added inv0.35.0
Err returns the error, if any, that was encountered during iteration.
typeWriter¶added inv0.26.0
type Writer struct {Buf []byte// underlying buffer// contains filtered or unexported fields}Writer writes json tokens to underlying buffer.
Zero value is valid.
func (*Writer)Base64¶added inv0.26.0
Base64 encodes data as standard base64 encoded string.
Same as encoding/json, base64.StdEncoding orRFC 4648.
func (*Writer)ByteStr¶added inv0.34.0
ByteStr encodes string without html escaping.
Use ByteStrEscape to escape html, this is default for encoding/json andshould be used by default for untrusted strings.
func (*Writer)ByteStrEscape¶added inv0.34.0
ByteStrEscape encodes string with html special characters escaping.
func (*Writer)Close¶added inv1.0.0
Close flushes underlying buffer to writer in streaming mode.Otherwise, it does nothing.
func (*Writer)FieldStart¶added inv0.26.0
FieldStart encodes field name and writes colon.
func (*Writer)Float32¶added inv0.26.0
Float32 encodes float32.
NB: Infinities and NaN are represented as null.
func (*Writer)Float64¶added inv0.26.0
Float64 encodes float64.
NB: Infinities and NaN are represented as null.
func (*Writer)Grow¶added inv1.1.0
Grow grows the underlying buffer.
Calls (*bytes.Buffer).Grow(n int) on w.Buf.
func (*Writer)Reset¶added inv0.26.0
func (w *Writer) Reset()
Reset resets underlying buffer.
If w is in streaming mode, it is reset to non-streaming mode.
func (*Writer)ResetWriter¶added inv1.0.0
ResetWriter resets underlying buffer and sets output writer.
func (*Writer)Str¶added inv0.26.0
Str encodes string without html escaping.
Use StrEscape to escape html, this is default for encoding/json andshould be used by default for untrusted strings.
func (*Writer)StrEscape¶added inv0.26.0
StrEscape encodes string with html special characters escaping.
Source Files¶
- dec.go
- dec_arr.go
- dec_arr_iter.go
- dec_b64.go
- dec_bool.go
- dec_capture.go
- dec_depth.go
- dec_error.go
- dec_float.go
- dec_float_big.go
- dec_int.gen.go
- dec_int.go
- dec_null.go
- dec_num.go
- dec_obj.go
- dec_obj_iter.go
- dec_raw.go
- dec_read.go
- dec_skip.go
- dec_str.go
- dec_validate.go
- enc.go
- enc_b64.go
- enc_comma.go
- enc_float.go
- enc_int.go
- enc_num.go
- enc_str.go
- enc_str_escape.go
- enc_stream.go
- generate.go
- jx.go
- num.go
- w.go
- w_b64.go
- w_float.go
- w_float_bits.go
- w_int.gen.go
- w_int.go
- w_num.go
- w_str.go
- w_str_escape.go
- w_stream.go
Directories¶
| Path | Synopsis |
|---|---|
internal | |
byteseq Package byteseq provides a Byteseq type that can be used to represent a sequence of bytes. | Package byteseq provides a Byteseq type that can be used to represent a sequence of bytes. |
tools | |
mkintcommand Command mkencint generates integer encoding/decoding functions. | Command mkencint generates integer encoding/decoding functions. |