Add _DynamicStructBuilder.to_bytes() and <struct module>.read_from_memory

to_bytes is not very efficient (it makes one necessary copy and one
unnecessary copy), but it will simplify a lot of use cases.

read_from_memory should be maximally efficient for most input types
(including mmap).
This commit is contained in:
Andy Lutomirski
2013-09-03 11:54:45 -07:00
parent b3264a7292
commit cd0fe97710
3 changed files with 69 additions and 2 deletions

View File

@@ -11,6 +11,8 @@ from libcpp cimport bool as cbool
cdef extern from "capnp/common.h" namespace " ::capnp":
enum Void:
VOID " ::capnp::VOID"
cdef cppclass word:
pass
cdef extern from "kj/string.h" namespace " ::kj":
cdef cppclass StringPtr:
@@ -31,6 +33,23 @@ cdef extern from "kj/common.h" namespace " ::kj":
size_t size()
T& operator[](size_t index)
# Cython can't handle ArrayPtr[word] as a function argument
cdef cppclass WordArrayPtr "::kj::ArrayPtr<::capnp::word>":
WordArrayPtr()
WordArrayPtr(word *, size_t size)
size_t size()
word& operator[](size_t index)
cdef extern from "kj/array.h" namespace " ::kj":
cdef cppclass Array[T]:
T* begin()
size_t size()
# Cython can't handle Array[word] as a function argument
cdef cppclass WordArray "::kj::Array<::capnp::word>":
word* begin()
size_t size()
cdef extern from "capnp/schema.h" namespace " ::capnp":
cdef cppclass Schema:
Node.Reader getProto() except +