Skip to content

Commit

Permalink
fix final alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
clickingbuttons committed Feb 1, 2024
1 parent eb0b0da commit e8c2bdb
Show file tree
Hide file tree
Showing 19 changed files with 305 additions and 54 deletions.
6 changes: 3 additions & 3 deletions build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
.{
.name = "flatbuffers",
.version = "0.0.2",
.version = "0.0.3",
.dependencies = .{
.clap = .{
.url = "https://github.com/Hejsil/zig-clap/archive/f49b94700e0761b7514abdca0e4f0e7f3f938a93.tar.gz",
.hash = "1220f48518ce22882e102255ed3bcdb7aeeb4891f50b2cdd3bd74b5b2e24d3149ba2"
},
.flatbuffers = .{
.url = "https://github.com/clickingbuttons/flatbuffers/archive/refs/tags/0.0.3.tar.gz",
.hash = "122049e1449018ff433beb3e5ee6107d081e561a93744b9ee59bd485acf23beb6f61"
.url = "https://github.com/clickingbuttons/flatbuffers/archive/refs/tags/0.0.4.tar.gz",
.hash = "122094e2b1ae9ef4b8bc50ecde2ee886aab1d4bf2e8b648927b53b48f7810b60e243"
},
}
}
22 changes: 18 additions & 4 deletions codegen/examples/arrow-cpp/test.zig
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
const std = @import("std");
const Builder = @import("flatbuffers").Builder;
const example_footer = @import("../arrow/test.zig").example_footer;
const samples = @import("../arrow/test.zig");

const testing = std.testing;

extern fn verifySchema(buf: [*]c_char, len: usize) bool;
extern fn verifyMessage(buf: [*]c_char, len: usize) bool;
extern fn verifyFooter(buf: [*]c_char, len: usize) bool;

