diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2023-01-30 21:58:51 -0700 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2023-01-30 21:58:51 -0700 |
commit | ab321d3f90b9a1b4c00b04be26867d9a03809259 (patch) | |
tree | 7f4a64fa5365ffd3b285f921c5f905754b3883b3 /README.md | |
parent | d473f861a5c3a3112c83518eafbcda50e274b182 (diff) | |
parent | cbf8ec9ae3212e9642385c034fe0b0846af6dfd0 (diff) |
Merge branch 'lukeshu/break'
Diffstat (limited to 'README.md')
-rw-r--r-- | README.md | 21 |
1 files changed, 5 insertions, 16 deletions
@@ -41,8 +41,8 @@ those types should decode identically with `lowmemjson`. Given types that encode as desired with `encoding/json`, those types should encode identically with `lowmemjson` (assuming an appropriately configured `ReEncoder` to match the whitespace-handling and special-character -escaping; a `ReEncoder` with `Compact=true` and all other settings -left as zero will match the behavior of `json.Marshal`). +escaping; a `ReEncoderConfig` with `Compact=true` and all other +settings left as zero will match the behavior of `json.Marshal`). For better memory usage: - Instead of implementing [`json.Marshaler`][], consider implementing @@ -95,6 +95,7 @@ types that go with it: + `type EncodeMethodError` 3. `type ReEncoder` + + `type ReEncoderConfig` + `type ReEncodeSyntaxError` + `type BackslashEscaper` * `type BackslashEscapeMode` @@ -108,25 +109,13 @@ A `*ReEncoder` handles transforming a JSON stream; this is useful for prettifying, minifying, sanitizing, and/or validating JSON. A `*ReEncoder` wraps an `io.Writer`, itself implementing `io.Writer`. The most common use of it will be something along the lines of - -```go -out = &ReEncoder{ - Out: out, - // settings here -} -``` +`out = lowmemjson.NewReEncoder(out, lowmemjson.ReEncoderConfig{…})`. An `*Encoder` handles encoding Go values into a JSON stream. `*Encoder` doesn't take much care in to making its output nice; so it is usually desirable to have the output stream of an `*Encoder` be a `*ReEncoder`; the most common use of it will be - -```go -lowmemjson.NewEncoder(&lowmemjson.ReEncoder{ - Out: out, - // settings here -}).Encode(val) -``` +`lowmemjson.NewEncoder(lowmemjson.NewReEncoder(out, lowmemjson.ReEncoderConfig{…})).Encode(val)`. `*Encoder` and `*ReEncoder` both tend to make many small writes; if writes are syscalls, you may want to wrap their output in a |