mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-15 06:01:50 +00:00
Merge pull request #125418 from benluddy/cbor-byte-array-to-array
KEP-4222: Encode byte array to CBOR as array of integer, not byte string.
This commit is contained in:
@@ -75,6 +75,10 @@ var Encode cbor.EncMode = func() cbor.EncMode {
|
|||||||
// Encode struct field names to the byte string type rather than the text string
|
// Encode struct field names to the byte string type rather than the text string
|
||||||
// type.
|
// type.
|
||||||
FieldName: cbor.FieldNameToByteString,
|
FieldName: cbor.FieldNameToByteString,
|
||||||
|
|
||||||
|
// Marshal Go byte arrays to CBOR arrays of integers (as in JSON) instead of byte
|
||||||
|
// strings.
|
||||||
|
ByteArray: cbor.ByteArrayToArray,
|
||||||
}.EncMode()
|
}.EncMode()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@@ -64,6 +64,12 @@ func TestEncode(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "byte array encodes to array of integers",
|
||||||
|
in: [3]byte{0x01, 0x02, 0x03},
|
||||||
|
want: []byte{0x83, 0x01, 0x02, 0x03}, // [1, 2, 3]
|
||||||
|
assertOnError: assertNilError,
|
||||||
|
},
|
||||||
} {
|
} {
|
||||||
encModes := tc.modes
|
encModes := tc.modes
|
||||||
if len(encModes) == 0 {
|
if len(encModes) == 0 {
|
||||||
|
@@ -47,6 +47,10 @@ func TestRoundtrip(t *testing.T) {
|
|||||||
name: "nil slice",
|
name: "nil slice",
|
||||||
obj: []interface{}(nil),
|
obj: []interface{}(nil),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "byte array",
|
||||||
|
obj: [3]byte{0x01, 0x02, 0x03},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "nil map",
|
name: "nil map",
|
||||||
obj: map[string]interface{}(nil),
|
obj: map[string]interface{}(nil),
|
||||||
|
Reference in New Issue
Block a user