mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-01 19:58:15 +00:00
Dart: binary lists (typed_data) (#6839)
* Dart - add eager mode to Uint8ListReader * Dart - add Int8ListReader * Dart - use binary reader where useful * Dart - test binary list reader laziness * Dart - update generated code
This commit is contained in:
@@ -658,15 +658,25 @@ class BuilderTest {
|
||||
List<int> byteList;
|
||||
{
|
||||
Builder builder = Builder(initialSize: 0);
|
||||
int offset = builder.writeListUint8(<int>[1, 2, 3, 4, 0x9A]);
|
||||
int offset = builder.writeListUint8(<int>[1, 2, 3, 4, 0x9A, 0xFA]);
|
||||
builder.finish(offset);
|
||||
byteList = builder.buffer;
|
||||
}
|
||||
// read and verify
|
||||
BufferContext buf = BufferContext.fromBytes(byteList);
|
||||
List<int> items = const Uint8ListReader().read(buf, 0);
|
||||
expect(items, hasLength(5));
|
||||
expect(items, orderedEquals(<int>[1, 2, 3, 4, 0x9A]));
|
||||
const buffOffset = 8; // 32-bit offset to the list, + 32-bit length
|
||||
for (final lazy in [true, false]) {
|
||||
List<int> items = Uint8ListReader(lazy: lazy).read(buf, 0);
|
||||
expect(items, hasLength(6));
|
||||
expect(items, orderedEquals(<int>[1, 2, 3, 4, 0x9A, 0xFA]));
|
||||
|
||||
// overwrite the buffer to verify the laziness
|
||||
buf.buffer.setUint8(buffOffset + 1, 99);
|
||||
expect(items, orderedEquals(<int>[1, lazy ? 99 : 2, 3, 4, 0x9A, 0xFA]));
|
||||
|
||||
// restore the previous value for the next loop
|
||||
buf.buffer.setUint8(buffOffset + 1, 2);
|
||||
}
|
||||
}
|
||||
|
||||
void test_reset() {
|
||||
|
||||
Reference in New Issue
Block a user