bytes: clean up and simplify encoding of HexBytes (#6810)

As written, the encoding step unnecessarily made and moved multiple copies of
the encoded representation. Reduce this to a single allocation and encode the
data in-place so that a shift is no longer required.

Also: Add a test to ensure letter digits are capitalized, which was previously not
verified but was expected downstream.

No functional changes.
This commit is contained in:
M. J. Fromberger
2021-08-10 09:58:18 -04:00
committed by GitHub
parent a7ecf49c10
commit 53d53e6205
2 changed files with 16 additions and 8 deletions
+1
View File
@@ -37,6 +37,7 @@ func TestJSONMarshal(t *testing.T) {
{[]byte(``), `{"B1":"","B2":""}`},
{[]byte(`a`), `{"B1":"YQ==","B2":"61"}`},
{[]byte(`abc`), `{"B1":"YWJj","B2":"616263"}`},
{[]byte("\x1a\x2b\x3c"), `{"B1":"Gis8","B2":"1A2B3C"}`},
}
for i, tc := range cases {