-
Notifications
You must be signed in to change notification settings - Fork 10
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
Provide a complete EBNF or ANTLR-like grammar #127
Comments
Hi @net-yehor-tretiakov, can you tell us a little more about your use case? What languages are you targeting for code generation? What features are you hoping to have in the generated code? Is there something that you think is lacking from the existing parser/reader logic and data models in either Also, as a FYI, we are working on ISL-based codegen ourselves, and if you're interested, it would be great if we could combine our efforts or at least learn from what each other is doing. |
Sure! Ty for your reaction! I would try to describe my problem: Consider, that for some purpose we need to write a bunch of similar structures` encode and decode code using ion. As for start - with rust and js (btw i have faced some problems with incompatibilities, will create an issue later on). Code here is not an actual part of the project of mine, it is here just as example. // Some ecosystem stuff
pub trait Encoder {
fn encode(&self) -> Vec<u8>;
}
pub trait Decoder {
fn decode(data: &[u8]) -> Self;
}
// Structure to encode/decode
#[derive(Debug, PartialEq, Eq)]
pub struct SomeStruct {
some_data: Vec<u8>
}
/* Some structure impl code */
// Structure encode/decode
impl Encoder for SomeStruct {
fn encode(&self) -> Vec<u8> {
let buffer: Vec<u8> = Vec::new();
let binary_writer_builder = ion_rs::BinaryWriterBuilder::new();
let mut writer = binary_writer_builder.build(buffer).unwrap();
writer.step_in(ion_rs::IonType::Struct).expect("Error while creating an ion struct");
writer.set_field_name("some_data");
writer.write_blob(&self.some_data).unwrap();
writer.step_out().unwrap();
writer.flush().unwrap();
writer.output().deref().into()
}
}
impl Decoder for DataPacketDTO {
fn decode(data: &[u8]) -> Self {
let mut binary_user_reader = ion_rs::ReaderBuilder::new().build(data).unwrap();
binary_user_reader.next().unwrap();
binary_user_reader.step_in().unwrap();
binary_user_reader.next().unwrap();
let binding = binary_user_reader.read_blob().unwrap();
let some_data = binding.as_slice();
SomeStruct {
some_data
}
}
} Previously I have been using Cap'n Proto, in rust with providing by them codegen, but decide to use ion instead. Mb I am a bit blind, but I can not find anything in public API in ion-schema-rust that can help me... |
Also, @popematt, it would be interesting for me to hear about your own codegen! Would you mind sharing: I am familiar with code generation using go/java only tho. It would be a cool experience to learn new ways of doing so! |
I was messing around and created a very rough proof of concept a few months ago using Ion Schema Kotlin (see here and here). We're still doing research for this, so don't take any of this as a guarantee. I can make no promises of when—or even if—this will come to fruition. Since we already have libraries that can read ISL, we would use those. Some transformation would be required to interpret the ISL into a more "conventional" (e.g. Java-like) representation of a type model, and then it would be handed off to a template engine or maybe a handwritten generator to produce the actual code. Ideally, the generated code would come with ready-to-use APIs for serialization and deserialization between Ion and the generated data model. One thing is, I think, pretty safe to say—we have put a lot of work into some of our core libraries (like |
FYI @net-yehor-tretiakov, we have been making progress towards adding code generation to the |
Originally posted by @net-yehor-tretiakov in #82 (comment)
The text was updated successfully, but these errors were encountered: