Fix #6, testsuite implemented.
This commit is contained in:
parent
270302bb4b
commit
b359400c83
16 changed files with 268 additions and 3 deletions
|
@ -155,16 +155,20 @@ class ByteLayer {
|
|||
|
||||
void writeFloat(double value) {
|
||||
_ensureCapacity(4);
|
||||
// Round the float to 8 decimal places before writing
|
||||
value = double.parse(value.toStringAsFixed(8));
|
||||
_byteBuffer.buffer.asByteData().setFloat32(_position, value, Endian.big);
|
||||
_position += 2;
|
||||
_position += 4;
|
||||
}
|
||||
|
||||
double readFloat() {
|
||||
final value =
|
||||
_byteBuffer.buffer.asByteData().getFloat32(_position, Endian.big);
|
||||
|
||||
_position += 2;
|
||||
return value;
|
||||
_position += 4;
|
||||
|
||||
// Round the float to 8 decimal places after reading
|
||||
return double.parse(value.toStringAsFixed(8));
|
||||
}
|
||||
|
||||
void writeTagName(String name) {
|
||||
|
@ -234,4 +238,49 @@ class ByteLayer {
|
|||
_position += 8;
|
||||
return value;
|
||||
}
|
||||
|
||||
void writeVarLongNoZigZag(int value) {
|
||||
while (true) {
|
||||
if ((value & ~0x7F) == 0) {
|
||||
writeByte(value);
|
||||
return;
|
||||
}
|
||||
writeByte((value & 0x7F) | 0x80);
|
||||
value = value >> 7;
|
||||
}
|
||||
}
|
||||
|
||||
void writeVarLongZigZag(int value) {
|
||||
value = (value << 1) ^ (value >> 63);
|
||||
writeVarLongNoZigZag(value);
|
||||
}
|
||||
|
||||
void writeLongZigZag(int value) {
|
||||
value = (value << 1) & (value >> 63);
|
||||
_byteBuffer.buffer.asByteData().setInt64(_position, value, Endian.big);
|
||||
}
|
||||
|
||||
int readVarLongNoZigZag() {
|
||||
int result = 0;
|
||||
int shift = 0;
|
||||
int b;
|
||||
|
||||
do {
|
||||
b = readByte();
|
||||
result |= (b & 0x7F) << shift;
|
||||
shift += 7;
|
||||
} while ((b & 0x80) != 0);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int readVarLongZigZag() {
|
||||
int result = readVarLongNoZigZag();
|
||||
return (result >> 1) ^ -(result & 1);
|
||||
}
|
||||
|
||||
int readLongZigZag() {
|
||||
int value = readLong();
|
||||
return (value >> 1) ^ (-(value & 1));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue