philippepascal / protobuf-actionscript3

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

A little bug on String "" #8

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
we are using the lib on our project and find a bug when we decode binarys
from python: when the proto include a field equals "". 

Here is the reason : Lind 467 of CodedInputStream.as:

      public function readRawBytes(size:int):ByteArray {
        if (size < 0) {
          throw InvalidProtocolBufferException.negativeSize();
        }

        //lame, wait until buffer is full enough
        //while (bytesAvailable() < size) {}            

        var bytes:ByteArray = new ByteArray();
        if ( size == 0)
            return bytes;
        input.readBytes(bytes,0,size);

        return bytes;
      }

When the size == 0, input.readBytes(bytes,0,size); means read all available
data. So I add the  if ( size == 0)  return bytes; .

My partner James help me find the bug.

And Thanks a lot for  sorrydevil's work and other guys' discusson here.

Original issue reported on code.google.com by holybre...@gmail.com on 19 Aug 2009 at 12:59

GoogleCodeExporter commented 9 years ago
Fixed in 2.2. Thanks a lot for the contribution!

Original comment by sorrydevil@gmail.com on 13 Oct 2009 at 12:06

GoogleCodeExporter commented 9 years ago
I'm sorry. 
I'm weak in English.
Therefore I was supported by web translation.

(By the way, I am a Japanese not a Chinese.)

When getSerializedSize is done by using "repeated", 
InvalidProtocolBufferException is 
thrown out. 

// proto file
    message TestMessage {
        enum En { GAME_TYPE = 9001; MSG_TYPE = 1001; }
        repeated string member = 1;
    }

//my test code
    var msg:TestMessage = new TestMessage();
    msg.member[0]   = "hoge1";
    msg.member[1]   = "hoge2";
    msg.member[2]   = "hoge3";

    msg.getSerializedSize(); //< Throw InvalidProtocolBufferException

It causes because of not corresponding to the case for the above-mentioned 
source to 
use "repeated". 

Source inside
//add Array Type
~
// Add End

 is a code that I wrote. 

Would it support "repeated"?

Original comment by piggest0...@gmail.com on 7 Jan 2010 at 4:04