コード例 #1
0
ファイル: fixtures.py プロジェクト: neumark/unimodel
from unimodel.model import Unimodel, UnimodelUnion, Field, FieldFactory
from unimodel import types
import sys

class NodeData(Unimodel):
    name = Field(types.UTF8)
    age = Field(types.Int)
    skills = Field(types.Map(types.UTF8, types.Int))


class TreeNode(Unimodel):
    pass

field_factory = FieldFactory()
field_factory.add_fields(TreeNode, {
    'children': Field(types.List(types.Struct(TreeNode))),
    'data': Field(types.Struct(NodeData))})

class A(Unimodel):
    f = Field(types.Int)

class TestUnion(UnimodelUnion):
    f1 = Field(types.Struct(NodeData))
    f2 = Field(types.Struct(A))

class AllTypes(Unimodel):
    f_struct = Field(types.Struct(NodeData))
    f_union = Field(types.Struct(TestUnion))
    f_utf8 = Field(types.UTF8)
    f_binary = Field(types.Binary)
    f_int64 = Field(types.Int64)
コード例 #2
0
ファイル: ast.py プロジェクト: neumark/unimodel

class ParametricType(Unimodel):
    type_id = Field(type_id_enum, required=True)
    type_parameters = Field(types.List(types.Struct(TypeDef)), required=True)


class TypeClass(UnimodelUnion):
    primitive_type_id = Field(type_id_enum)
    enum = Field(types.Map(types.Int, types.UTF8))
    struct_name = Field(types.UTF8)
    parametric_type = Field(types.Struct(ParametricType))

field_factory = FieldFactory()
field_factory.add_fields(TypeDef, {
    'metadata': Field(types.Struct(SchemaObjectMetadata)),
    'type_class': Field(types.Struct(TypeClass), required=True)})

class LiteralValue(UnimodelUnion):
    integer = Field(types.Int)
    double = Field(types.Double)
    string = Field(types.UTF8)

class Literal(Unimodel):
    literal_value = Field(types.Struct(LiteralValue()))
    metadata = Field(
        types.Struct(SchemaObjectMetadata),
        metadata=Metadata(
            backend_data={'json': {MDK_TYPE_STRUCT_UNBOXED: True}}))