Commit 78a7f26b authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 28777de8
......@@ -463,54 +463,29 @@ func typeDecodingSizeFixed(encoding byte, typ types.Type) (wireSize int, ok bool
}
func typeRxTxSizeFixed(encoding byte, typ types.Type, rx bool) (wireSize int, ok bool) {
switch encoding {
default:
panic("bad encoding")
// pass typ through sizerM and see if encoded size is fixed or not
// XXX make something not fixed when rx=true?
var size SymSize
switch encoding {
case 'M':
// pass typ through sizerM and see if encoded size is fixed or not
// XXX make something not fixed when rx=true?
s := &sizerM{}
codegenType("x", typ, nil, s)
if !s.size.IsNumeric() { // no symbolic part
return 0, false
}
return s.size.num, true
size = s.size
case 'N':
// implemented below
// XXX also pass through sizerN ?
}
switch u := typ.Underlying().(type) {
case *types.Basic:
basic, ok := basicTypesN[u.Kind()]
if ok {
return basic.wireSize, ok
}
case *types.Struct:
for i := 0; i < u.NumFields(); i++ {
size, ok := typeEncodingSizeFixed(encoding, u.Field(i).Type())
if !ok {
goto notfixed
}
wireSize += size
}
return wireSize, true
s := &sizerN{}
codegenType("x", typ, nil, s)
size = s.size
case *types.Array:
elemSize, ok := typeEncodingSizeFixed(encoding, u.Elem())
if ok {
return int(u.Len()) * elemSize, ok
}
default:
panic("bad encoding")
}
notfixed:
// everything else is of not fixed wire size
return 0, false
if !size.IsNumeric() { // no symbolic part
return 0, false
}
return size.num, true
}
// interface of a codegenerator (for sizer/encoder/decoder)
......
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