Return an Ethernet object reconstructed from raw bytes, or an
        Exception if we can't resurrect the packet.
774914
def from_bytes(self, raw):
        ''''''
        if len(raw) < Ethernet._MINLEN:
            raise NotEnoughDataError("Not enough bytes ({}) to reconstruct an "
                "Ethernet object".format(len(raw)))
        dst,src,ethertype = struct.unpack(Ethernet._PACKFMT, 
            raw[:Ethernet._MINLEN])
        self.src = src
        self.dst = dst
        if ethertype <= 1500:
            self.ethertype = EtherType.NoType
        else:
            self.ethertype = ethertype
        return raw[Ethernet._MINLEN:]
139378
def recv_raw(self, x=MTU):
        """"""  # noqa: E501
        ll = self.ins.datalink()
        if ll in conf.l2types:
            cls = conf.l2types[ll]
        else:
            cls = conf.default_l2
            warning("Unable to guess datalink type (interface=%s linktype=%i). Using %s",  # noqa: E501
                    self.iface, ll, cls.name)

        pkt = None
        while pkt is None:
            pkt = self.ins.next()
            if pkt is not None:
                ts, pkt = pkt
            if pkt is None and scapy.consts.WINDOWS:
                raise TimeoutElapsed  # To understand this behavior, have a look at L2pcapListenSocket's note  # noqa: E501
            if pkt is None:
                return None, None, None
        return cls, pkt, ts
729581
def from_raw(conn, raw):
        ''''''
        frame_type = struct.unpack('>l', raw[0:4])[0]
        message = raw[4:]
        if frame_type == FRAME_TYPE_MESSAGE:
            return Message(conn, frame_type, message)
        elif frame_type == FRAME_TYPE_RESPONSE:
            return Response(conn, frame_type, message)
        elif frame_type == FRAME_TYPE_ERROR:
            return Error(conn, frame_type, message)
        else:
            raise TypeError('Unknown frame type: %s' % frame_type)
1072988
def from_bytes(cls, bitstream):
        '''
        
        '''
        packet = cls()

        # Convert to ConstBitStream (if not already provided)
        if not isinstance(bitstream, ConstBitStream):
            if isinstance(bitstream, Bits):
                bitstream = ConstBitStream(auto=bitstream)
            else:
                bitstream = ConstBitStream(bytes=bitstream)

        # Read the type
        type_nr = bitstream.read('uint:4')
        if type_nr != packet.message_type:
            msg = 'Invalid bitstream for a {0} packet'
            class_name = packet.__class__.__name__
            raise ValueError(msg.format(class_name))

        # Read the flags
        packet.proxy_map_reply = bitstream.read('bool')

        # Skip reserved bits
        packet._reserved1 = bitstream.read(1)

        # NATT bits
        has_xtr_site_id = bitstream.read('bool')
        packet.for_rtr = bitstream.read('bool')

        # Skip reserved bits
        packet._reserved2 = bitstream.read(15)

        # Read the rest of the flags
        packet.want_map_notify = bitstream.read('bool')

        # Store the record count until we need it
        record_count = bitstream.read('uint:8')

        # Read the nonce
        packet.nonce = bitstream.read('bytes:8')

        # Read the key id
        packet.key_id = bitstream.read('uint:16')

        # Read the authentication data
        data_length = bitstream.read('uint:16')
        packet.authentication_data = bitstream.read('bytes:%d' % data_length)

        # Read the records
        for dummy in range(record_count):
            record = MapRegisterRecord.from_bytes(bitstream)
            packet.records.append(record)

        # Read the xtr-id and site-id
        if has_xtr_site_id:
            packet.xtr_id = bitstream.read('uint:128')
            packet.site_id = bitstream.read('uint:64')

        # Verify that the properties make sense
        packet.sanitize()

        return packet
943323
def decode(self, encoded_packet):
        """"""
        b64 = False
        if not isinstance(encoded_packet, binary_types):
            encoded_packet = encoded_packet.encode('utf-8')
        elif not isinstance(encoded_packet, bytes):
            encoded_packet = bytes(encoded_packet)
        self.packet_type = six.byte2int(encoded_packet[0:1])
        if self.packet_type == 98:  # 'b' --> binary base64 encoded packet
            self.binary = True
            encoded_packet = encoded_packet[1:]
            self.packet_type = six.byte2int(encoded_packet[0:1])
            self.packet_type -= 48
            b64 = True
        elif self.packet_type >= 48:
            self.packet_type -= 48
            self.binary = False
        else:
            self.binary = True
        self.data = None
        if len(encoded_packet) > 1:
            if self.binary:
                if b64:
                    self.data = base64.b64decode(encoded_packet[1:])
                else:
                    self.data = encoded_packet[1:]
            else:
                try:
                    self.data = self.json.loads(
                        encoded_packet[1:].decode('utf-8'))
                    if isinstance(self.data, int):
                        # do not allow integer payloads, see
                        # github.com/miguelgrinberg/python-engineio/issues/75
                        # for background on this decision
                        raise ValueError
                except ValueError:
                    self.data = encoded_packet[1:].decode('utf-8')
1140669
def from_bytes(self, raw):
        ''''''
        if len(raw) < 4:
            raise NotEnoughDataError("Not enough bytes ({}) to reconstruct a Null object".format(len(raw)))
        fields = struct.unpack('=I', raw[:4])
        self._af = fields[0]
        return raw[4:]
241495
def _download_raw(self, url=None):
        """"""
        if url is None:
            url = self.url
        req = request.Request(url, headers=self.HEADERS_PLAIN)
        return request.urlopen(req).read().decode("utf8")
