The Rosetta Stone of the Koinos ecosystem. Allows for the interpretation of Koinos data structures in a multitude of languages. Useful in the development of microservices, clients, and smart contracts.
MIT License
12
stars
3
forks
source link
VariableBlob should be string instead of byte slice in Golang target #142
It is useful to be able to use types reflected by koinos-types as map keys in Golang.
Map keys must be types that are comparable, where "comparable" is defined by a specific part of the Golang language spec [1]. Unfortunately, "Slice...values are not comparable" [1]. Which means []byte cannot be used as a map key, nor can any type containing []byte. Since VariableBlob is currently an alias of []byte, this includes much of our type hierarchy.
Fortunately, there is a simple solution. Strings can be used as map keys [1]. The string type, in fact, "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." [2]
So we should change the type alias for VariableBlob from []byte to string in order to solve this problem.
It is useful to be able to use types reflected by
koinos-types
as map keys in Golang.Map keys must be types that are comparable, where "comparable" is defined by a specific part of the Golang language spec [1]. Unfortunately, "Slice...values are not comparable" [1]. Which means
[]byte
cannot be used as a map key, nor can any type containing[]byte
. SinceVariableBlob
is currently an alias of[]byte
, this includes much of our type hierarchy.Fortunately, there is a simple solution. Strings can be used as map keys [1]. The
string
type, in fact, "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." [2]So we should change the type alias for
VariableBlob
from[]byte
tostring
in order to solve this problem.[1] https://golang.org/ref/spec#Comparison_operators
[2] https://blog.golang.org/strings