-
Notifications
You must be signed in to change notification settings - Fork 198
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
Throws an error when I try to _read a large file #255
Comments
It's somewhat complicated issue, which should be started to be dealt with in kaitai-io/kaitai_struct_compiler#133, but it's still a good way to go. For a while, I could recommend the following workaround. pcap format literally consists of the header and a long list of packets. If you don't need them all at once in the memory, then it can be done like that:
seq:
- id: hdr
type: header
Pcap p = Pcap.fromFile("material/log114MB.pcap");
KaitaiStream io = p._io();
// iterate over all the packets until reached end of file
while (!io.isEof()) {
Pcap.Packet packet = new Pcap.Packet(io, p, p);
// do something with `packet` here, for example, print out timestamp
System.out.println(packet.tsSec());
} |
Thank you very much for you answer! This is a very good solution. However, the purpose of my work is to get the contents of the packages. To be precise, I need to handle each one in turn. Could you advise another solution without losing the data? |
Um, this solution exactly allows you to access each packet, one-by-one. What exactly are you losing here? |
Oh, I misunderstood you, I'm sorry. Your solution is great and it works. The only thing I wanted to notice, you meant this method probably: But this is of very small importance. |
Yeah, my bad, I forgot that it's |
Great Example! |
The overall algorithm is the same for all languages, so may be it warrants a FAQ entry actually... |
This was the solution that I landed on in my case (another file with a header followed by an unbounded sequence of records). However, when I removed the equivalent of seq:
- id: file_header
type: file_header_v1
- id: file_header_v3
if: v3tag == "LOG_V3"
type: file_header_v3
- id: records
type: record
if: false
doc: Having this reference satisfies type deduction requirements; the conditional allows us to defer reading it. That structure also makes it clearer what's actually going on...so, if you create a FAQ/example, you might want to consider providing that idiom. |
Moved from #1196, original by @bulbum.
The text was updated successfully, but these errors were encountered: