generate: cast integers when decoding

This commit is contained in:
Sasha Koshka 2025-08-27 00:43:10 -04:00
parent 0097dbeedd
commit de6099fadc

View File

@ -491,16 +491,35 @@ func (this *Generator) generateDecodeValue(typ Type, typeName, valueSource, tagS
// LI/LSI: <value: IntN>
if typ.Bits <= 5 {
// SI stores the value in the tag
nn, err := this.iprintf("*%s = uint8(%s.CN())\n", valueSource, tagSource)
n += nn; if err != nil { return n, err }
if typeName == "" {
nn, err := this.iprintf("*%s = uint8(%s.CN())\n", valueSource, tagSource)
n += nn; if err != nil { return n, err }
} else {
nn, err := this.iprintf("*%s = %s(%s.CN())\n", valueSource, typeName, tagSource)
n += nn; if err != nil { return n, err }
}
break
}
prefix := "ReadUint"
if typ.Signed {
prefix = "ReadInt"
}
nn, err := this.iprintf("*%s, nn, err = decoder.%s%d()\n", valueSource, prefix, typ.Bits)
destinationVar := this.newTemporaryVar("destination")
nn, err := this.iprintf("var %s ", destinationVar)
n += nn; if err != nil { return n, err }
nn, err = this.generateType(typ)
n += nn; if err != nil { return n, err }
nn, err = this.print("\n")
n += nn; if err != nil { return n, err }
nn, err = this.iprintf("%s, nn, err = decoder.%s%d()\n", destinationVar, prefix, typ.Bits)
n += nn; if err != nil { return n, err }
if typeName == "" {
nn, err := this.iprintf("*%s = %s\n", valueSource, destinationVar)
n += nn; if err != nil { return n, err }
} else {
nn, err := this.iprintf("*%s = %s(%s)\n", valueSource, typeName, destinationVar)
n += nn; if err != nil { return n, err }
}
nn, err = this.generateErrorCheck()
n += nn; if err != nil { return n, err }
case TypeFloat: