Commit e1c25b29 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 0e028e1c
......@@ -452,19 +452,9 @@ var basicTypesN = map[types.BasicKind]basicCodecN{
types.Float64: {8, "float64_neoEncode(%v, %v)", "float64_neoDecode(%v)"},
}
// does a type have fixed wire size when encoded and, if yes, what it is?
func typeEncodingSizeFixed(encoding byte, typ types.Type) (wireSize int, ok bool) {
return typeRxTxSizeFixed(encoding, typ, false)
}
// does a type always have fixed wire size when we are decoding it from
// a packet received from outside? if yes, what size it is?
func typeDecodingSizeFixed(encoding byte, typ types.Type) (wireSize int, ok bool) {
return typeRxTxSizeFixed(encoding, typ, true)
}
func typeRxTxSizeFixed(encoding byte, typ types.Type, rx bool) (wireSize int, ok bool) {
// pass typ through sizerM and see if encoded size is fixed or not
// XXX make something not fixed when rx=true?
// does a type have fixed wire size and, if yes, what it is?
func typeSizeFixed(encoding byte, typ types.Type) (wireSize int, ok bool) {
// pass typ through sizer and see if encoded size is fixed or not
var size SymSize
switch encoding {
......@@ -1396,7 +1386,7 @@ func (s *sizerCommon) genSliceCommon(xs CodeGenCustomize, path string, typ *type
xs.genSliceHead(path, typ, obj)
// if size(item)==const - size update in one go
elemSize, ok := typeEncodingSizeFixed(xs.encoding(), typ.Elem())
elemSize, ok := typeSizeFixed(xs.encoding(), typ.Elem())
if ok {
s.size.AddExpr("len(%v) * %v", path, elemSize)
return
......@@ -1457,7 +1447,7 @@ func (d *decoderCommon) genSliceCommon(xd CodeGenCustomize, assignto string, typ
d.resetPos()
// if size(item)==const - check overflow in one go
elemSize, elemFixed := typeDecodingSizeFixed(xd.encoding(), typ.Elem())
elemSize, elemFixed := typeSizeFixed(xd.encoding(), typ.Elem())
if elemFixed {
d.overflowCheck()
d.overflow.AddExpr("uint64(l) * %v", elemSize)
......@@ -1530,8 +1520,8 @@ func (s *sizerN) genMap(path string, typ *types.Map, obj types.Object) {
func (s *sizerCommon) genMapCommon(xs CodeGenCustomize, path string, typ *types.Map, obj types.Object) {
xs.genMapHead(path, typ, obj)
keySize, keyFixed := typeEncodingSizeFixed(xs.encoding(), typ.Key())
elemSize, elemFixed := typeEncodingSizeFixed(xs.encoding(), typ.Elem())
keySize, keyFixed := typeSizeFixed(xs.encoding(), typ.Key())
elemSize, elemFixed := typeSizeFixed(xs.encoding(), typ.Elem())
if keyFixed && elemFixed {
s.size.AddExpr("len(%v) * %v", path, keySize+elemSize)
......@@ -1602,8 +1592,8 @@ func (d *decoderCommon) genMapCommon(xd CodeGenCustomize, assignto string, typ *
d.resetPos()
// if size(key,item)==const - check overflow in one go
keySize, keyFixed := typeDecodingSizeFixed(xd.encoding(), typ.Key())
elemSize, elemFixed := typeDecodingSizeFixed(xd.encoding(), typ.Elem())
keySize, keyFixed := typeSizeFixed(xd.encoding(), typ.Key())
elemSize, elemFixed := typeSizeFixed(xd.encoding(), typ.Elem())
if keyFixed && elemFixed {
d.overflowCheck()
d.overflow.AddExpr("uint64(l) * %v", keySize+elemSize)
......
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