Given a packet, this turns it into a dictionary ... is this useful?

	in: packet, array of numbers
	out: dictionary (key, value)
497666
def packetToDict(pkt):
	

	d = {
		'id': pkt[4],
		# 'instruction': xl320.InstrToStr[pkt[7]],
		# 'length': (pkt[6] << 8) + pkt[5],
		# 'params': pkt[8:-2],
		'Model Number': (pkt[10] << 8) + pkt[9],
		'Firmware Ver': pkt[11],
		'Error': ErrorStatusMsg[pkt[8]],
		# 'crc': pkt[-2:]
	}

	return d
749623
def to_dict(cls):
        
        return dict((item.name, item.number) for item in iter(cls))
373560
def pairs_to_dict(response, encoding):
    ""
    it = iter(response)
    return dict(((k.decode(encoding), v) for k, v in zip(it, it)))
650711
def _unpack_sdp_into_packet(packet, bytestring):
    
    # Extract the header and the data from the packet
    packet.data = bytestring[10:]  # Everything but the header

    # Unpack the header
    (flags, packet.tag, dest_cpu_port, src_cpu_port,
     packet.dest_y, packet.dest_x,
     packet.src_y, packet.src_x) = struct.unpack_from('<2x8B', bytestring)
    packet.reply_expected = flags == FLAG_REPLY

    # Neaten up the combined VCPU and port fields
    packet.dest_cpu = dest_cpu_port & 0x1f
    packet.dest_port = (dest_cpu_port >> 5)  # & 0x07
    packet.src_cpu = src_cpu_port & 0x1f
    packet.src_port = (src_cpu_port >> 5)
881538
def as_dict(self):
        """"""
        return {k: unfreeze(v)
                for k, v in self.items()
                if not self.is_special(k)}
264233
def to_msgpack(*a)
      msg = {
        'msgpack_class' => self.class.name,
        'data'          => instance_variables.inject({}) do |m, ivar|
                             name = ivar.to_s.sub(/@/, '')
                             m[name] = instance_variable_get(ivar) unless NOT_SERIALIZED.include?(name)
                             m
                           end,
        'size'          => nil
      }.to_msgpack(*a)
      @size = msg.size
      # For msgpack 0.5.1 the to_msgpack result is a MessagePack::Packer so need to convert to string
      msg = msg.to_s.sub!(PACKET_SIZE_REGEXP) { |m| "size" + @size.to_msgpack }
      msg
    end
847801
def fromdict(dict):
        
        return State(hb_decode(dict["f_key"]),
                     hb_decode(dict["alpha_key"]),
                     dict["chunks"],
                     dict["encrypted"],
                     hb_decode(dict["iv"]),
                     hb_decode(dict["hmac"]))
994842
def parse_packet(data, format=None):
    
    unpacked = struct.unpack(BASE_FORMAT, data[:_FORMAT_SIZE])
    psize, protocol, mac, gateway, time, ptype = unpacked
    header = Header(psize, protocol, mac, gateway, time, ptype)
    return header, data[_FORMAT_SIZE:]
816674
def to_s
      # Encode the fixed header
      header = [
        ((type_id.to_i & 0x0F) << 4) |
          (flags[3] ? 0x8 : 0x0) |
          (flags[2] ? 0x4 : 0x0) |
          (flags[1] ? 0x2 : 0x0) |
          (flags[0] ? 0x1 : 0x0)
      ]

      # Get the packet's variable header and payload
      body = encode_body

      # Check that that packet isn't too big
      body_length = body.bytesize
      if body_length > 268_435_455
        raise 'Error serialising packet: body is more than 256MB'
      end

      # Build up the body length field bytes
      loop do
        digit = (body_length % 128)
        body_length = body_length.div(128)
        # if there are more digits to encode, set the top bit of this digit
        digit |= 0x80 if body_length > 0
        header.push(digit)
        break if body_length <= 0
      end

      # Convert header to binary and add on body
      header.pack('C*') + body
    end
