philippepascal / protobuf-actionscript3

Automatically exported from code.google.com/p/protobuf-actionscript3
13 stars 8 forks source link

writing & reading floats & doubles - problems and fixes #17

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago

What version of the product are you using? On what operating system?

r22
os x

Please provide any additional information below.

attached is a svn diff file which fixes two serious and two not-so-serious
issues around working with floats & doubles in revision 22.

Issue 1:
writing a float or a double will crash because the ByteArray in
writeRawFloat() is not rewound before calling readByte().
Solution:
add a "bytes.position = 0;" before the calls to readByte() in
writeRawFloat() and writeRawDouble().

Issue 2:
in the case where a float happens to have an integral value, it will be
written as an int32, but read as a float, causing a crash. This is because
if "value" happens to be integral (eg "123"), then AS3 evaluates the
expression "(value is uint)" as true, and the logic in writeField() breaks
down.
Solution:
move the two tests for is Number above the tests for integral types,
including Boolean.

Issue 3:
big integer import statement got lost from CodedOutputStream.as.
Solution:
re-add the BigInteger import to CodedOutputStream.as.

Issue 4:
compiler warnings around the return-type of writeDouble() and readDouble().
Solution:
change the return type of writeDouble() and readDouble() from BigInteger to
Number.

Original issue reported on code.google.com by DocOce...@gmail.com on 13 Jan 2010 at 12:09

Attachments:

GoogleCodeExporter commented 9 years ago
note, these fixes have been only minimally tested.

Original comment by DocOce...@gmail.com on 13 Jan 2010 at 12:13