How to decode more than one metric (stream multiple) from the single protobuf binary file in golang

Hello

I am newbie to golang. I have protobuff binary message file which has multiple messages (stream). Able to decode that using Python easily like below, but could not find any simple way to achieve same using GO. Any help would be much appreciated.

Python code:

def read_pb_stream_from_file():
    amw = my_stream_pb2.MyTestMessageWrapper()
    count = 0
    with open("stream.strmpb",'rb') as f:
        data = f.read()
        n = 0

        while n < len(data):
            msg_len,new_pos = _DecodeVarint32(data,0)
            n = new_pos
            msg_buf = data[n:n+msg_len]
            n += msg_len
            amw.ParseFromString(msg_buf)
            data = data[n:]
            print(count)
            print(amw)
            count+=1

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.