Created
March 13, 2024 15:54
-
-
Save fynngodau/eebf750dac2be8440b231767a4f1da67 to your computer and use it in GitHub Desktop.
Encode as grpc request
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
# * provide a message to be grpc encoded: `python packGrpc.py $FILE` | |
# * grpc compression will not be enabled | |
# * output: $FILE.pac is a one-message grpc frame | |
# opposite of https://gist.github.com/fynngodau/bba7b2d11a17d01f8439979f3cfe4fb9 | |
import struct | |
import sys | |
assert len(sys.argv) == 2 | |
with open(sys.argv[1], "rb") as file: | |
decoded_message = file.read() | |
msg_is_compressed = False | |
length = len(decoded_message) | |
data = struct.pack("!?i", msg_is_compressed, length) + struct.pack("!%is" % length, decoded_message) | |
with open(sys.argv[1] + ".pac", "wb") as out_file: | |
out_file.write(data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment