Unis
Unis

Reputation: 824

Julia: Using ProtoBuf to read messages from gzipped file

A sensor provides a stream of frames containing object coordinates, which are stored in ProtoBuf format in a gzipped file. I would like to read this file in Julia.

Using protoc, I have generated the Protobuf files for both Python and Julia, coordinate_push.py and coordinate_push.jl

My Python code is as follows:

frameList = []

with gzip.open(filePath) as f:
    data = f.read()
    next_pos, pos = 0, 0

    while pos < len(data):
        msg = coordinate_push.CoordinatesFrame()

        next_pos, pos = _DecodeVarint32(data, pos)
        msg.ParseFromString(data[pos:pos + next_pos])

        frameList.append(msg)

        pos += next_pos

I'd like to rewrite the above in Julia, and don't know where to start. Part of the problem is that I haven't fully understood the Python script (IO is not my strong point).

I understand that I need:

What I don't understand is:

Insight on any of the three points would be highly appreciated.

Upvotes: 1

Views: 365

Answers (1)

logankilpatrick
logankilpatrick

Reputation: 14561

You should open an issue on the Gzip GitHub repo and ask this first part of your question there (I am not a Gzip expert unfortunately).

On the second point, I suggest looking here: https://github.com/JuliaIO/FileIO.jl/blob/master/README.md for lots of examples of FileIO loops which seems exactly what you need to replicate that Python loop. For the second part of this question, you best bet for that function is to try and hunt down the definition on GitHub or in the docs somewhere.

For the 3rd questions, coordinate_push.jl does not need to be in the same folder as your "main file" (I am not sure what you mean by this so perhaps it would help to add context on the structure of your files). To import that file all you need to do is add include("path/to/coordinate_push.jl") at the top of the file you want to call/run the code from. It's worth noting that the path can either be the absolute path or the relative project path (in some cases).

Upvotes: 1

Related Questions