Skip to content

Conversation

@fxamacker
Copy link
Owner

This PR improves unreleased decoding options to be included in v2.7.0.

Changes include:

  • Renamed ByteSliceExpectedEncodingMode to ByteStringExpectedFormatMode, also renamed related options

  • Renamed DecOptions.ByteSliceExpectedEncoding to DecOptions.ByteStringExpectedFormat

  • Added ByteStringExpectedFormatError, which is returned when decoding expected format fails

  • Updated comments to improve docs. For example,

    // ByteStringExpectedFormatMode specifies how to decode CBOR byte string into Go byte slice
    // when the byte string is NOT enclosed in CBOR tag 21, 22, or 23.  An error is returned if
    // the CBOR byte string does not contain the expected format (e.g. base64) specified.
    // For tags 21-23, see "Expected Later Encoding for CBOR-to-JSON Converters"
    // in RFC 8949 Section 3.4.5.2.

@fxamacker fxamacker added the improvement improvement that does not add new feature label Jun 9, 2024
@fxamacker fxamacker added this to the v2.7.0 milestone Jun 9, 2024
@fxamacker fxamacker self-assigned this Jun 9, 2024
@fxamacker
Copy link
Owner Author

@x448 PTAL 🙏

@fxamacker
Copy link
Owner Author

@benluddy PTAL 🙏

// ByteSliceExpectedEncodingMode specifies how to decode a byte string NOT enclosed in an "expected
// later encoding" tag (RFC 8949 Section 3.4.5.2) into a Go byte slice.
type ByteSliceExpectedEncodingMode int
// ByteStringExpectedFormatMode specifies how to decode CBOR byte string into Go byte slice
Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense. The old suffix "EncodingMode" for a decoding mode name would have been confusing.

name: "unsigned bignum content not enclosed in expected encoding tag",
tag: Tag{Number: tagNumUnsignedBignum, Content: []byte{0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
opts: EncOptions{ByteSlice: ByteSliceExpectedEncodingBase16},
opts: EncOptions{ByteSlice: ByteSliceToByteStringWithExpectedConversionToBase16},
Copy link
Contributor

Choose a reason for hiding this comment

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

It wasn't named in this PR but ByteSliceToByteStringWithExpectedConversionToBase16 can be renamed to a shorter name.

@fxamacker fxamacker merged commit 58a5aa0 into master Jun 10, 2024
@fxamacker fxamacker deleted the fxamacker/improve-bytestringformat-dec-mode branch September 7, 2024 20:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

improvement improvement that does not add new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants