Skip to content

Instantly share code, notes, and snippets.

@fynngodau
Created March 13, 2024 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fynngodau/eebf750dac2be8440b231767a4f1da67 to your computer and use it in GitHub Desktop.
Save fynngodau/eebf750dac2be8440b231767a4f1da67 to your computer and use it in GitHub Desktop.
Encode as grpc request
# * 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