jonny91 / protoc-gen-as3

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

double and float values were wrong. #27

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

1. Create [.proto] file.

    message DoubleFloat {
       optional double myDouble = 1;
       optional float myFloat = 2;
    }

2. Run this program.

    var values:DoubleFloat = new DoubleFloat();
    values.myDouble = 1.0;
    values.myFloat  = 1.0;

    var bytes:ByteArray = new ByteArray();
    values.writeTo(bytes);

    trace(bytes[0].toString(16));   // 09 -- correct
    trace(bytes[1].toString(16));   // 00 -- correct
    trace(bytes[2].toString(16));   // 00 -- correct
    trace(bytes[3].toString(16));   // 00 -- correct
    trace(bytes[4].toString(16));   // 00 -- correct
    trace(bytes[5].toString(16));   // 00 -- correct
    trace(bytes[6].toString(16));   // 00 -- correct
    trace(bytes[7].toString(16));   // F0 -- correct
    trace(bytes[8].toString(16));   // 3F -- correct

    trace(bytes[9].toString(16));   // 15 -- correct
    trace(bytes[10].toString(16));  // 00 -- correct
    trace(bytes[11].toString(16));  // 00 -- correct
    trace(bytes[12].toString(16));  // 80 -- correct
    trace(bytes[13].toString(16));  // 3F -- correct

    bytes.position = 0;
    var loaded:DoubleFloat = new DoubleFloat();
    loaded.readFromSlice(bytes, 0);

    bytes.clear()
    loaded.writeTo(bytes);

    trace(bytes[0].toString(16));   // 09 -- correct
    trace(bytes[1].toString(16));   // 3F -- wrong(It is big endian!)
    trace(bytes[2].toString(16));   // F0 -- wrong(It is big endian!)
    trace(bytes[3].toString(16));   // 00 -- correct
    trace(bytes[4].toString(16));   // 00 -- correct
    trace(bytes[5].toString(16));   // 00 -- correct
    trace(bytes[6].toString(16));   // 00 -- correct
    trace(bytes[7].toString(16));   // 00 -- wrong(It is big endian!)
    trace(bytes[8].toString(16));   // 00 -- wrong(It is big endian!)

    trace(bytes[9].toString(16));   // 15 -- correct
    trace(bytes[10].toString(16));  // 3F -- wrong(It is big endian!)
    trace(bytes[11].toString(16));  // 80 -- wrong(It is big endian!)
    trace(bytes[12].toString(16));  // 00 -- wrong(It is big endian!)
    trace(bytes[13].toString(16));  // 00 -- wrong(It is big endian!)

    bytes.position = 0;
    var loaded2:DoubleFloat = new DoubleFloat();
    loaded2.readFromSlice(bytes, 0);

    bytes.clear()
    loaded2.writeTo(bytes);

    trace(bytes[0].toString(16));   // 09 -- correct
    trace(bytes[1].toString(16));   // 00 -- correct
    trace(bytes[2].toString(16));   // 00 -- correct
    trace(bytes[3].toString(16));   // 00 -- correct
    trace(bytes[4].toString(16));   // 00 -- correct
    trace(bytes[5].toString(16));   // 00 -- correct
    trace(bytes[6].toString(16));   // 00 -- correct
    trace(bytes[7].toString(16));   // F0 -- correct
    trace(bytes[8].toString(16));   // 3F -- correct

    trace(bytes[9].toString(16));   // 15 -- correct
    trace(bytes[10].toString(16));  // 00 -- correct
    trace(bytes[11].toString(16));  // 00 -- correct
    trace(bytes[12].toString(16));  // 80 -- correct
    trace(bytes[13].toString(16));  // 3F -- correct

What is the expected output? What do you see instead?

    The ByteArray should keep same values anytime.

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

    1.0.0-rc6

Please provide any additional information below.

Original issue reported on code.google.com by mk.trans...@gmail.com on 6 Feb 2012 at 11:00

GoogleCodeExporter commented 8 years ago
readFromSlice() is an internal method. This method should only be called from 
generated code, not from you.

Original comment by pop.atry@gmail.com on 6 Feb 2012 at 2:02