1190186
def as_dict(self):
        
        out = dict({})
        for key in self.keys():
            if self._has_delimiter(key):
                pk, ck = key.split(self._delimiter, 1)
                if self._has_delimiter(ck):
                    ck = ck.split(self._delimiter, 1)[0]
                if isinstance(self._values[pk], FlatterDict) and pk not in out:
                    out[pk] = dict()
                if isinstance(self._values[pk][ck], FlatterDict):
                    if self._values[pk][ck].original_type == tuple:
                        out[pk][ck] = tuple(self._child_as_list(pk, ck))
                    elif self._values[pk][ck].original_type == list:
                        out[pk][ck] = self._child_as_list(pk, ck)
                    elif self._values[pk][ck].original_type == set:
                        out[pk][ck] = set(self._child_as_list(pk, ck))
                    elif self._values[pk][ck].original_type == dict:
                        out[pk][ck] = self._values[pk][ck].as_dict()
                else:
                    out[pk][ck] = self._values[pk][ck]
            else:
                out[key] = self._values[key]
        return out
858587
def packet2chain(packet):
    """"""
    chain = [type(packet).__name__]
    payload = packet.data
    while not isinstance(payload, bytes):
        chain.append(type(payload).__name__)
        payload = payload.data
    return ':'.join(chain)
899626
def as_dict(self):
        
        out = dict({})
        for key in self.keys():
            if self._has_delimiter(key):
                pk, ck = key.split(self._delimiter, 1)
                if self._has_delimiter(ck):
                    ck = ck.split(self._delimiter, 1)[0]
                if isinstance(self._values[pk], FlatDict) and pk not in out:
                    out[pk] = dict()
                if isinstance(self._values[pk][ck], FlatDict):
                    out[pk][ck] = self._values[pk][ck].as_dict()
                else:
                    out[pk][ck] = self._values[pk][ck]
            else:
                out[key] = self._values[key]
        return out
283750
def _dict_to_string(dictionary):
    '''
    
    '''
    ret = ''
    for key, val in sorted(dictionary.items()):
        if isinstance(val, dict):
            for line in _dict_to_string(val):
                ret += six.text_type(key) + '-' + line + '\n'
        elif isinstance(val, list):
            text = ' '.join([six.text_type(item) for item in val])
            ret += six.text_type(key) + ': ' + text + '\n'
        else:
            ret += six.text_type(key) + ': ' + six.text_type(val) + '\n'
    return ret.splitlines()
1339999
def recarray2dict(recarray):
    """"""
    # TODO: subarrays
    result = {}
    for descr, value in zip(recarray.dtype.descr, recarray):
        name, dtype = descr[:2]
        if dtype[1] == 'S':
            value = bytes2str(stripnull(value))
        elif value.ndim < 2:
            value = value.tolist()
        result[name] = value
    return result
132298
def unpack_bytes(self, obj_bytes, encoding=None):
        """"""
        assert self.bytes_to_dict or self.string_to_dict
        encoding = encoding or self.default_encoding
        LOGGER.debug('%r decoding %d bytes with encoding of %s',
                     self, len(obj_bytes), encoding)
        if self.bytes_to_dict:
            return escape.recursive_unicode(self.bytes_to_dict(obj_bytes))
        return self.string_to_dict(obj_bytes.decode(encoding))
1146523
def _shrink_dict(self, shrink):
        
        res = {}

        if len(shrink.keys()) == 1 and "value" in shrink:
            return self.shrink(shrink['value'])
        else:
            for a in shrink:
                res[a] = self.shrink(shrink[a])

                if not res[a]:
                    del res[a]
        return res
1306285
def DecodePacket(self, packet):
        """"""

        try:
            (self.code, self.id, length, self.authenticator) = \
                    struct.unpack('!BBH16s', packet[0:20])
        except struct.error:
            raise PacketError('Packet header is corrupt')
        if len(packet) != length:
            raise PacketError('Packet has invalid length')
        if length > 8192:
            raise PacketError('Packet length is too long (%d)' % length)

        self.clear()

        packet = packet[20:]
        while packet:
            try:
                (key, attrlen) = struct.unpack('!BB', packet[0:2])
            except struct.error:
                raise PacketError('Attribute header is corrupt')

            if attrlen < 2:
                raise PacketError(
                        'Attribute length is too small (%d)' % attrlen)

            value = packet[2:attrlen]
            if key == 26:
                # 26 is the Vendor-Specific attribute
                (vendor, subattrs) = self._PktDecodeVendorAttribute(value)
                if vendor is None:
                    self.setdefault(key, []).append(value)
                else:
                    for (k, v) in subattrs:
                        self.setdefault((vendor, k), []).append(v)
            else:
                self.setdefault(key, []).append(value)

            packet = packet[attrlen:]