Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions dart/lib/flat_buffers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,31 @@ class Builder {
}
}

/// Prepare for writing a struct with the given [alignment] and [size].
///
/// Struct fields are written one at a time, so this only writes the padding
/// needed before the whole inline struct. Field writes still advance the tail.
@pragma('vm:prefer-inline')
void prepStruct(int alignment, int size) {
assert(!_finished);
if (_maxAlign < alignment) {
_maxAlign = alignment;
}
final alignDelta = (-(_tail + size)) & (alignment - 1);
final oldCapacity = _buf.lengthInBytes;
if (_tail + alignDelta > oldCapacity) {
final desiredNewCapacity = (oldCapacity + alignDelta) * 2;
var deltaCapacity = desiredNewCapacity - oldCapacity;
deltaCapacity += (-deltaCapacity) & (_maxAlign - 1);
final newCapacity = oldCapacity + deltaCapacity;
_buf = _allocator.resize(_buf, newCapacity, _tail, 0);
}
for (var i = _tail + 1; i <= _tail + alignDelta; i++) {
_setUint8AtTail(i, 0);
}
_tail += alignDelta;
}

/// Prepare for writing the given `count` of scalars of the given `size`.
/// Additionally allocate the specified `additionalBytes`. Update the current
/// tail pointer to point at the allocated space.
Expand Down
11 changes: 11 additions & 0 deletions dart/test/bool_structs.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,14 @@ struct foo_properties
a : bool;
b : bool;
}

// Test for #9099
struct Header {
time: ulong;
ident: ushort;
}

table Message {
prefix: ushort;
header: Header;
}
Loading