Commit b0c747c4 authored by Kirill Smelkov's avatar Kirill Smelkov

go/neo/proto: protogen: Clarify criteria to detect []byte

We previously used criteria that sizeof(typ.Elem()) == 1, but it would
also trigger on e.g. `struct { x byte }` which we would not want to
consider as byte array.

-> Clarify the test to explicitly test for typ.Elem() == byte.
No change in generated code.
parent a7c10aec
......@@ -449,13 +449,6 @@ notfixed:
return 0, false
}
// does a type have fixed wire size == 1 ?
func typeSizeFixed1(typ types.Type) bool {
wireSize, _ := typeSizeFixed(typ)
return wireSize == 1
}
// interface of a codegenerator (for sizer/coder/decoder)
type CodeGenerator interface {
// tell codegen it should generate code for which type & receiver name
......@@ -1222,7 +1215,7 @@ func codegenType(path string, typ types.Type, obj types.Object, codegen CodeGene
case *types.Array:
// [...]byte or [...]uint8 - just straight copy
if typeSizeFixed1(u.Elem()) {
if isByte(u.Elem()) {
codegen.genArray1(path, u)
} else {
var i int64
......@@ -1232,7 +1225,7 @@ func codegenType(path string, typ types.Type, obj types.Object, codegen CodeGene
}
case *types.Slice:
if typeSizeFixed1(u.Elem()) {
if isByte(u.Elem()) {
codegen.genSlice1(path, u)
} else {
codegen.genSlice(path, u, obj)
......@@ -1258,3 +1251,9 @@ func generateCodecCode(typespec *ast.TypeSpec, codegen CodeGenerator) string {
return codegen.generatedCode()
}
// isByte returns whether typ represents byte.
func isByte(typ types.Type) bool {
t, ok := typ.(*types.Basic)
return ok && t.Kind() == types.Byte
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment