Padding data to fixed size

I need to send a block of data to a python script via an IPC socket. The python script expects a fixed size packet. What’s the best way to pad the data I’m sending to reach that size? Most likely I’ll be sending a JSON object, but the actual data I send will almost always be smaller than the packet size.

The thinking is that it’s easier/faster on the python side to just expect a fixed size and wait for that, rather than parsing the incoming data for some kind of end-of-message character. the data I’m sending comes from a fixed set of commands/parameters, so it’s never going to exceed 1KB. probably not even half of that.

I tried putting the string in a memory block of the size Python is expecting, but it only seems to be sending the string size to python, not the size of the memory block.