Closed benluddy closed 7 months ago
Thanks @benluddy for detailed write up in #449 and this POC!
The POC covers all use cases you mentioned and the roundtrip tests illustrating those use cases are great!
I see that TextConversionMode
has 3 options, including the TextConversionEncodeToText
option.
Since tag numbers 21-23 are defined in Section 3.4.5.2 of RFC 8949, what do you think about moving TextConversionEncodeToText
option into it's own separate mode?
For example, we can add a decoding mode with 2 options:
This new decoding mode for tags 21-23 would match the new encoding mode ByteSliceMode
added by the POC.
It can also help simplify TextConversionMode
since the new mode can be used without being tied to TextConversions
.
Thoughts?
I see that
TextConversionMode
has 3 options, including theTextConversionEncodeToText
option.Since tag numbers 21-23 are defined in Section 3.4.5.2 of RFC 8949, what do you think about moving
TextConversionEncodeToText
option into it's own separate mode?For example, we can add a decoding mode with 2 options:
* by default, ignore tag number 21-23 and only decode tag content for backward compatibility * decode tag number 21-23 as well as tag content (as handled by POC)
This new decoding mode for tags 21-23 would match the new encoding mode
ByteSliceMode
added by the POC.It can also help simplify
TextConversionMode
since the new mode can be used without being tied toTextConversions
.Thoughts?
Yes, that sounds reasonable. I waffled a bit on the shape of the decode options before ending up with the current iteration. It was clear that the exact text conversion behavior depends on the type of the destination Go value, but less clear whether or not it was useful to make those types configurable. The example in the roundtrip test (string: encode, []byte: decode) is sufficient for my use case.
Would you prefer to see the TextConversions function replaced entirely by two decode options: one for decoding into strings and one for byte slices?
Would you prefer to see the TextConversions function replaced entirely by two decode options: one for decoding into strings and one for byte slices?
@benluddy Yes, that would be great! :+1: Thanks for suggesting it.
Updated based on the discussion from last month. It should be fairly close to its final shape now. I'll follow up soon to fill out the test coverage.
OK, I think this is ready now.
While I was filling in the test coverage gaps, I realized that only one new decode option was required. The existing option ByteStringToString
has modes "forbidden" (error on decoding byte string into string) and "allowed" (no error on decoding byte string into string). Rather than add a new option to control the behavior of decoding expected-later-encoding-tagged byte strings into strings -- which would itself require ByteStringToStringAllowed
to be useful -- I added a third mode to ByteStringToString
that extends ByteStringToStringAllowed
by automatically applying the text encoding.
Please take another look!
Hi @fxamacker, I've pushed changes to address your feedback on the encode side. Thanks for the review!
Description
This is a proof-of-concept solution for https://github.com/fxamacker/cbor/issues/449. It includes a test that roundtrips a struct value with fields of types
[]byte
and[5]byte
tointerface{}
and back to the original struct type, via both CBOR (using the features here) and via encoding/json.PR Was Proposed and Welcomed in Currently Open Issue
Checklist (for code PR only, ignore for docs PR)
Last line of each commit message should be in this format:
Signed-off-by: Firstname Lastname firstname.lastname@example.com
Certify the Developer's Certificate of Origin 1.1