Make Text and Data fields readable

This commit is contained in:
Jason Paryani
2013-06-25 23:23:24 -07:00
parent a378430b7e
commit 481841730c
6 changed files with 3483 additions and 3281 deletions

View File

@@ -14,13 +14,24 @@ ctypedef int16_t Int16
ctypedef int32_t Int32
ctypedef int64_t Int64
ctypedef char * Data
ctypedef char * Object
ctypedef char * Text
ctypedef bint Bool
ctypedef float Float32
ctypedef double Float64
cdef extern from "capnp/blob.h" namespace "::capnp":
cdef cppclass Data:
cppclass Reader:
char * begin()
size_t size()
cppclass Builder:
char * begin()
size_t size()
cdef cppclass Text:
cppclass Reader:
char * cStr()
cppclass Builder:
char * cStr()
cdef extern from "capnp/message.h" namespace "::capnp":
cdef cppclass List[T]:
cppclass Reader:
@@ -60,12 +71,12 @@ cdef extern from "schema.capnp.h" namespace "::capnp::schema":
cppclass Reader:
{{'int which()' if node_dict['body'] == 'union'}}
{%- for member_name, member_dict in node_dict['members'].items() %}
{{member_dict['type']}}{{'.Reader' if member_dict.get('type', '').startswith('List') }} get{{member_name|capitalize}}()
{{member_dict['type']}}{{'.Reader' if member_dict.get('type', '').startswith('List') or member_dict.get('type', '') in ['Text', 'Data'] }} get{{member_name|capitalize}}()
{%- endfor %}
cppclass Builder:
{{'int which()' if node_dict['body'] == 'union'}}
{%- for member_name, member_dict in node_dict['members'].items() %}
{{member_dict['type']}}{{'.Builder' if member_dict.get('type', '').startswith('List') }} get{{member_name|capitalize}}()
{{member_dict['type']}}{{'.Builder' if member_dict.get('type', '').startswith('List') or member_dict.get('type', '') in ['Text', 'Data'] }} get{{member_name|capitalize}}()
{%- if member_dict.get('type', '').startswith('List') %}
{{member_dict['type']}}.Builder init{{member_name|capitalize}}(int)
{%- else %}

View File

@@ -3,12 +3,12 @@
# distutils: extra_compile_args = --std=c++11
# distutils: libraries = capnp
cimport capnp_schema as capnp
from capnp_schema cimport {% for node_name, node_dict in nodes.items() %}{% if node_dict['body'] != 'enum' %}{{node_name|capitalize}} as C_{{node_name|capitalize}}{{',' if not loop.last}}{%- endif %}{% endfor %}
from capnp_schema cimport {% for node_dict in enum_types %}{%- for member_name, member_dict in node_dict['members'].items() %}{{node_dict['full_name_cython']}}_{{member_name}}{{',' if not loop.last}}{%- endfor %}{{',' if not loop.last}}{%- endfor %}
from capnp_schema cimport {% for node_dict in union_types %}{%- for member_name, member_dict in node_dict['members'].items() %}{{node_dict['full_name_cython']}}_{{member_name}}{{',' if not loop.last}}{%- endfor %}{{',' if not loop.last}}{% endfor %}
cimport schema_cpp as capnp
from schema_cpp cimport {% for node_name, node_dict in nodes.items() %}{% if node_dict['body'] != 'enum' %}{{node_name|capitalize}} as C_{{node_name|capitalize}}{{',' if not loop.last}}{%- endif %}{% endfor %}
from schema_cpp cimport {% for node_dict in enum_types %}{%- for member_name, member_dict in node_dict['members'].items() %}{{node_dict['full_name_cython']}}_{{member_name}}{{',' if not loop.last}}{%- endfor %}{{',' if not loop.last}}{%- endfor %}
from schema_cpp cimport {% for node_dict in union_types %}{%- for member_name, member_dict in node_dict['members'].items() %}{{node_dict['full_name_cython']}}_{{member_name}}{{',' if not loop.last}}{%- endfor %}{{',' if not loop.last}}{% endfor %}
# from capnp_schema cimport *
# from schema_cpp cimport *
# Not doing this since we want to namespace away the class names
from cython.operator cimport dereference as deref
@@ -24,12 +24,16 @@ ctypedef int16_t Int16
ctypedef int32_t Int32
ctypedef int64_t Int64
ctypedef char * Data
ctypedef char * Object
ctypedef char * Text
ctypedef bint Bool
ctypedef float Float32
ctypedef double Float64
cdef extern from "capnp/blob.h" namespace "::capnp":
cdef cppclass Data:
char * begin()
size_t size()
cdef cppclass Text:
char * cStr()
cdef extern from "capnp/message.h" namespace "::capnp":
cdef cppclass List[T]:
cppclass Reader:
@@ -104,6 +108,11 @@ cdef class {{ node_dict['full_name_cython'] }}Reader:
return self.thisptr.get{{member_name|capitalize}}()
{%- elif member_dict['type'].startswith('List[') %}
return _{{ member_dict['type'] |replace('[', '_')|replace(']','_')|replace('.','_')}}Reader().init(self.thisptr.get{{member_name|capitalize}}())
{%- elif member_dict['type'] == 'Text' %}
return self.thisptr.get{{member_name|capitalize}}().cStr()
{%- elif member_dict['type'] == 'Data' %}
temp = self.thisptr.get{{member_name|capitalize}}()
return (<char*>temp.begin())[:temp.size()]
{%- elif member_dict['type'] in built_in_types %}
return None
{%- else %}
@@ -127,6 +136,11 @@ cdef class {{ node_dict['full_name_cython'] }}Builder:
return self.thisptr.get{{member_name|capitalize}}()
{%- elif member_dict['type'].startswith('List[') %}
return _{{ member_dict['type'] |replace('[', '_')|replace(']','_')|replace('.','_')}}Builder().init(self.thisptr.get{{member_name|capitalize}}())
{%- elif member_dict['type'] == 'Text' %}
return self.thisptr.get{{member_name|capitalize}}().cStr()
{%- elif member_dict['type'] == 'Data' %}
temp = self.thisptr.get{{member_name|capitalize}}()
return (<char*>temp.begin())[:temp.size()]
{%- elif member_dict['type'] in built_in_types %}
return None
{%- else %}
@@ -178,11 +192,11 @@ cdef class MessageReader:
cdef class StreamFdMessageReader(MessageReader):
def __cinit__(self, int fd):
self.thisptr = new capnp.StreamFdMessageReader(int)
self.thisptr = new capnp.StreamFdMessageReader(fd)
cdef class PackedFdMessageReader(MessageReader):
def __cinit__(self, int fd):
self.thisptr = new capnp.PackedFdMessageReader(int)
self.thisptr = new capnp.PackedFdMessageReader(fd)
def writeMessageToFd(int fd, MessageBuilder m):
capnp.writeMessageToFd(fd, deref(m.thisptr))
@@ -197,6 +211,8 @@ temp = {{ node_dict['full_name'] }} = ModuleType('{{ node_dict['full_name'] }}')
{%- if node_dict['body'] != 'enum' %}
temp.Reader = {{ node_dict['full_name_cython'] }}Reader
temp.Builder = {{ node_dict['full_name_cython'] }}Builder
{%- elif node_dict['body'] == 'union' %}
temp.Which = {{ node_dict['full_name_cython'] }}_Which
{%- else %}
{{ node_dict['full_name'] }} = {{ node_dict['full_name_cython'] }}
{%- endif %}

6603
schema.cpp

File diff suppressed because it is too large Load Diff

View File

@@ -8,7 +8,7 @@ from schema_cpp cimport CodeGeneratorRequest as C_CodeGeneratorRequest,Interface
from schema_cpp cimport _ElementSize_inlineComposite,_ElementSize_eightBytes,_ElementSize_pointer,_ElementSize_bit,_ElementSize_twoBytes,_ElementSize_fourBytes,_ElementSize_byte,_ElementSize_empty
from schema_cpp cimport _Value_Body_uint32Value,_Value_Body_float64Value,_Value_Body_voidValue,_Value_Body_dataValue,_Value_Body_listValue,_Value_Body_int32Value,_Value_Body_enumValue,_Value_Body_int8Value,_Value_Body_boolValue,_Value_Body_int16Value,_Value_Body_float32Value,_Value_Body_interfaceValue,_Value_Body_uint16Value,_Value_Body_uint8Value,_Value_Body_int64Value,_Value_Body_structValue,_Value_Body_textValue,_Value_Body_uint64Value,_Value_Body_objectValue,_Type_Body_boolType,_Type_Body_structType,_Type_Body_int32Type,_Type_Body_voidType,_Type_Body_uint16Type,_Type_Body_dataType,_Type_Body_objectType,_Type_Body_int64Type,_Type_Body_float64Type,_Type_Body_interfaceType,_Type_Body_uint32Type,_Type_Body_uint8Type,_Type_Body_listType,_Type_Body_int8Type,_Type_Body_float32Type,_Type_Body_enumType,_Type_Body_uint64Type,_Type_Body_textType,_Type_Body_int16Type,_Node_Body_annotationNode,_Node_Body_interfaceNode,_Node_Body_enumNode,_Node_Body_structNode,_Node_Body_constNode,_Node_Body_fileNode,_StructNode_Member_Body_fieldMember,_StructNode_Member_Body_unionMember
# from capnp_schema cimport *
# from schema_cpp cimport *
# Not doing this since we want to namespace away the class names
from cython.operator cimport dereference as deref
@@ -24,12 +24,16 @@ ctypedef int16_t Int16
ctypedef int32_t Int32
ctypedef int64_t Int64
ctypedef char * Data
ctypedef char * Object
ctypedef char * Text
ctypedef bint Bool
ctypedef float Float32
ctypedef double Float64
cdef extern from "capnp/blob.h" namespace "::capnp":
cdef cppclass Data:
char * begin()
size_t size()
cdef cppclass Text:
char * cStr()
cdef extern from "capnp/message.h" namespace "::capnp":
cdef cppclass List[T]:
cppclass Reader:
@@ -470,7 +474,7 @@ cdef class _InterfaceNode_Method_ParamReader:
return _TypeReader().init(<C_Type.Reader>self.thisptr.getType())
property name:
def __get__(self):
return None
return self.thisptr.getName().cStr()
property annotations:
def __get__(self):
return _List_InterfaceNode_Method_Param_Annotation_Reader().init(self.thisptr.getAnnotations())
@@ -493,7 +497,7 @@ cdef class _InterfaceNode_Method_ParamBuilder:
pass
property name:
def __get__(self):
return None
return self.thisptr.getName().cStr()
def __set__(self, val):
pass
property annotations:
@@ -512,7 +516,7 @@ cdef class _InterfaceNode_MethodReader:
return self.thisptr.getCodeOrder()
property name:
def __get__(self):
return None
return self.thisptr.getName().cStr()
property params:
def __get__(self):
return _List_InterfaceNode_Method_InterfaceNode_Method_Param_Reader().init(self.thisptr.getParams())
@@ -539,7 +543,7 @@ cdef class _InterfaceNode_MethodBuilder:
self.thisptr.setCodeOrder(val)
property name:
def __get__(self):
return None
return self.thisptr.getName().cStr()
def __set__(self, val):
pass
property params:
@@ -605,7 +609,8 @@ cdef class _Value_BodyReader:
return None
property dataValue:
def __get__(self):
return None
temp = self.thisptr.getDataValue()
return (<char*>temp.begin())[:temp.size()]
property listValue:
def __get__(self):
return None
@@ -644,7 +649,7 @@ cdef class _Value_BodyReader:
return None
property textValue:
def __get__(self):
return None
return self.thisptr.getTextValue().cStr()
property uint64Value:
def __get__(self):
return self.thisptr.getUint64Value()
@@ -677,7 +682,8 @@ cdef class _Value_BodyBuilder:
pass
property dataValue:
def __get__(self):
return None
temp = self.thisptr.getDataValue()
return (<char*>temp.begin())[:temp.size()]
def __set__(self, val):
pass
property listValue:
@@ -742,7 +748,7 @@ cdef class _Value_BodyBuilder:
pass
property textValue:
def __get__(self):
return None
return self.thisptr.getTextValue().cStr()
def __set__(self, val):
pass
property uint64Value:
@@ -1012,7 +1018,7 @@ cdef class _FileNode_ImportReader:
return self.thisptr.getId()
property name:
def __get__(self):
return None
return self.thisptr.getName().cStr()
cdef class _FileNode_ImportBuilder:
cdef C_FileNode.Import.Builder thisptr
@@ -1027,7 +1033,7 @@ cdef class _FileNode_ImportBuilder:
self.thisptr.setId(val)
property name:
def __get__(self):
return None
return self.thisptr.getName().cStr()
def __set__(self, val):
pass
cdef class _FileNodeReader:
@@ -1128,7 +1134,7 @@ cdef class _Node_NestedNodeReader:
property name:
def __get__(self):
return None
return self.thisptr.getName().cStr()
property id:
def __get__(self):
return self.thisptr.getId()
@@ -1141,7 +1147,7 @@ cdef class _Node_NestedNodeBuilder:
property name:
def __get__(self):
return None
return self.thisptr.getName().cStr()
def __set__(self, val):
pass
property id:
@@ -1160,7 +1166,7 @@ cdef class _NodeReader:
return _Node_BodyReader().init(<C_Node.Body.Reader>self.thisptr.getBody())
property displayName:
def __get__(self):
return None
return self.thisptr.getDisplayName().cStr()
property annotations:
def __get__(self):
return _List_Node_Annotation_Reader().init(self.thisptr.getAnnotations())
@@ -1187,7 +1193,7 @@ cdef class _NodeBuilder:
pass
property displayName:
def __get__(self):
return None
return self.thisptr.getDisplayName().cStr()
def __set__(self, val):
pass
property annotations:
@@ -1333,7 +1339,7 @@ cdef class _EnumNode_EnumerantReader:
return self.thisptr.getCodeOrder()
property name:
def __get__(self):
return None
return self.thisptr.getName().cStr()
property annotations:
def __get__(self):
return _List_EnumNode_Enumerant_Annotation_Reader().init(self.thisptr.getAnnotations())
@@ -1351,7 +1357,7 @@ cdef class _EnumNode_EnumerantBuilder:
self.thisptr.setCodeOrder(val)
property name:
def __get__(self):
return None
return self.thisptr.getName().cStr()
def __set__(self, val):
pass
property annotations:
@@ -1464,7 +1470,7 @@ cdef class _StructNode_MemberReader:
return self.thisptr.getCodeOrder()
property name:
def __get__(self):
return None
return self.thisptr.getName().cStr()
property annotations:
def __get__(self):
return _List_StructNode_Member_Annotation_Reader().init(self.thisptr.getAnnotations())
@@ -1492,7 +1498,7 @@ cdef class _StructNode_MemberBuilder:
self.thisptr.setCodeOrder(val)
property name:
def __get__(self):
return None
return self.thisptr.getName().cStr()
def __set__(self, val):
pass
property annotations:
@@ -1688,11 +1694,11 @@ cdef class MessageReader:
cdef class StreamFdMessageReader(MessageReader):
def __cinit__(self, int fd):
self.thisptr = new capnp.StreamFdMessageReader(int)
self.thisptr = new capnp.StreamFdMessageReader(fd)
cdef class PackedFdMessageReader(MessageReader):
def __cinit__(self, int fd):
self.thisptr = new capnp.PackedFdMessageReader(int)
self.thisptr = new capnp.PackedFdMessageReader(fd)
def writeMessageToFd(int fd, MessageBuilder m):
capnp.writeMessageToFd(fd, deref(m.thisptr))

