-
-
Save Cphilo/7c875087bde84f98b7e2d2cb247d7c51 to your computer and use it in GitHub Desktop.
Snapshot proto file read test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from libs.walter_protobuf.python import message_pb2 | |
import delimited_protobuf | |
from google.protobuf.json_format import Parse | |
class ProtobufParser: | |
def get_messages(self, proto_file, header_market=True): | |
f_in = open(proto_file, "rb") | |
if header_market: | |
market = delimited_protobuf.read(f_in, message_pb2.Market) | |
else: | |
market = None | |
count = 0 | |
msgs = [] | |
while True: | |
msg = delimited_protobuf.read(f_in, message_pb2.Message) | |
count += 1 | |
if msg is None: | |
break | |
msgs.append(msg) | |
f_in.close() | |
return market, msgs | |
def test_l2_snapshot_protobuf_parser(): | |
p = ProtobufParser() | |
proto_file = "/mnt/tt_walter4/lcheng/hft-data-new/protobuf/binance/PERP_BTC_USDT/TF_2022_06_02/v1/binance.linear_swap.trade.BTC.USDT.BTCUSDT.2020-12-31.proto.plain" | |
p2 = ProtobufParser() | |
market, msgs = p2.get_messages(proto_file) | |
print(msgs[:10]) | |
print(market) | |
print("Total %s msgs" % len(msgs)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment