flatbuffers icon indicating copy to clipboard operation
flatbuffers copied to clipboard

Failure reading with Dart data written/read correctly with TypeScript.

Open lcrocker opened this issue 5 months ago • 0 comments

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? But that's just a no-op, right, changing the point of view on the same chunk of bytes?

lcrocker avatar Sep 12 '24 02:09 lcrocker