docs: add godoc examples, extend the basic example and map encoding/json
Test / test (push) Successful in 1m47s
Test / test (push) Successful in 1m47s
Assisted-by: GLM 5.3 Flash
This commit is contained in:
+23
@@ -797,6 +797,29 @@ sequenceDiagram
|
||||
Marshal-->>Caller: bytes, error
|
||||
```
|
||||
|
||||
## Coming from encoding/json
|
||||
|
||||
The API follows the shapes encoding/json made familiar, with the differences
|
||||
TOML asks for:
|
||||
|
||||
| encoding/json | interpres | Notes |
|
||||
|---|---|---|
|
||||
| `json.Unmarshal(data, v)` | `Unmarshal(data, v)` | the same shape; the value mapping is TOML's |
|
||||
| `json.Marshal(v)` | `Marshal(v)` | the same shape; the output is TOML 1.1 |
|
||||
| `json.MarshalAppend(buf, v)` | `MarshalAppend(buf, v)` | the same shape |
|
||||
| `(*json.Decoder).DisallowUnknownFields` | `(*Decoder).DisallowUnknownFields` | the same effect; the one-shot form is `UnmarshalWithOptions` |
|
||||
| `json.Number`, `(*json.Decoder).UseNumber` | `Number`, `(*Decoder).UseNumber` | the TOML literal carries its radix and separators, so `0x1f` stays `0x1f` |
|
||||
| `json.MarshalIndent` | none | TOML is the presentation format; the `-json` mode of interpres-decode prints plain JSON |
|
||||
| tag `json:"name,omitempty"` | tag `toml:"name,omitempty"` | the empty-value rules match encoding/json as of 2.0 |
|
||||
| tag `json:"name,omitzero"` | tag `toml:"name,omitzero"` | the same, `IsZero()` honoured |
|
||||
| tag `json:"name,inline"` (v2) | tag `toml:"name,inline"` | forces the inline table form on encode |
|
||||
| `json.Marshaler` (`MarshalJSON`) | `Marshaler` (`MarshalTOML`) | the TOML method returns a value the encoder renders, not bytes |
|
||||
| `json.Unmarshaler` (`UnmarshalJSON`) | `Unmarshaler` (`UnmarshalTOML`) | the data arrives decoded, not as bytes |
|
||||
| `encoding.TextMarshaler`, `TextUnmarshaler` | honoured, the same | a type that renders itself as text becomes a TOML string, both ways |
|
||||
| `*json.UnmarshalTypeError` | `*DecodeError` | the path is segments with a `String()` renderer, not a dotted string |
|
||||
| `*json.SyntaxError` | `*SyntaxError` | the TOML error adds the byte `Offset` and the `Column` to the line |
|
||||
| context support | `*Context` variants of every entry point | encoding/json has none |
|
||||
|
||||
## Types
|
||||
|
||||
### `type SyntaxError struct{ Line, Offset, Column int; Msg string }`
|
||||
|
||||
Reference in New Issue
Block a user