#!/usr/bin/python # -*- coding: GBK -*- #------------------------------------------------------------------------------- # #------------------------------------------------------------------------------- # #·â°üÏà¹ØµÄ¹«¹²¶¨Òå from ctypes import (Structure, c_ubyte, memmove, string_at, sizeof, addressof) class tagHead(Structure): _pack_ = 1 _fields_ = [ ("Cmd", c_ubyte), ("SubCmd", c_ubyte), ] def __init__(self): self.Clear() return def ReadData(self, stringData, _pos=0, _len=0): self.Clear() memmove(addressof(self), stringData[_pos:], self.GetLength()) return _pos + self.GetLength() def Clear(self): self.Cmd = 0 self.SubCmd = 0 return def GetLength(self): return sizeof(tagHead) def GetBuffer(self): return string_at(addressof(self), self.GetLength()) def OutputString(self): DumpString = ''' Cmd:%d, SubCmd:%d '''\ %( self.Cmd, self.SubCmd ) return DumpString