View File

@@ -14,13 +14,24 @@ ctypedef int16_t Int16
ctypedef int32_t Int32
ctypedef int64_t Int64
ctypedef char * Data
ctypedef char * Object
ctypedef char * Text
ctypedef bint Bool
ctypedef float Float32
ctypedef double Float64
cdef extern from "capnp/blob.h" namespace "::capnp":
cdef cppclass Data:
cppclass Reader:
char * begin()
size_t size()
cppclass Builder:
char * begin()
size_t size()
cdef cppclass Text:
cppclass Reader:
char * cStr()
cppclass Builder:
char * cStr()
cdef extern from "capnp/message.h" namespace "::capnp":
cdef cppclass List[T]:
cppclass Reader:
@@ -130,7 +141,7 @@ cdef extern from "schema.capnp.h" namespace "::capnp::schema":
Value getDefaultValue()
Type getType()
Text getName()
Text.Reader getName()
List[InterfaceNode.Method.Param.Annotation].Reader getAnnotations()
cppclass Builder:
@@ -138,14 +149,14 @@ cdef extern from "schema.capnp.h" namespace "::capnp::schema":
void setDefaultValue(Value)
Type getType()
void setType(Type)
Text getName()
Text.Builder getName()
void setName(Text)
List[InterfaceNode.Method.Param.Annotation].Builder getAnnotations()
List[InterfaceNode.Method.Param.Annotation].Builder initAnnotations(int)
cppclass Reader:
UInt16 getCodeOrder()
Text getName()
Text.Reader getName()
List[InterfaceNode.Method.InterfaceNode.Method.Param].Reader getParams()
UInt16 getRequiredParamCount()
Type getReturnType()
@@ -154,7 +165,7 @@ cdef extern from "schema.capnp.h" namespace "::capnp::schema":
UInt16 getCodeOrder()
void setCodeOrder(UInt16)
Text getName()
Text.Builder getName()
void setName(Text)
List[InterfaceNode.Method.InterfaceNode.Method.Param].Builder getParams()
List[InterfaceNode.Method.InterfaceNode.Method.Param].Builder initParams(int)
@@ -183,7 +194,7 @@ cdef extern from "schema.capnp.h" namespace "::capnp::schema":
UInt32 getUint32Value()
Float64 getFloat64Value()
Void getVoidValue()
Data getDataValue()
Data.Reader getDataValue()
Object getListValue()
Int32 getInt32Value()
UInt16 getEnumValue()
@@ -196,7 +207,7 @@ cdef extern from "schema.capnp.h" namespace "::capnp::schema":
UInt8 getUint8Value()
Int64 getInt64Value()
Object getStructValue()
Text getTextValue()
Text.Reader getTextValue()
UInt64 getUint64Value()
Object getObjectValue()
cppclass Builder:
@@ -207,7 +218,7 @@ cdef extern from "schema.capnp.h" namespace "::capnp::schema":
void setFloat64Value(Float64)
Void getVoidValue()
void setVoidValue(Void)
Data getDataValue()
Data.Builder getDataValue()
void setDataValue(Data)
Object getListValue()
void setListValue(Object)
@@ -233,7 +244,7 @@ cdef extern from "schema.capnp.h" namespace "::capnp::schema":
void setInt64Value(Int64)
Object getStructValue()
void setStructValue(Object)
Text getTextValue()
Text.Builder getTextValue()
void setTextValue(Text)
UInt64 getUint64Value()
void setUint64Value(UInt64)
@@ -344,12 +355,12 @@ cdef extern from "schema.capnp.h" namespace "::capnp::schema":
cppclass Reader:
UInt64 getId()
Text getName()
Text.Reader getName()
cppclass Builder:
UInt64 getId()
void setId(UInt64)
Text getName()
Text.Builder getName()
void setName(Text)
cppclass Reader:
@@ -393,18 +404,18 @@ cdef extern from "schema.capnp.h" namespace "::capnp::schema":
cppclass Reader:
Text getName()
Text.Reader getName()
UInt64 getId()
cppclass Builder:
Text getName()
Text.Builder getName()
void setName(Text)
UInt64 getId()
void setId(UInt64)
cppclass Reader:
Node.Body getBody()
Text getDisplayName()
Text.Reader getDisplayName()
List[Node.Annotation].Reader getAnnotations()
UInt64 getScopeId()
List[Node.Node.NestedNode].Reader getNestedNodes()
@@ -413,7 +424,7 @@ cdef extern from "schema.capnp.h" namespace "::capnp::schema":
Node.Body getBody()
void setBody(Node.Body)
Text getDisplayName()
Text.Builder getDisplayName()
void setDisplayName(Text)
List[Node.Annotation].Builder getAnnotations()
List[Node.Annotation].Builder initAnnotations(int)
@@ -476,13 +487,13 @@ cdef extern from "schema.capnp.h" namespace "::capnp::schema":
cppclass Reader:
UInt16 getCodeOrder()
Text getName()
Text.Reader getName()
List[EnumNode.Enumerant.Annotation].Reader getAnnotations()
cppclass Builder:
UInt16 getCodeOrder()
void setCodeOrder(UInt16)
Text getName()
Text.Builder getName()
void setName(Text)
List[EnumNode.Enumerant.Annotation].Builder getAnnotations()
List[EnumNode.Enumerant.Annotation].Builder initAnnotations(int)
@@ -534,7 +545,7 @@ cdef extern from "schema.capnp.h" namespace "::capnp::schema":
UInt16 getOrdinal()
StructNode.Member.Body getBody()
UInt16 getCodeOrder()
Text getName()
Text.Reader getName()
List[StructNode.Member.Annotation].Reader getAnnotations()
cppclass Builder:
@@ -544,7 +555,7 @@ cdef extern from "schema.capnp.h" namespace "::capnp::schema":
void setBody(StructNode.Member.Body)
UInt16 getCodeOrder()
void setCodeOrder(UInt16)
Text getName()
Text.Builder getName()
void setName(Text)
List[StructNode.Member.Annotation].Builder getAnnotations()
List[StructNode.Member.Annotation].Builder initAnnotations(int)

View File

@@ -1,11 +1,6 @@
#!/usr/bin/env python
from distutils.core import setup
from Cython.Build import cythonize
from jinja2 import Environment, FileSystemLoader
import os
curr_dir = os.path.abspath(os.path.dirname(__file__))
env = Environment(loader=FileSystemLoader(curr_dir))
setup(
name = "capnp",