示例#1
0
    def testDecoderBase(self):
        # Allocate message, write reference payload
        msg = Message()
        msg.init(MSGID)
        msg.buf.skip(12)
        msg.buf.write(PAYLOAD)
        msg.finish()

        # Allocate and init decoder
        dec = Decoder()
        dec.init(msg)

        # Read
        try:
            i8 = dec.readI8()
            u8 = dec.readU8()
            i16 = dec.readI16()
            u16 = dec.readU16()
            i32 = dec.readI32()
            u32 = dec.readU32()
            i64 = dec.readI64()
            u64 = dec.readU64()
            sval = dec.readStr()
            buf = dec.readBuf()
            f32 = dec.readF32()
            f64 = dec.readF64()

            # Check
            self.assertEqual(VAL_I8, i8)
            self.assertEqual(VAL_U8, u8)
            self.assertEqual(VAL_I16, i16)
            self.assertEqual(VAL_U16, u16)
            self.assertEqual(VAL_I32, i32)
            self.assertEqual(VAL_U32, u32)
            self.assertEqual(VAL_I64, i64)
            self.assertEqual(VAL_U64, u64)
            self.assertEqual(VAL_STR, sval)
            self.assertEqual(len(VAL_BUF), len(buf))
            self.assertEqual(VAL_BUF, buf)
            self.assertEqual(VAL_F32, f32)
            self.assertEqual(VAL_F64, f64)
        except DecodeException as ex:
            self.fail(ex.message)

        # Clear
        dec.clear()
        msg.clear()
示例#2
0
    def testDecoderBase(self):
        # Allocate message, write reference payload
        msg = Message()
        msg.init(MSGID)
        msg.buf.skip(12)
        msg.buf.write(PAYLOAD)
        msg.finish()

        # Allocate and init decoder
        dec = Decoder()
        dec.init(msg)

        # Read
        try:
            i8 = dec.readI8()
            u8 = dec.readU8()
            i16 = dec.readI16()
            u16 = dec.readU16()
            i32 = dec.readI32()
            u32 = dec.readU32()
            i64 = dec.readI64()
            u64 = dec.readU64()
            sval = dec.readStr()
            buf = dec.readBuf()
            f32 = dec.readF32()
            f64 = dec.readF64()

            # Check
            self.assertEqual(VAL_I8, i8)
            self.assertEqual(VAL_U8, u8)
            self.assertEqual(VAL_I16, i16)
            self.assertEqual(VAL_U16, u16)
            self.assertEqual(VAL_I32, i32)
            self.assertEqual(VAL_U32, u32)
            self.assertEqual(VAL_I64, i64)
            self.assertEqual(VAL_U64, u64)
            self.assertEqual(VAL_STR, sval)
            self.assertEqual(len(VAL_BUF), len(buf))
            self.assertEqual(VAL_BUF, buf)
            self.assertEqual(VAL_F32, f32)
            self.assertEqual(VAL_F64, f64)
        except DecodeException as ex:
            self.fail(ex.message)

        # Clear
        dec.clear()
        msg.clear()
示例#3
0
 def dump(self):
     dec = Decoder()
     dec.init(self)
     res = dec.dump()
     dec.clear()
     return res
示例#4
0
 def read(self, fmt):
     dec = Decoder()
     dec.init(self)
     res = dec.read(fmt)
     dec.clear()
     return res
示例#5
0
 def dump(self):
     dec = Decoder()
     dec.init(self)
     res = dec.dump()
     dec.clear()
     return res
示例#6
0
 def read(self, fmt):
     dec = Decoder()
     dec.init(self)
     res = dec.read(fmt)
     dec.clear()
     return res