pylibrlp

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

commit e8a9b8fb5e86e1dc09356bae95bda71c54c31a52
parent 4f6a89256be3765d0361894eda6b1cf5e20883f2
Author: nolash <dev@holbrook.no>
Date:   Sun, 11 Apr 2021 18:13:32 +0200

Add init between encodings

Diffstat:
Mrlpstream/encode.py | 12+++++-------
1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/rlpstream/encode.py b/rlpstream/encode.py @@ -10,12 +10,11 @@ from . import ( logg = logging.getLogger().getChild(__name__) -#path_librlp = ctypes.util.find_library('rlp') -#librlp = ctypes.CDLL(path_librlp) - class RLPEncoder: + __nullptr = ctypes.POINTER(ctypes.c_void_p)() + def __init__(self, buffer_size): class RLPEncoderBackend(ctypes.Structure): @@ -29,12 +28,10 @@ class RLPEncoder: ('list_ptr', ctypes.POINTER(ctypes.POINTER(ctypes.c_char)) * LIBRLP_RLP_MAX_LIST_DEPTH), ('ptr', ctypes.POINTER(ctypes.c_char)), ] - + + self.buffer_size = buffer_size self.backend = RLPEncoderBackend() self.encoder = ctypes.pointer(self.backend) - nullptr = ctypes.POINTER(ctypes.c_void_p)() - librlp.rlp_init(self.encoder, buffer_size, nullptr) - logg.debug('alloc {} {}'.format(self.backend.alloc, self.backend.state)) def __del__(self): @@ -57,6 +54,7 @@ class RLPEncoder: def encode(self, v): + librlp.rlp_init(self.encoder, self.buffer_size, self.__nullptr) r = self.encode_item(v) return bytes(self.backend.buf.contents[:r])