Exemplo n.º 1
0
class SizedBuff(Message):
    _struct_ = [
        Field("code", Uint8),
        Field("buff", String, byte_size=16),
        Field("buff1_len", Uint8),
        Field("buff1", Buffer, size_ref="buff1_len"),
        Field("buff2", Buffer, byte_size=0)
    ]
Exemplo n.º 2
0
class Mother(Message):
    _struct_ = [
        Field("name", String),
        Field("age", Int32),
        Field(
            "alive",
            Bool,
        ),
        Field("baby", Baby, optional=True),
    ]
Exemplo n.º 3
0
class HelloResponse(ResponseBase):
    """hello response definition
    """
    _struct_ = [
        Field('len', Uint32),
        Field('seq', Uint32),
        Field('result', String, byte_size=0)
    ]
    _serializer_ = BinarySerializer()
    _length_field_ = "len"

    def get_sequence_id(self):
        return self.seq
Exemplo n.º 4
0
class JsonData(Message):
    '''Json数据
    '''
    _struct_ = [Field("data", Variant)]

    def __repr__(self):
        return 'JsonData(%s)' % self.data
Exemplo n.º 5
0
class FooMessage(Message):
    _struct_ = [
        Field("x", Uint32),
        Field("s_len", Uint16),
        Field("s", String, size_ref="s_len"),
        Field("jce_len", Uint16),
        Field("jce", DemoJce, serializer=JceSerializer(), size_ref="jce_len"),
        Field("pb_len", Uint16),
        Field("pb",
              AddressBook,
              serializer=ProtobufSerializer(),
              size_ref="pb_len"),
        Field("option1", Uint32, optional=True),
        Field("option2", Uint32, optional=True, default=2),
        Field("unknown", String)
    ]
Exemplo n.º 6
0
class FooRequest(RequestBase):
    _struct_ = [Field("buffer", Buffer)]
    _serializer_ = BinarySerializer()
    response_class = FooResponse

    def get_sequence_id(self):
        return None
Exemplo n.º 7
0
class HelloRequest(RequestBase):
    """hello request definition
    """
    _struct_ = [
        Field('len', Uint32),
        Field('seq', Uint32),
        Field('username', String, byte_size=0)
    ]
    _serializer_ = BinarySerializer()
    _length_field_ = "len"
    response_class = HelloResponse

    def get_sequence_id(self):
        return self.seq

    def pre_process(self, chan):
        self.seq = chan.create_seq()
Exemplo n.º 8
0
class Options(Message):
    _struct_ = [
        Field("d", Bool, default=True),
        Field("d2", Bool, default=True, optional=True),
        Field("1", Int32, display="n"),
        Field("a", String, allow_none=True),
        Field("o", String, optional=True),
        Field("x", String)
    ]
Exemplo n.º 9
0
class Binary(Message, HttpBody):
    _struct_ = [
        Field("data", Buffer)
    ]
    _serializer_ = BinarySerializer()

    @property
    def content_type(self):
        return ""

    def loads(self, value, confs={}, deserializer=None):
        return Message.loads(self, value, deserializer=deserializer)

    def dumps(self, serializer=None):
        return Message.dumps(self, serializer=serializer)
Exemplo n.º 10
0
class Mother2(Message):
    _struct_ = [
        Field("name", String),
        Field("age", Int32),
        Field("alive", Bool),
        Field("baby", [
            Field("name", String, optional=True),
            Field("age", Uint32, optional=True),
        ],
              optional=True)
    ]
Exemplo n.º 11
0
class FooBuff(Message):
    _struct_ = [
        Field("buf_len", Uint32, size_ref_hook=lambda x: x - 4),
        Field("buf", Buffer, size_ref="buf_len", size_ref_hook=lambda x: x + 4),
        Field("a", Float)
    ]
Exemplo n.º 12
0
class FooMap(Message):
    _struct_ = [
        Field("map", Map(String, Uint32))
    ]
Exemplo n.º 13
0
class Bar(Message):
    _struct_ = [
        Field("byte_len_string", ByteLenString)
    ]
Exemplo n.º 14
0
class ByteLenString(Message):
    _struct_ = [
        Field("len", Uint8),
        Field("string", String, size_ref="len")
    ]
Exemplo n.º 15
0
class BArrayFixSize0(Message):
    _struct_ = [Field("arr", Array(BItem), array_size=0)]
Exemplo n.º 16
0
class BArrayRefSize(Message):
    _struct_ = [
        Field("size", Uint32),
        Field("arr", Array(BItem), size_ref="size")
    ]
Exemplo n.º 17
0
class StringContainer(Message):
    _struct_ = [
        Field("str", String),
        Field("str2", String, optional=True, encoding='gbk')
    ]
Exemplo n.º 18
0
class MapStruct(Message):
    _struct_ = [
        Field("name", String),
        Field("mm", Map(String, Int32)),
        Field("nm", Map(Int32, Int32))
    ]
Exemplo n.º 19
0
class Baby(Message):
    _struct_ = [
        Field("name", String, optional=True),
        Field("age", Int32, optional=True),
    ]
Exemplo n.º 20
0
class VariantDict(Message):
    _struct_ = [Field("var", Variant)]
Exemplo n.º 21
0
class Variant3(Message):
    _struct_ = [Field("id", Int64, default=3), Field("flag", Bool)]

    @property
    def data(self):
        return 'data_' + str(self.flag)
Exemplo n.º 22
0
class Variant2(Message):
    _struct_ = [Field("id", Int64, default=2), Field("num", Int64)]

    @property
    def data(self):
        return 'data_' + str(self.num)
Exemplo n.º 23
0
class Variant1(Message):
    _struct_ = [Field("id", Int64, default=1), Field("str", String)]

    @property
    def data(self):
        return 'data_' + self.str
Exemplo n.º 24
0
class FooMessage(Message):
    _struct_ = [
        Field("cmd", String, byte_size=16),
        Field("username_len", Uint8, size_ref_hook=lambda x: x - 4),
        Field("username", String, size_ref="username_len", size_ref_hook=lambda x: x + 4),
        Field("version", Uint32, default=0),
        Field("timestamp", Float),
        Field("double_data", Double),
        Field("seq", Uint32),
        Field("len", Uint32),
        Field("uint32_list", Array(Uint32), array_size=5),
        Field("array_size", Uint8, default=0),
        Field("string_list", Array(ByteLenString), size_ref="array_size"),
        Field("bar", Bar)
    ]
Exemplo n.º 25
0
class NumberOwner(Message):
    _struct_ = [Field('one', SingleNumber), Field('extra', Int64)]
Exemplo n.º 26
0
class Carrage(Message):
    _struct_ = [Field("id", Uint64)]
Exemplo n.º 27
0
class DType2(Message):
    _struct_ = [
        Field("name", Map(Int32, String)),
        Field("arr", Array(Int32)),
    ]
Exemplo n.º 28
0
class BItem(Message):
    _struct_ = [
        Field("foo", Uint32),
    ]
Exemplo n.º 29
0
class FastMsg(Message):
    _struct_ = [Field("name", String), Field("id", Int32)]
Exemplo n.º 30
0
class Train(Message):
    _struct_ = [Field("name", String), Field("carrages", Array(Carrage))]