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:
- to open the gzip file, presumably using
using GZip; file = GZip.open(file_path, "r") - to read in the data, along the lines of
using ProtoBuf; data = readproto(iob, CoordinatesFrame())
What I don't understand is:
- how to define
iob, and especially how to link it tofile(in the Julia Protobuf manual, we hadiob = PipeBuffer(), but here it's a gzip-file that we'd like to read) - how to replicate the while-loop in Julia, and in particular the mysterious
_DecodeVarint32(I'm on Windows, if it's related to that.) - whether the file
coordinate_push.jlhas to be in the same directory as my main file, and if not, how I can properly import it (it is currently in aprotosubfolder, and in Python I'd import it usingfrom src.proto import coordinate_push)
Insight on any of the three points would be highly appreciated.