qykings / protobuf-actionscript3

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

ByteArray#endian will help you #25

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago

For example

class CodedOutputStream

public function writeRawLittleEndian64(value:Number):void {
    //tricky: BigInteger takes an array with heaviest byte first!
    //reverse from the stream

    var bytes:ByteArray = value.toByteArray();
    var b8:int = bytes.readByte();
    var b7:int = bytes.readByte();
    var b6:int = bytes.readByte();
    var b5:int = bytes.readByte();
    var b4:int = bytes.readByte();
    var b3:int = bytes.readByte();
    var b2:int = bytes.readByte();
    var b1:int = bytes.readByte();

    writeRawByte(b1);
    writeRawByte(b2);
    writeRawByte(b3);
    writeRawByte(b4);
    writeRawByte(b5);
    writeRawByte(b6);
    writeRawByte(b7);
    writeRawByte(b8);
}

Get ride to 
public function writeRawLittleEndian64(value:Number):void {
    //var endian:String = this.output.endian; // save if need
    this.output.endian = Endian.BIG_ENDIAN;
    this.output.writeByte(value);
    //this.output.endian = endian; // restore
}

Original issue reported on code.google.com by goodcore...@gmail.com on 19 Nov 2010 at 12:33