-
Notifications
You must be signed in to change notification settings - Fork 533
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
Helper for iterating lenght-delimited from a Read #157
Comments
Do you have control over the format? If so I'd recommend using a fixed width delimiter, it makes it a bit easier. You can see an example of using |
Not really. I already have some files with data. Yes, I'm pretty sure I can make it work and the „tedious“ is about as good explanation as any of how I envision the implementation will look like. My question was more in the sense, is it OK to put the code into prost once I write it? If so, do you have any preferences on the interface, naming and such? |
@danburkert Could I ask you for the opinion? Can you give a very fast skim over the draft linked above? I want to polish the think eventually. But, do you want this in the Thanks |
Sorry to resurrect this old conversation, I am trying to do something similar, but I don't think I can even get it to work with the |
You can pass Alternatively, you can pass slices (they also implement |
Ah, I missed the https://docs.rs/bytes/1.0.1/bytes/trait.Buf.html#impl-Buf-for-%26mut%20T impl, thanks for pointing out! All good now :) |
@tiziano88 @vorner Can you possibly attach a code sample of doing that . I am struggling with that . I want to loop through the message that is read . this is what I have Thanks a lot and sorry for piling on to a thread that was meant for a different purpose pub mod dnstap { include!(concat!(env!("OUT_DIR"), "/dnstap.rs")); } fn main() -> Result<(), Box> { println!("Hello, world!"); let mut f = File::open("dnstap.log")?; let mut buffer = Vec::new(); // read the whole file f.read_to_end(&mut buffer)?; let mut cursor: Cursor> = Cursor::new(buffer); let message:dnstap::Message = prost::Message::decode_length_delimited(&mut cursor)?; println!("Finished Reading! {:?}",message); Ok(()) } where the dnstap.rs is dnstap.rs is from dnstap.proto Github using the protobuild |
Hello
I know prost doesn't build its base abstraction on top of
Read
, but onBuf
. However, if I have a huge file of length-delimited messages, I'm in a quite tricky situation. The options I see:Message::decode_length_delimited(&mut buffer)
until the whole buffer is consumed. This is convenient, but has the downside of putting the whole file into memory at once.decode_length_delimiter
, then refilling with as many bytes and callingMessage::decode
. That seems possible, but a lot of work and lot of space for errors.So I was thinking that if I'm going to write the latter, it would make sense to share it with others (and get another pair of eyes to review the errors I'll make 😇). Before I dive in, I have few questions, though:
read_length_delimited<R: Read, M: Msg>(read: R) -> impl Iterator<Result<M, SomeError { IoError | DecodeError }>>
, but I'm open to other suggestions.write_length_delimited
counter-part?Thank you
The text was updated successfully, but these errors were encountered: