generate: cast integers when decoding
This commit is contained in:
parent
0097dbeedd
commit
de6099fadc
@ -491,16 +491,35 @@ func (this *Generator) generateDecodeValue(typ Type, typeName, valueSource, tagS
|
|||||||
// LI/LSI: <value: IntN>
|
// LI/LSI: <value: IntN>
|
||||||
if typ.Bits <= 5 {
|
if typ.Bits <= 5 {
|
||||||
// SI stores the value in the tag
|
// SI stores the value in the tag
|
||||||
nn, err := this.iprintf("*%s = uint8(%s.CN())\n", valueSource, tagSource)
|
if typeName == "" {
|
||||||
n += nn; if err != nil { return n, err }
|
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
|
break
|
||||||
}
|
}
|
||||||
prefix := "ReadUint"
|
prefix := "ReadUint"
|
||||||
if typ.Signed {
|
if typ.Signed {
|
||||||
prefix = "ReadInt"
|
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 }
|
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()
|
nn, err = this.generateErrorCheck()
|
||||||
n += nn; if err != nil { return n, err }
|
n += nn; if err != nil { return n, err }
|
||||||
case TypeFloat:
|
case TypeFloat:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user