Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/src/serialize.dart
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,9 @@ class SerialBuffer {

// /** Get a `float32` */
double getFloat32() {
return getUint8List(4).buffer.asFloat32List()[0];
var rp = readPos;
getUint8List(4);
return array.buffer.asByteData(rp).getFloat32(0, Endian.little);
}

// /** Append a `float64` */
Expand All @@ -229,7 +231,9 @@ class SerialBuffer {

// /** Get a `float64` */
double getFloat64() {
return getUint8List(8).buffer.asFloat64List()[0];
var rp = readPos;
getUint8List(8);
return array.buffer.asByteData(rp).getFloat64(0, Endian.little);
}

/// Append a `name` */
Expand Down
29 changes: 29 additions & 0 deletions test/eosdart_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,35 @@ import 'package:test/test.dart';

void main() {
const verbose = false;
group('float32 & float64 serdes', () {
final double floatval = 3.141590118408203; // an exact float32
final sb = new SerialBuffer(new Uint8List(0));
test('serialize', () {
sb.push([15]); // misalign by pushing 1 arbitrary byte
sb.pushFloat32(floatval);
sb.pushFloat64(floatval);
final serialized = sb.asUint8List();

if(verbose) {
print("floatval: $floatval");
print("serialized: $serialized\n"+" ${arrayToHex(serialized)}");
}
expect(serialized,
[15, 208, 15, 73, 64, 0, 0, 0, 0, 250, 33, 9, 64]);
});
test('deserialize', () {
sb.restartRead();
sb.get();
final v32 = sb.getFloat32();
final v64 = sb.getFloat64();
if(verbose) {
print("floatval32: $v32, floatval64: $v64");
}
expect([v32, v64],
[floatval, floatval]);
});
});

group('public keys', () {
test('serialize k1 old style', () {
final keystring = 'EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV';
Expand Down