Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
lcrocker opened this issue Sep 12, 2024 · 0 comments
Open

Comments

@lcrocker
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant