-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use flatbuffers to serialize dtypes (#126)
- Loading branch information
1 parent
0199f4d
commit 10ad5af
Showing
8 changed files
with
532 additions
and
356 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use std::env; | ||
use std::ffi::OsStr; | ||
use std::path::{Path, PathBuf}; | ||
use std::process::Command; | ||
|
||
use flatc::flatc; | ||
use walkdir::WalkDir; | ||
|
||
fn main() { | ||
let flatbuffers_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()) | ||
.canonicalize() | ||
.expect("Failed to canonicalize CARGO_MANIFEST_DIR") | ||
.join("flatbuffers"); | ||
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap()) | ||
.canonicalize() | ||
.expect("Failed to canonicalize OUT_DIR"); | ||
|
||
let fbs_files = WalkDir::new(flatbuffers_dir) | ||
.into_iter() | ||
.filter_map(|e| e.ok()) | ||
.filter(|e| e.path().extension() == Some(OsStr::new("fbs"))) | ||
.map(|e| { | ||
rerun_if_changed(e.path()); | ||
e.path().to_path_buf() | ||
}) | ||
.collect::<Vec<_>>(); | ||
|
||
if !Command::new(flatc()) | ||
.args(["--filename-suffix", ""]) | ||
.arg("--rust") | ||
.arg("-o") | ||
.arg(out_dir.join("flatbuffers")) | ||
.args(fbs_files) | ||
.status() | ||
.unwrap() | ||
.success() | ||
{ | ||
panic!("Failed to run flatc"); | ||
} | ||
} | ||
|
||
fn rerun_if_changed(path: &Path) { | ||
println!( | ||
"cargo:rerun-if-changed={}", | ||
path.canonicalize() | ||
.unwrap_or_else(|_| panic!("failed to canonicalize {}", path.to_str().unwrap())) | ||
.to_str() | ||
.unwrap() | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
enum Nullability: byte { | ||
NonNullable, | ||
Nullable, | ||
} | ||
|
||
enum Signedness: byte { | ||
Signed, | ||
Unsigned, | ||
Unknown, | ||
} | ||
|
||
enum IntWidth: byte { | ||
Unknown, | ||
_8, | ||
_16, | ||
_32, | ||
_64, | ||
} | ||
|
||
enum FloatWidth: byte { | ||
Unknown, | ||
_16, | ||
_32, | ||
_64, | ||
} | ||
|
||
table Null {} | ||
|
||
table Bool { | ||
nullability: Nullability; | ||
} | ||
|
||
table Int { | ||
width: IntWidth = Unknown; | ||
signedness: Signedness = Unknown; | ||
nullability: Nullability; | ||
} | ||
|
||
table Decimal { | ||
/// Total number of decimal digits | ||
precision: ubyte; | ||
|
||
/// Number of digits after the decimal point "." | ||
scale: byte; | ||
nullability: Nullability; | ||
} | ||
|
||
table Float { | ||
width: FloatWidth = Unknown; | ||
nullability: Nullability; | ||
} | ||
|
||
table Utf8 { | ||
nullability: Nullability; | ||
|
||
} | ||
|
||
table Binary { | ||
nullability: Nullability; | ||
} | ||
|
||
table Struct_ { | ||
names: [string]; | ||
fields: [DType]; | ||
} | ||
|
||
table List { | ||
element_type: DType; | ||
nullability: Nullability; | ||
} | ||
|
||
table Composite { | ||
id: string; | ||
nullability: Nullability; | ||
} | ||
|
||
union Type { | ||
Null, | ||
Bool, | ||
Int, | ||
Decimal, | ||
Float, | ||
Utf8, | ||
Binary, | ||
Struct_, | ||
List, | ||
Composite, | ||
} | ||
|
||
table DType { | ||
type: Type; | ||
} | ||
|
||
root_type DType; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.