test "arrow cpp verifies flatbuffer" {
fn verifyPack(comptime s: anytype, comptime verifier: anytype) !void {
var builder = Builder.init(testing.allocator);
const offset = try example_footer.pack(&builder);
const offset = try s.pack(&builder);
const bytes = try builder.finish(offset);
defer testing.allocator.free(bytes);

try std.testing.expectEqual(true, verifyFooter(@ptrCast(bytes.ptr), bytes.len));
try std.testing.expectEqual(true, verifier(@ptrCast(bytes.ptr), bytes.len));
}

test "arrow cpp verifies schema flatbuffer" {
try verifyPack(samples.example_schema, verifySchema);
}

test "arrow cpp verifies message flatbuffer" {
try verifyPack(samples.example_message, verifyMessage);
}

test "arrow cpp verifies footer flatbuffer" {
try verifyPack(samples.example_footer, verifyFooter);
}
22 changes: 22 additions & 0 deletions codegen/examples/arrow-cpp/verify.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
#include "Schema_generated.h"
#include "Message_generated.h"
#include "File_generated.h"

extern "C" bool verifySchema(char* buf, size_t len) {
const Schema* schema = GetSchema(buf);

flatbuffers::Verifier verifier(
(const uint8_t*) buf, len,
/*max_depth=*/128,
/*max_tables=*/static_cast<flatbuffers::uoffset_t>(8 * len));
return schema->Verify(verifier);
}

extern "C" bool verifyMessage(char* buf, size_t len) {
const Message* message = GetMessage(buf);

flatbuffers::Verifier verifier(
(const uint8_t*) buf, len,
/*max_depth=*/128,
/*max_tables=*/static_cast<flatbuffers::uoffset_t>(8 * len));
return message->Verify(verifier);
}

extern "C" bool verifyFooter(char* buf, size_t len) {
const Footer* footer = GetFooter(buf);

Expand Down
16 changes: 16 additions & 0 deletions codegen/examples/arrow/Message.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,22 @@ table RecordBatch {

/// Optional compression of the message body
compression: BodyCompression;

/// Some types such as Utf8View are represented using a variable number of buffers.
/// For each such Field in the pre-ordered flattened logical schema, there will be
/// an entry in variadicBufferCounts to indicate the number of number of variadic
/// buffers which belong to that Field in the current RecordBatch.
///
/// For example, the schema
/// col1: Struct<alpha: Int32, beta: BinaryView, gamma: Float64>
/// col2: Utf8View
/// contains two Fields with variadic buffers so variadicBufferCounts will have
/// two entries, the first counting the variadic buffers of `col1.beta` and the
/// second counting `col2`'s.
///
/// This field may be omitted if and only if the schema contains no Fields with
/// a variable number of buffers, such as BinaryView and Utf8View.
variadicBufferCounts: [long];
}

/// For sending dictionary encoding information. Any Field can be
Expand Down
25 changes: 0 additions & 25 deletions codegen/examples/arrow/README.rst

This file was deleted.

44 changes: 41 additions & 3 deletions codegen/examples/arrow/Schema.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
/// Version 1.1 - Add Decimal256.
/// Version 1.2 - Add Interval MONTH_DAY_NANO.
/// Version 1.3 - Add Run-End Encoded.
/// Version 1.4 - Add BinaryView, Utf8View, variadicBufferCounts, ListView, and
/// LargeListView.

enum MetadataVersion:short {
/// 0.1.0 (October 2016).
Expand All @@ -36,7 +38,7 @@ enum MetadataVersion:short {
/// >= 0.8.0 (December 2017). Non-backwards compatible with V3.
V4,

/// >= 1.0.0 (July 2020. Backwards compatible with V4 (V5 readers can read V4
/// >= 1.0.0 (July 2020). Backwards compatible with V4 (V5 readers can read V4
/// metadata and IPC messages). Implementations are recommended to provide a
/// V4 compatibility mode with V5 format changes disabled.
///
Expand Down Expand Up @@ -94,6 +96,17 @@ table List {
table LargeList {
}

/// Represents the same logical types that List can, but contains offsets and
/// sizes allowing for writes in any order and sharing of child values among
/// list values.
table ListView {
}

/// Same as ListView, but with 64-bit offsets and sizes, allowing to represent
/// extremely large data values.
table LargeListView {
}

table FixedSizeList {
/// Number of list items per value
listSize: int;
Expand Down Expand Up @@ -169,6 +182,27 @@ table LargeUtf8 {
table LargeBinary {
}

/// Logically the same as Utf8, but the internal representation uses a view
/// struct that contains the string length and either the string's entire data
/// inline (for small strings) or an inlined prefix, an index of another buffer,
/// and an offset pointing to a slice in that buffer (for non-small strings).
///
/// Since it uses a variable number of data buffers, each Field with this type
/// must have a corresponding entry in `variadicBufferCounts`.
table Utf8View {
}

/// Logically the same as Binary, but the internal representation uses a view
/// struct that contains the string length and either the string's entire data
/// inline (for small strings) or an inlined prefix, an index of another buffer,
/// and an offset pointing to a slice in that buffer (for non-small strings).
///
/// Since it uses a variable number of data buffers, each Field with this type
/// must have a corresponding entry in `variadicBufferCounts`.
table BinaryView {
}


table FixedSizeBinary {
/// Number of bytes per value
byteWidth: int;
Expand All @@ -179,7 +213,7 @@ table Bool {

/// Contains two child arrays, run_ends and values.
/// The run_ends child array must be a 16/32/64-bit integer array
/// which encodes the indices at which the run with the value in
/// which encodes the indices at which the run with the value in
/// each corresponding index in the values child array ends.
/// Like list/struct types, the value array can be of any type.
table RunEndEncoded {
Expand Down Expand Up @@ -336,7 +370,7 @@ table Time {
/// no indication of how to map this information to a physical point in time.
/// Naive date-times must be handled with care because of this missing
/// information, and also because daylight saving time (DST) may make
/// some values ambiguous or non-existent. A naive date-time may be
/// some values ambiguous or nonexistent. A naive date-time may be
/// stored as a struct with Date and Time fields. However, it may also be
/// encoded into a Timestamp column with an empty timezone. The timestamp
/// values should be computed "as if" the timezone of the date-time values
Expand Down Expand Up @@ -425,6 +459,10 @@ union Type {
LargeUtf8,
LargeList,
RunEndEncoded,
BinaryView,
Utf8View,
ListView,
LargeListView,
}

/// ----------------------------------------------------------------------
Expand Down
29 changes: 29 additions & 0 deletions codegen/examples/arrow/gen/BinaryView.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//! generated by flatc-zig from Schema.fbs

const flatbuffers = @import("flatbuffers");

/// Logically the same as Binary, but the internal representation uses a view
/// struct that contains the string length and either the string's entire data
/// inline (for small strings) or an inlined prefix, an index of another buffer,
/// and an offset pointing to a slice in that buffer (for non-small strings).
///
/// Since it uses a variable number of data buffers, each Field with this type
/// must have a corresponding entry in `variadicBufferCounts`.
pub const BinaryView = struct {
const Self = @This();

pub fn pack(self: Self, builder: *flatbuffers.Builder) flatbuffers.Error!u32 {
_ = self;
try builder.startTable();
return builder.endTable();
}
};

/// Logically the same as Binary, but the internal representation uses a view
/// struct that contains the string length and either the string's entire data
/// inline (for small strings) or an inlined prefix, an index of another buffer,
/// and an offset pointing to a slice in that buffer (for non-small strings).
///
/// Since it uses a variable number of data buffers, each Field with this type
/// must have a corresponding entry in `variadicBufferCounts`.
pub const PackedBinaryView = struct {};
4 changes: 1 addition & 3 deletions codegen/examples/arrow/gen/DictionaryEncoding.zig
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ pub const DictionaryEncoding = struct {
const Self = @This();

pub fn init(packed_: PackedDictionaryEncoding) flatbuffers.Error!Self {
const index_type_ = if (try packed_.indexType()) |i| try types.Int.init(i) else null;
errdefer {}
return .{
.id = try packed_.id(),
.index_type = index_type_,
.index_type = try packed_.indexType(),
.is_ordered = try packed_.isOrdered(),
.dictionary_kind = try packed_.dictionaryKind(),
};
Expand Down
4 changes: 1 addition & 3 deletions codegen/examples/arrow/gen/Field.zig
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ pub const Field = struct {
errdefer {
@"type".deinit(allocator);
}
const dictionary_ = if (try packed_.dictionary()) |d| try types.DictionaryEncoding.init(d) else null;
errdefer {}
const children_ = try flatbuffers.unpackVector(allocator, types.Field, packed_, "children");
errdefer {
for (children_) |c| c.deinit(allocator);
Expand All @@ -49,7 +47,7 @@ pub const Field = struct {
.name = name_,
.nullable = try packed_.nullable(),
.type = @"type",
.dictionary = dictionary_,
.dictionary = try packed_.dictionary(),
.children = children_,
.custom_metadata = custom_metadata_,
};
Expand Down
19 changes: 19 additions & 0 deletions codegen/examples/arrow/gen/LargeListView.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//! generated by flatc-zig from Schema.fbs

const flatbuffers = @import("flatbuffers");

/// Same as ListView, but with 64-bit offsets and sizes, allowing to represent
/// extremely large data values.
pub const LargeListView = struct {
const Self = @This();

pub fn pack(self: Self, builder: *flatbuffers.Builder) flatbuffers.Error!u32 {
_ = self;
try builder.startTable();
return builder.endTable();
}
};

/// Same as ListView, but with 64-bit offsets and sizes, allowing to represent
/// extremely large data values.
pub const PackedLargeListView = struct {};
21 changes: 21 additions & 0 deletions codegen/examples/arrow/gen/ListView.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//! generated by flatc-zig from Schema.fbs

const flatbuffers = @import("flatbuffers");

/// Represents the same logical types that List can, but contains offsets and
/// sizes allowing for writes in any order and sharing of child values among
/// list values.
pub const ListView = struct {
const Self = @This();

pub fn pack(self: Self, builder: *flatbuffers.Builder) flatbuffers.Error!u32 {
_ = self;
try builder.startTable();
return builder.endTable();
}
};

/// Represents the same logical types that List can, but contains offsets and
/// sizes allowing for writes in any order and sharing of child values among
/// list values.
pub const PackedListView = struct {};
4 changes: 3 additions & 1 deletion codegen/examples/arrow/gen/MetadataVersion.zig
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
/// Version 1.1 - Add Decimal256.
/// Version 1.2 - Add Interval MONTH_DAY_NANO.
/// Version 1.3 - Add Run-End Encoded.
/// Version 1.4 - Add BinaryView, Utf8View, variadicBufferCounts, ListView, and
/// LargeListView.
pub const MetadataVersion = enum(i16) {
/// 0.1.0 (October 2016).
v1 = 0,
Expand All @@ -15,7 +17,7 @@ pub const MetadataVersion = enum(i16) {
v3 = 2,
/// >= 0.8.0 (December 2017). Non-backwards compatible with V3.
v4 = 3,
/// >= 1.0.0 (July 2020. Backwards compatible with V4 (V5 readers can read V4
/// >= 1.0.0 (July 2020). Backwards compatible with V4 (V5 readers can read V4
/// metadata and IPC messages). Implementations are recommended to provide a
/// V4 compatibility mode with V5 format changes disabled.
///
Expand Down
Loading

0 comments on commit e8c2bdb

Please sign in to comment.