Пример #1
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='')
Пример #2
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)
Пример #3
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)
Пример #4
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)
Пример #5
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')