440281
def handle_raw_packet(self, raw_packet):
        """"""
        log.debug('got packet: %s', raw_packet)
        if rflink_log:
            print(raw_packet, file=rflink_log)
            rflink_log.flush()
        packet = None
        try:
            packet = decode_packet(raw_packet)
        except:
            log.exception('failed to parse packet: %s', packet)

        log.debug('decoded packet: %s', packet)

        if packet:
            if 'ok' in packet:
                # handle response packets internally
                log.debug('command response: %s', packet)
                self._last_ack = packet
                self._command_ack.set()
            else:
                self.handle_packet(packet)
        else:
            log.warning('no valid packet')
996804
def from_bytes(self, bytes_representation, resource=None):
        
        text = bytes_representation.decode(self.encoding)
        return self.from_string(text, resource=resource)
2632
function processUncompressedData (o) {
  // Resets the packet counter back to zero
  o.lastSampleNumber = k.OBCIGanglionByteIdUncompressed;  // used to find dropped packets

  for (let i = 0; i < 4; i++) {
    o.decompressedSamples[0][i] = utilitiesModule.interpret24bitAsInt32(o.rawDataPacket.slice(1 + (i * 3), 1 + (i * 3) + 3));  // seed the decompressor
  }

  return [buildSample(0, o.decompressedSamples[0], o.sendCounts)];
}
520889
def unpack(cls, rawpacket):
        

        structs_ = get_structs_for_rawpacket(rawpacket)

        for struct_ in structs_:
            try:
                return cls(*struct_.unpack(rawpacket))
            except struct.error:
                raise
                # Try next one.
                pass

        # Packet ID 0xff is a pseudo-packet representing
        # packets unknown to `python-TSIP` in their raw format.
        #
        return cls(0xff, rawpacket)
296487
def from_bytes(cls, bitstream):
        '''
        
        '''
        packet = cls()

        # Convert to ConstBitStream (if not already provided)
        if not isinstance(bitstream, ConstBitStream):
            if isinstance(bitstream, Bits):
                bitstream = ConstBitStream(auto=bitstream)
            else:
                bitstream = ConstBitStream(bytes=bitstream)

        # Read the type
        type_nr = bitstream.read('uint:4')
        if type_nr != packet.message_type:
            msg = 'Invalid bitstream for a {0} packet'
            class_name = packet.__class__.__name__
            raise ValueError(msg.format(class_name))

        # Skip reserved bits
        packet._reserved1 = bitstream.read(20)

        # Store the record count
        record_count = bitstream.read('uint:8')

        # Store the nonce
        packet.nonce = bitstream.read('bytes:8')

        # Read the records
        for dummy in range(record_count):
            record = MapReferralRecord.from_bytes(bitstream)
            packet.records.append(record)

        # Verify that the properties make sense
        packet.sanitize()

        return packet
214743
def handle_raw_tx_packet(self, writer, raw_packet):
        """"""
        peer = writer.get_extra_info('peername')
        log.debug(' %s:%s: processing data: %s', peer[0], peer[1], raw_packet)
        packet = None
        try:
            packet = decode_tx_packet(raw_packet)
        except:
            log.exception(' %s:%s: failed to parse packet: %s',
                          peer[0], peer[1], packet)

        log.debug(' %s:%s: decoded packet: %s', peer[0], peer[1], packet)
        if self.protocol and packet:
            if not ';PING;' in raw_packet:
                log.info(' %s:%s: forwarding packet %s to RFLink', peer[0], peer[1], raw_packet)
            else:
                log.debug(' %s:%s: forwarding packet %s to RFLink', peer[0], peer[1], raw_packet)
            yield from self.forward_packet(writer, packet, raw_packet)
        else:
            log.warning(' %s:%s: no valid packet %s', peer[0], peer[1], packet)
1335978
public static final Object reconstruct(String string, ExternalContext ctx)
    {
        byte[] bytes;
        try
        {
            if(log.isLoggable(Level.FINE))
            {
                log.fine("Processing state : " + string);
            }

            bytes = string.getBytes(ZIP_CHARSET);
            bytes = decode(bytes);
            if(isSecure(ctx))
            {
                bytes = decrypt(bytes, ctx);
            }
            if( enableCompression(ctx) )
            {
                bytes = decompress(bytes);
            }
            return getAsObject(bytes, ctx);
        }
        catch (Throwable e)
        {
            if (log.isLoggable(Level.FINE))
            {
                log.log(Level.FINE, "View State cannot be reconstructed", e);
            }
            return null;
        }
    }
1191389
def loads(astring):
        """"""
        try:
            return marshal.loads(zlib.decompress(astring))
        except zlib.error as e:
            raise SerializerError(
                'Cannot decompress object ("{}")'.format(str(e))
            )
        except Exception as e:
            # marshal module does not provide a proper Exception model
            raise SerializerError(
                'Cannot restore object ("{}")'.format(str(e))
            )
429963
public Packet decode(ByteBuffer bytes) {
        return processPacket(Memories.wrap(bytes, memoryProperties.getCheckBounds()));
    }
1236672
def decode_network_packet(buf):
    
    off = 0
    blen = len(buf)

    while off < blen:
        ptype, plen = header.unpack_from(buf, off)

        if plen > blen - off:
            raise ValueError("Packet longer than amount of data in buffer")

        if ptype not in _decoders:
            raise ValueError("Message type %i not recognized" % ptype)

        yield ptype, _decoders[ptype](ptype, plen, buf[off:])
        off += plen