commit 4527d2284d23c8b76f71553dbddc98c45f10ff81
parent 721cd3ac9af238306d78319e4085961ba938e420
Author: nolash <dev@holbrook.no>
Date: Sun, 11 Apr 2021 14:08:15 +0200
Update struct
Diffstat:
1 file changed, 17 insertions(+), 9 deletions(-)
diff --git a/rlpstream/encode.py b/rlpstream/encode.py
@@ -1,14 +1,17 @@
# standard imports
import logging
import ctypes
-import ctypes.util
-logg = logging.getLogger().getChild(__name__)
+# local imports
+from . import (
+ LIBRLP_RLP_MAX_LIST_DEPTH,
+ librlp,
+ )
-path_librlp = ctypes.util.find_library('rlp')
-librlp = ctypes.CDLL(path_librlp)
+logg = logging.getLogger().getChild(__name__)
-LIBRLP_RLP_MAX_LIST_DEPTH = 1024
+#path_librlp = ctypes.util.find_library('rlp')
+#librlp = ctypes.CDLL(path_librlp)
class RLPEncoder:
@@ -19,18 +22,23 @@ class RLPEncoder:
_fields_ = [
('buf', ctypes.POINTER(ctypes.c_char * buffer_size)),
+ ('alloc', ctypes.c_char),
('depth', ctypes.c_int),
- ('list_ptr', ctypes.POINTER(ctypes.POINTER(ctypes.c_char) * LIBRLP_RLP_MAX_LIST_DEPTH)),
+ ('size', ctypes.c_int),
+ ('state', ctypes.c_int),
+ ('list_ptr', ctypes.POINTER(ctypes.POINTER(ctypes.c_char)) * LIBRLP_RLP_MAX_LIST_DEPTH),
('ptr', ctypes.POINTER(ctypes.c_char)),
]
-
self.backend = RLPEncoderBackend()
self.encoder = ctypes.pointer(self.backend)
- librlp.rlp_init(self.encoder, buffer_size)
+ 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):
+ logg.debug('free')
librlp.rlp_free(self.encoder)
@@ -45,7 +53,7 @@ class RLPEncoder:
b = (ctypes.c_char * len(v))(*v)
librlp.rlp_add(self.encoder, len(v), b)
- return librlp.rlp_length(self.encoder)
+ return self.backend.size
def encode(self, v):