summaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2023-01-27 13:12:35 -0700
committerLuke Shumaker <lukeshu@lukeshu.com>2023-01-30 21:58:29 -0700
commitcbf8ec9ae3212e9642385c034fe0b0846af6dfd0 (patch)
tree7f4a64fa5365ffd3b285f921c5f905754b3883b3 /README.md
parentd473f861a5c3a3112c83518eafbcda50e274b182 (diff)
BREAKING CHANGE: reencode: Separate config from state
Diffstat (limited to 'README.md')
-rw-r--r--README.md21
1 files changed, 5 insertions, 16 deletions
diff --git a/README.md b/README.md
index fcb46fa..108f3dc 100644
--- a/README.md
+++ b/README.md
@@ -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