|
10 | 10 | [](https://goreportcard.com/report/github.com/fxamacker/cbor) |
11 | 11 | [](#cbor-library-installation) |
12 | 12 |
|
13 | | -[__fxamacker/cbor__](https://github.com/fxamacker/cbor) is a [CBOR](https://tools.ietf.org/html/rfc8949) codec in full compliance with [IETF RFC 8949 (STD 94)](https://www.rfc-editor.org/info/std94). This codec also supports [CBOR Sequences](https://www.rfc-editor.org/rfc/rfc8742.html) (IETF RFC 8742). |
| 13 | +[__fxamacker/cbor__](https://github.com/fxamacker/cbor) is a [CBOR](https://tools.ietf.org/html/rfc8949) codec in full conformance with [IETF STD 94 (RFC 8949)](https://www.rfc-editor.org/info/std94). This CBOR codec also supports [CBOR Sequences](https://www.rfc-editor.org/rfc/rfc8742.html) (IETF RFC 8742) and human-readable [Extended Diagnostic Notation](https://www.rfc-editor.org/rfc/rfc8610.html#appendix-G). |
14 | 14 |
|
15 | | -This codec is a compact, deterministic, and secure alternative to [Go's](https://golang.org) `encoding/json`, `encoding/gob`, and others. It's fast despite avoiding use of Go's `unsafe` package. It's very fast and memory efficient at rejecting malformed CBOR data. |
| 15 | +fxamacker/cbor is a deterministic, efficient, and secure alternative to [Go's](https://golang.org) `encoding/json`, `encoding/gob`, and other codecs. It's fast despite avoiding use of Go's `unsafe` package. It's very fast and memory efficient at rejecting malformed CBOR data. |
16 | 16 |
|
17 | 17 | API is designed to be safe, efficient, and easy for concurrent use. API is mostly same as `encoding/json` plus extra functions for immutable encoding and decoding modes (with custom settings) which simplify concurrent use. |
18 | 18 |
|
19 | | -Features include `keyasint` and `toarray` struct tags for more compact CBOR encoding with less programming effort. |
| 19 | +Features include Go struct tags (`toarray`, `keyasint`, `omitempty`), which automatically make CBOR encodings more compact. |
20 | 20 |
|
21 | | -Other features include: CBOR tags, duplicate map key detection, float64→32→16, and Go struct tags (`toarray`, `keyasint`, `omitempty`). Predefined CBOR options include Core Deterministic Encoding, Preferred Serialization, CTAP2, Canonical CBOR, etc. |
| 21 | +Other features include: CBOR tags for extensibility, duplicate map key detection, and float64→32→16. Preset CBOR options include Core Deterministic Encoding, Preferred Serialization, CTAP2, Canonical CBOR, etc. |
22 | 22 |
|
23 | 23 | Install with `go get github.com/fxamacker/cbor/v2` and `import "github.com/fxamacker/cbor/v2"`. |
24 | 24 | See [Quick Start 🔖](#quick-start) to save time. |
@@ -155,6 +155,11 @@ __Standard API__. Function signatures identical to [`encoding/json`](https://go |
155 | 155 | __Standard Interfaces__. Custom encoding and decoding is handled by implementing: |
156 | 156 | `BinaryMarshaler`, `BinaryUnmarshaler`, `Marshaler`, and `Unmarshaler`. |
157 | 157 |
|
| 158 | +__Other__. `UnmarshalFirst` decodes first CBOR data item and returns any remaining bytes. |
| 159 | + |
| 160 | +__Diagnostic API__. These functions produce human-readable [Extended Diagnostic Notation](https://www.rfc-editor.org/rfc/rfc8610.html#appendix-G): |
| 161 | +`Diagnose`, `DiagnoseFirst`. |
| 162 | + |
158 | 163 | __Predefined Encoding Options__. Encoding options are easy to use and are customizable. |
159 | 164 |
|
160 | 165 | ```go |
@@ -203,14 +208,20 @@ import "github.com/fxamacker/cbor/v2" // imports as cbor |
203 | 208 | ``` |
204 | 209 |
|
205 | 210 | ## Quick Start |
206 | | -🛡️ Use Go's `io.LimitReader` to limit size when decoding very large or indefinite size data. |
| 211 | +🛡️ Use Go's `io.LimitReader` to limit size when decoding very large or indefinite size data. `DecOptions` can be used to modify default limits with `MaxArrayElements`, `MaxMapPairs`, and `MaxNestedLevels`. |
207 | 212 |
|
208 | 213 | Import using "/v2" like this: `import "github.com/fxamacker/cbor/v2"`, and |
209 | 214 | it will import version 2.x as package "cbor" (when using Go modules). |
210 | 215 |
|
211 | 216 | Functions with identical signatures to encoding/json include: |
212 | 217 | `Marshal`, `Unmarshal`, `NewEncoder`, `NewDecoder`, `(*Encoder).Encode`, `(*Decoder).Decode`. |
213 | 218 |
|
| 219 | +NOTE: `Unmarshal` will return `ExtraneousDataError` if there are remaining bytes. |
| 220 | +Use `UnmarshalFirst` to decode the first CBOR data item and return any remaining bytes. |
| 221 | + |
| 222 | +These functions produce human-readable [Extended Diagnostic Notation](https://www.rfc-editor.org/rfc/rfc8610.html#appendix-G): |
| 223 | +`Diagnose`, `DiagnoseFirst`. |
| 224 | + |
214 | 225 | __Default Mode__ |
215 | 226 |
|
216 | 227 | If default options are acceptable, package level functions can be used for encoding and decoding. |
|
0 commit comments