flatbuffers
flatbuffers copied to clipboard
Failure reading with Dart data written/read correctly with TypeScript.
flatc 24.3.25, running on Linux. Here's the schema:
namespace Oj;
table MasterDeck {
name: string;
dups_allowed: bool;
low_aces: bool;
q_is_knight: bool;
aliases: [string];
card_list: [int8];
}
table MasterDeckList {
count: int32;
list: [MasterDeck];
}
root_type MasterDeckList;
I made a TypeScript script to create a bin file, and successfully read it back. No issues there. I then ran flatc to create Dart code, tried to read the binary with this code:
class MasterDeck {
static oj.MasterDeckList? mdl;
static Future<void> load() async {
// makes no difference between reading file and asset
final ByteData data = await rootBundle.load('assets/master_decks.bin');
// var file = File('./assets/master_decks.bin');
// var data = file.readAsBytesSync();
debugPrint("data: ${data.lengthInBytes}");
final List<int> bytes = data.buffer.asInt64List();
mdl = oj.MasterDeckList(bytes);
debugPrint("count: ${mdl!.count}");
debugPrint("list: ${mdl!.list}");
}
}
This results in the output:
flutter: data: 2572
flutter: count: 4
flutter: list: null
There are 18 decks in the list, so count should be 18, and list, obviously, should not be null. Something isn't lining up right. Perhaps the way the ByteData is being converted to List