google / google/flatbuffers

[Dart] Enums with "bit_flags" cannot be used as bit flags

Open
#9,087 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
26.5k
Forks
3.7k
PR merge metrics
No merged PRs in 30d

Description

Reading a bit_flags enum where multiple values are set throws an exception:

```
Unhandled exception:
RangeError (byteOffset): Index out of range: no indices are valid: 3
#0 _byteDataByteOffsetCheck (dart:typed_data-patch/typed_data_patch.dart:5419:5)
#1 _ByteDataView.getUint32 (dart:typed_data-patch/typed_data_patch.dart:5191:5)
#2 BufferContext._getUint32 (package:flat_buffers/flat_buffers.dart:68:41)
#3 BufferContext.derefObject (package:flat_buffers/flat_buffers.dart:40:43)
#4 TableReader.read (package:flat_buffers/flat_buffers.dart:1119:29)
...
```

Schema:
```
enum DigitalInputs: ubyte (bit_flags) {
DI_CLK1,
DI_CLK2,
DI_S1,
DI_S2,
}

table Holder {
digital_inputs: DigitalInputs;
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.