tap: Fix the failure of protobuf to PCAP generation (#28180)

tap: Fix the protobuf to PCAP generation failure

When run 'bazel run @envoy_api//tools:tap2pcap path_0.pb path_0.pcap':
  ...
  Traceback (most recent call last):
  File "..../tools/tap2pcap.runfiles/envoy_api/tools/tap2pcap.py", line 88, in <module>
    tap2pcap(sys.argv[1], sys.argv[2])
  File "..../tools/tap2pcap.runfiles/envoy_api/tools/tap2pcap.py", line 53, in tap2pcap
    wrapper.ParseFromString(f.read())
                            ^^^^^^^^
  File "<frozen codecs>", line 322, in decode
  UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb8 in position 1: invalid start byte
  ...

The protobuf file is in binary format, opening this file in binary mode
will help to generate the PCAP file successfully.

Signed-off-by: Haiyue Wang <haiyue.wang@intel.com>

Mirrored from https://github.com/envoyproxy/envoy @ c1cae43bed0cd91b423dafa388a370a27cb163e7
main
update-envoy[bot] 1 year ago
parent e76c403fc5
commit 50b5cf1c11
  1. 2
      tools/tap2pcap.py

@ -49,7 +49,7 @@ def tap2pcap(tap_path, pcap_path):
with open(tap_path, 'r') as f: with open(tap_path, 'r') as f:
text_format.Merge(f.read(), wrapper) text_format.Merge(f.read(), wrapper)
else: else:
with open(tap_path, 'r') as f: with open(tap_path, 'rb') as f:
wrapper.ParseFromString(f.read()) wrapper.ParseFromString(f.read())
trace = wrapper.socket_buffered_trace trace = wrapper.socket_buffered_trace

Loading…
Cancel
Save