示例#1
0
 def __init__(self, value = [], template = None):
     """Initialize a new packet.
     
     value -- an input list, or packet. Note that any meta-data such as template of an input packet will be lost.
     template -- the template used to generate this packet. Useful for updating etc...
     """
     list.__init__(self, utilities.flattenList(value))
     self.template = template
示例#2
0
 def _encode_(self, encodeValue, inProcessPacket):
     """Returns the checksum value of the in-process packet.
     
     inProcessPacket -- contains a third-pass in-process packet whose checksum should be computed.
     """
     
     if len(inProcessPacket)>0: #an inProcess packet has been provided
         # create list of all the ints. At this point that should be everything but the checksum token
         checksumList = list(itertools.ifilter(lambda token: type(token) == int, utilities.flattenList(inProcessPacket)))
         return self.CRCInstance.generate(checksumList)  #generate and return checksum
     else: return self
示例#3
0
 def _encode_(self, encodeValue, inProcessPacket):
     """Returns the length of the inProcessPacket, either including or nor itself.
     
     inProcessPacket -- contains a second-pass in-process packet whose length should be measured.
     
     NOTES:  
         -Assumes that there are not multiple length tokens in a single packet. 
         -Because checksums are encoded last, they are not counted in the length value reported by this function.
     """
     
     if len(inProcessPacket)>0:  #an inProcess packet has been provided
         #create and count a list only containing integers from the flattened inProcessPacket
         length = len(list(itertools.ifilter(lambda token: type(token) == int, utilities.flattenList(inProcessPacket))))
         if self.countSelf: length += 1
         return utilities.unsignedIntegerToBytes(length, self.size)  #convert to integer of lenth self.size
     else: return self   #no in-process packet has been provided.