pylibrlp

Python3 wrapper for librlp
git clone git://git.defalsify.org/pylibrlp.git
Log | Files | Refs | LICENSE

commit 721cd3ac9af238306d78319e4085961ba938e420
parent e55e11faaf793f3bf8dd13e19a9aafa08712aef0
Author: nolash <dev@holbrook.no>
Date:   Sun, 11 Apr 2021 00:33:26 +0200

Enable dynamic assignment of buffer size

Diffstat:
Mrlpstream/encode.py | 22+++++++++++-----------
Mtests/test_rlp_encoder.py | 2+-
2 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/rlpstream/encode.py b/rlpstream/encode.py @@ -9,25 +9,25 @@ path_librlp = ctypes.util.find_library('rlp') librlp = ctypes.CDLL(path_librlp) LIBRLP_RLP_MAX_LIST_DEPTH = 1024 -RLP_BUFFER_SIZE = 1024 -class RLPEncoderBackend(ctypes.Structure): +class RLPEncoder: - _fields_ = [ - ('buf', ctypes.POINTER(ctypes.c_char * RLP_BUFFER_SIZE)), - ('depth', ctypes.c_int), - ('list_ptr', ctypes.POINTER(ctypes.POINTER(ctypes.c_char) * LIBRLP_RLP_MAX_LIST_DEPTH)), - ('ptr', ctypes.POINTER(ctypes.c_char)), - ] + def __init__(self, buffer_size): + class RLPEncoderBackend(ctypes.Structure): + + _fields_ = [ + ('buf', ctypes.POINTER(ctypes.c_char * buffer_size)), + ('depth', ctypes.c_int), + ('list_ptr', ctypes.POINTER(ctypes.POINTER(ctypes.c_char) * LIBRLP_RLP_MAX_LIST_DEPTH)), + ('ptr', ctypes.POINTER(ctypes.c_char)), + ] -class RLPEncoder: - def __init__(self): self.backend = RLPEncoderBackend() self.encoder = ctypes.pointer(self.backend) - librlp.rlp_init(self.encoder, RLP_BUFFER_SIZE); + librlp.rlp_init(self.encoder, buffer_size) def __del__(self): diff --git a/tests/test_rlp_encoder.py b/tests/test_rlp_encoder.py @@ -13,7 +13,7 @@ logg = logging.getLogger() class TestRlpEncoder(unittest.TestCase): def setUp(self): - self.encoder = RLPEncoder() + self.encoder = RLPEncoder(1024) def test_encode_single(self):