Skip to content

Commit

Permalink
Merge pull request #402 from fxamacker/fxamacker/add-unmarshalfirst-t…
Browse files Browse the repository at this point in the history
…o-DecMode-interface

Add UnmarshalFirst to DecMode interface
  • Loading branch information
fxamacker authored May 6, 2023
2 parents 21a6738 + bb06d38 commit 03bf60e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,14 @@ type DecMode interface {
// See the documentation for Unmarshal for details.
Unmarshal(data []byte, v interface{}) error

// UnmarshalFirst parses the first CBOR data item into the value pointed to by v
// using the decoding mode. Any remaining bytes are returned in rest.
//
// If v is nil, not a pointer, or a nil pointer, UnmarshalFirst returns an error.
//
// See the documentation for Unmarshal for details.
UnmarshalFirst(data []byte, v interface{}) (rest []byte, err error)

// Valid checks whether data is a well-formed encoded CBOR data item and
// that it complies with configurable restrictions such as MaxNestedLevels,
// MaxArrayElements, MaxMapPairs, etc.
Expand Down
2 changes: 1 addition & 1 deletion decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6034,7 +6034,7 @@ func TestUnmarshalFirstInvalidItem(t *testing.T) {
invalidCBOR := hexDecode("83FF20030102")
var v interface{}
rest, err := UnmarshalFirst(invalidCBOR, &v)
if rest != nil {
if rest != nil || err == nil {
t.Errorf("UnmarshalFirst(0x%x) = (%x, %v), want (nil, err)", invalidCBOR, rest, err)
}
}

0 comments on commit 03bf60e

Please sign in to comment.