Forked from mydreambei-ai/convert_struct_to_bytes.py
Created
September 20, 2019 07:43
-
-
Save iamadou/8a894c7c20c98b08c8c62e9583bb5d5b to your computer and use it in GitHub Desktop.
Python ctypes Structure to bytes
This file contains hidden or 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
| from ctypes import * | |
| def convert_bytes_to_structure(st, byte): | |
| # sizoef(st) == sizeof(byte) | |
| memmove(addressof(st), byte, sizeof(st)) | |
| def convert_struct_to_bytes(st): | |
| buffer = create_string_buffer(sizeof(st)) | |
| memmove(buffer, addressof(st), sizeof(st)) | |
| return buffer.raw | |
| def conver_int_to_bytes(number, size): | |
| return (number).to_bytes(size, 'big') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment