Beispiel #1
0
 class MemcachedProtocol(instructor_model.InstructorModel):
     byte_order = instructor_fields.NetworkByteOrder()
     magic = instructor_fields.UInt8()
     opcode = instructor_fields.UInt8()
     key_length = instructor_fields.UInt16()
     ext_length = instructor_fields.UInt8()
     data_type = instructor_fields.UInt8()
     status = instructor_fields.UInt16()
     body_length = instructor_fields.ULong32()
     opaque = instructor_fields.ULong32()
     cas = instructor_fields.UInt64()
Beispiel #2
0
 class Protocol(instructor_model.InstructorModel):
     byte_order = instructor_fields.BigEndianByteOrder()
     protocol = instructor_fields.UInt16(default=7)
     received_status = instructor_fields.UInt8(default=0)
     urgency = instructor_fields.UInt8(default=0)
     msglen = instructor_fields.UInt32(default=0)
     data = instructor_fields.Str(msglen, default='')
Beispiel #3
0
    def test_protocol_creation_str_length_is_defined(self):
        protocol = 9
        name = '0123456789'
        length = 5

        fields = {
            'byte_order': instructor_fields.NetworkByteOrder(),
            'protocol': instructor_fields.UInt16(default=protocol),
            'name': instructor_fields.Str(length)
        }
        Protocol = type('BaseProtocol', (instructor_model.InstructorModel, ),
                        fields)

        package = struct.pack('>H{}s'.format(length), protocol,
                              name.encode('utf-8'))

        p = Protocol(package)
        self.assertTrue(p.protocol == protocol)
        self.assertTrue(p.name.decode('utf-8') == name[:length])

        self.assertTrue(p.pack() == package)
Beispiel #4
0
    def test_protocol_creation_str_length_depended_as_str(self):
        protocol = 9
        length = 5
        name = '0123456789'

        fields = {
            'byte_order': instructor_fields.NetworkByteOrder(),
            'protocol': instructor_fields.UInt16(default=protocol),
            'length': instructor_fields.UInt32(default=length),
            'name': instructor_fields.Str('length')
        }
        Protocol = type('BaseProtocol', (instructor_model.InstructorModel, ),
                        fields)

        package = struct.pack('>HI{}s'.format(length), protocol, length, name)

        p = Protocol(package)
        self.assertTrue(p.protocol == protocol)
        self.assertTrue(p.length == length)
        self.assertTrue(p.name == name[:length])

        self.assertTrue(p.pack() == package)
Beispiel #5
0
 class Protocol(instructor_model.InstructorModel):
     byte_order = instructor_fields.BigEndianByteOrder()
     protocol = instructor_fields.UInt16()
     received_status = instructor_fields.UInt8()
     urgency = instructor_fields.UInt8()
     data = instructor_fields.Str(8)
Beispiel #6
0
 class Protocol(instructor_model.InstructorModel):
     byte_order = instructor_fields.NetworkByteOrder()
     protocol = instructor_fields.UInt16(default=proto)
     length = instructor_fields.UInt32(default=str_length)
     name = instructor_fields.Str('length')
Beispiel #7
0
 class Protocol(instructor_model.InstructorModel):
     byte_order = instructor_fields.BigEndianByteOrder()
     protocol = instructor_fields.UInt16(default=8)