From 50b5cf1c117b9716815f9dc537ddc3f45dc4e8b4 Mon Sep 17 00:00:00 2001 From: "update-envoy[bot]" <135279899+update-envoy[bot]@users.noreply.github.com> Date: Fri, 1 Sep 2023 06:46:31 +0000 Subject: [PATCH] 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 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 "", 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 Mirrored from https://github.com/envoyproxy/envoy @ c1cae43bed0cd91b423dafa388a370a27cb163e7 --- tools/tap2pcap.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/tap2pcap.py b/tools/tap2pcap.py index bcb13fdf..1f773256 100644 --- a/tools/tap2pcap.py +++ b/tools/tap2pcap.py @@ -49,7 +49,7 @@ def tap2pcap(tap_path, pcap_path): with open(tap_path, 'r') as f: text_format.Merge(f.read(), wrapper) else: - with open(tap_path, 'r') as f: + with open(tap_path, 'rb') as f: wrapper.ParseFromString(f.read()) trace = wrapper.socket_buffered_trace