Atry / protoc-gen-as3

Automatically exported from code.google.com/p/protoc-gen-as3
BSD 2-Clause "Simplified" License
55 stars 18 forks source link

endian should be restored #22

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Thanks a lot for the library. It is very useful.

com.netease.protobuf.Message class changes the input's endian attribute when 
reading data.

I think it should be restored. I have had problems reading from a socket. I was 
reading data encoding with protobuf but also unencoded data. The first 
socket.readShort() was correct but the next, after reading a protobuf chunk,  
were wrong. I solved it setting back the endian attr to 
flash.utils.Endian.BIG_ENDIAN but I'd prefer that the library didn't interfere.

ACTUAL CODE:
public final function mergeFrom(input:IDataInput):void {
    input.endian = flash.utils.Endian.LITTLE_ENDIAN
    readFromSlice(input, 0)
}
public final function mergeDelimitedFrom(input:IDataInput):void {
    input.endian = flash.utils.Endian.LITTLE_ENDIAN
    ReadUtils.read$TYPE_MESSAGE(input, this)
}

PROPOSED CODE:
public final function mergeFrom(input:IDataInput):void {
    const endian:String = input.endian
    input.endian = flash.utils.Endian.LITTLE_ENDIAN
    readFromSlice(input, 0)
    input.endian = endian
}
public final function mergeDelimitedFrom(input:IDataInput):void {
    const endian:String = input.endian
    input.endian = flash.utils.Endian.LITTLE_ENDIAN
    ReadUtils.read$TYPE_MESSAGE(input, this)
    input.endian = endian
}

Original issue reported on code.google.com by ppr...@gmail.com on 6 Nov 2011 at 11:06

GoogleCodeExporter commented 9 years ago
mergeFrom and mergeDelimitedFrom never promise not to change IDataInput's 
state. It *does* apply side effects. For example, when you read from a 
ByteArray, the ByteArray's position will change. Anyway, I will indicate all 
side effects in ASDoc.

Original comment by pop.atry@gmail.com on 8 Nov 2011 at 12:49

GoogleCodeExporter commented 9 years ago
The asdoc is added in changeset f266ca92d300.

Original comment by pop.atry@gmail.com on 8 Nov 2011 at 1:27