Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci-go-cover.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@ jobs:
- name: Go Coverage
run: |
go version
go test -short -cover | grep "^.*coverage:.*of statements$" | python -c "import os,re,sys; cover_rpt = sys.stdin.read(); print(cover_rpt) if len(cover_rpt) != 0 and len(cover_rpt.splitlines()) == 1 else sys.exit(1); min_cover = float(re.findall(r'\d*\.\d+|\d+', os.environ['GITHUB_WORKFLOW'])[0]); cover = float(re.findall(r'\d*\.\d+|\d+', cover_rpt)[0]); sys.exit(1) if (cover > 100) or (cover < min_cover) else sys.exit(0)"
go test -short -cover | grep "^.*coverage:.*of statements$" | python -c "import os,re,sys; cover_rpt = sys.stdin.read(); print(cover_rpt) if len(cover_rpt) != 0 and len(cover_rpt.splitlines()) == 1 else sys.exit(1); min_cover = float(re.findall(r'\d*\.\d+|\d+', os.environ['GITHUB_WORKFLOW'])[0]); cover = float(re.findall(r'coverage:\s*(\d+(?:\.\d+)?)', cover_rpt)[0]); sys.exit(1) if (cover > 100) or (cover < min_cover) else sys.exit(0)"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

shell: bash
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ because RFC 8949 treats CBOR data item with remaining bytes as malformed.
Other useful functions:
- `Diagnose`, `DiagnoseFirst` produce human-readable [Extended Diagnostic Notation](https://www.rfc-editor.org/rfc/rfc8610.html#appendix-G) from CBOR data.
- `UnmarshalFirst` decodes first CBOR data item and return any remaining bytes.
- `Wellformed` returns true if the CBOR data item is well-formed.
- `Wellformed` returns nil error if the CBOR data item is well-formed.

Interfaces identical or comparable to Go `encoding` packages include:
`Marshaler`, `Unmarshaler`, `BinaryMarshaler`, and `BinaryUnmarshaler`.
Expand Down
2 changes: 1 addition & 1 deletion decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -2263,7 +2263,7 @@ func (d *decoder) applyByteStringTextConversion(
default:
// If this happens, there is a bug: the decoder has pushed an invalid
// "expected later encoding" tag to the stack.
panic(fmt.Sprintf("unrecognized expected later encoding tag: %d", d.expectedLaterEncodingTags))
panic(fmt.Sprintf("unrecognized expected later encoding tag: %d", d.expectedLaterEncodingTags[len(d.expectedLaterEncodingTags)-1]))
}

case reflect.Slice:
Expand Down
20 changes: 15 additions & 5 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,30 @@ modes won't accidentally change at runtime after they're created.

Modes are intended to be reused and are safe for concurrent use.

EncMode and DecMode Interfaces
EncMode, UserBufferEncMode, and DecMode Interfaces

// EncMode interface uses immutable options and is safe for concurrent use.
type EncMode interface {
Marshal(v interface{}) ([]byte, error)
Marshal(v any) ([]byte, error)
NewEncoder(w io.Writer) *Encoder
EncOptions() EncOptions // returns copy of options
EncOptions() EncOptions
}

// UserBufferEncMode extends EncMode with MarshalToBuffer, which supports
// user specified buffer rather than encoding into the built-in buffer pool.
type UserBufferEncMode interface {
EncMode
MarshalToBuffer(v any, buf *bytes.Buffer) error
}

// DecMode interface uses immutable options and is safe for concurrent use.
type DecMode interface {
Unmarshal(data []byte, v interface{}) error
Unmarshal(data []byte, v any) error
UnmarshalFirst(data []byte, v any) (rest []byte, err error)
Valid(data []byte) error // Deprecated: use Wellformed instead.
Wellformed(data []byte) error
NewDecoder(r io.Reader) *Decoder
DecOptions() DecOptions // returns copy of options
DecOptions() DecOptions
}

Using Default Encoding Mode
Expand Down
8 changes: 8 additions & 0 deletions encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,14 @@ var marshalTestCases = []marshalTestCase{
wantData: mustHexDecode("3affffffff"),
values: []any{int64(-4294967296)},
},
{
wantData: mustHexDecode("3b0000000100000000"),
values: []any{int64(-4294967297)},
},
{
wantData: mustHexDecode("3b7fffffffffffffff"),
values: []any{int64(math.MinInt64)},
},

// byte string
{
Expand Down
Loading