Skip to content

Commit

Permalink
remove SB64 from Coze and move it to package Cyphrme/Tree
Browse files Browse the repository at this point in the history
  • Loading branch information
zamicol committed Aug 10, 2023
1 parent 2ff8402 commit d933d6d
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 45 deletions.
24 changes: 0 additions & 24 deletions base64.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,27 +53,3 @@ func MustDecode(b64 string) B64 {
}
return b
}

// SB64 is useful for B64 map keys. Idiomatically, map key type should be `B64`,
// but currently in Go map keys are only type `string`, not `[]byte`. Since
// B64's underlying type is `[]byte` it cannot be used as a map key. See
// https://github.com/golang/go/issues/283 and
// https://github.com/google/go-cmp/issues/67. SB64 will be deprecated if/when
// Go supports []byte keys.
//
// This is an acceptable hack because (from https://go.dev/blog/strings)
//
// >[A] string holds arbitrary bytes. It is not required to hold Unicode text,
// > UTF-8 text, or any other predefined format. As far as the content of a
// > string is concerned, it is exactly equivalent to a slice of bytes.
type SB64 string

// String implements fmt.Stringer
func (b SB64) String() string {
return B64(b).String()
}

// GoString implements fmt.GoString
func (b SB64) GoString() string {
return b.String()
}
21 changes: 0 additions & 21 deletions base64_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,27 +131,6 @@ func ExampleB64_non_strict_decode() {
// invalid character '\r' in string literal
}

// ExampleSB64 demonstrates using SB64 as a map key and that fmt prints "RFC
// 4648 base 64 URI canonical with padding truncated" properly.
func ExampleSB64() {
b := MustDecode("zVzgRU3WFpnrlVJAnI4ZU1Od4Agl5Zd4jIP79oubOW0")
b2 := MustDecode("vZIAk8rjcSIKZKokGylCtVoI3DXvFYJn4XNWzf_C_FA")

lp := make(map[SB64]B64)
lp[SB64(b)] = B64(b2)

fmt.Printf("%s\n", SB64(b))
fmt.Printf("%s\n", lp)
fmt.Printf("%+v\n", lp)
fmt.Printf("%#v\n", lp)

// Output:
// zVzgRU3WFpnrlVJAnI4ZU1Od4Agl5Zd4jIP79oubOW0
// map[zVzgRU3WFpnrlVJAnI4ZU1Od4Agl5Zd4jIP79oubOW0:vZIAk8rjcSIKZKokGylCtVoI3DXvFYJn4XNWzf_C_FA]
// map[zVzgRU3WFpnrlVJAnI4ZU1Od4Agl5Zd4jIP79oubOW0:vZIAk8rjcSIKZKokGylCtVoI3DXvFYJn4XNWzf_C_FA]
// map[coze.SB64]coze.B64{zVzgRU3WFpnrlVJAnI4ZU1Od4Agl5Zd4jIP79oubOW0:vZIAk8rjcSIKZKokGylCtVoI3DXvFYJn4XNWzf_C_FA}
}

// FuzzCastB64ToString ensures that casting to and from B64 and string does not
// cause unexpected issues (issues like replacing bytes with the unicode
// replacement character).
Expand Down

0 comments on commit d933d6d

Please sign in to comment.