Read a block of data and parse using the given protobuf object.
164943
def read_proto_object(fobj, klass):
    """"""
    log.debug('%s chunk', klass.__name__)
    obj = klass()
    obj.ParseFromString(read_block(fobj))
    log.debug('Header: %s', str(obj))
    return obj
203152
def _read_protos(self, size):
        
        _byte = self._read_unpack(size)
        _prot = ETHERTYPE.get(_byte)
        return _prot
758199
def _deserialize(s, proto):  # type: (bytes, _Proto) -> _Proto
    '''
    
    '''
    if not isinstance(s, bytes):
        raise ValueError('Parameter s must be bytes, but got type: {}'.format(type(s)))

    if not (hasattr(proto, 'ParseFromString') and callable(proto.ParseFromString)):
        raise ValueError('No ParseFromString method is detected. '
                         '\ntype is {}'.format(type(proto)))

    decoded = cast(Optional[int], proto.ParseFromString(s))
    if decoded is not None and decoded != len(s):
        raise google.protobuf.message.DecodeError(
            "Protobuf decoding consumed too few bytes: {} out of {}".format(
                decoded, len(s)))
    return proto
504311
function read(buf, options, forceType) {
	var input = buf;
	if (typeof (buf) !== 'string') {
		assert.buffer(buf, 'buf');
		buf = buf.toString('ascii');
	}

	var lines = buf.trim().split(/[\r\n]+/g);

	var m;
	var si = -1;
	while (!m && si < lines.length) {
		m = lines[++si].match(/*JSSTYLED*/
		    /[-]+[ ]*BEGIN ([A-Z0-9][A-Za-z0-9]+ )?(PUBLIC|PRIVATE) KEY[ ]*[-]+/);
	}
	assert.ok(m, 'invalid PEM header');

	var m2;
	var ei = lines.length;
	while (!m2 && ei > 0) {
		m2 = lines[--ei].match(/*JSSTYLED*/
		    /[-]+[ ]*END ([A-Z0-9][A-Za-z0-9]+ )?(PUBLIC|PRIVATE) KEY[ ]*[-]+/);
	}
	assert.ok(m2, 'invalid PEM footer');

	/* Begin and end banners must match key type */
	assert.equal(m[2], m2[2]);
	var type = m[2].toLowerCase();

	var alg;
	if (m[1]) {
		/* They also must match algorithms, if given */
		assert.equal(m[1], m2[1], 'PEM header and footer mismatch');
		alg = m[1].trim();
	}

	lines = lines.slice(si, ei + 1);

	var headers = {};
	while (true) {
		lines = lines.slice(1);
		m = lines[0].match(/*JSSTYLED*/
		    /^([A-Za-z0-9-]+): (.+)$/);
		if (!m)
			break;
		headers[m[1].toLowerCase()] = m[2];
	}

	/* Chop off the first and last lines */
	lines = lines.slice(0, -1).join('');
	buf = Buffer.from(lines, 'base64');

	var cipher, key, iv;
	if (headers['proc-type']) {
		var parts = headers['proc-type'].split(',');
		if (parts[0] === '4' && parts[1] === 'ENCRYPTED') {
			if (typeof (options.passphrase) === 'string') {
				options.passphrase = Buffer.from(
				    options.passphrase, 'utf-8');
			}
			if (!Buffer.isBuffer(options.passphrase)) {
				throw (new errors.KeyEncryptedError(
				    options.filename, 'PEM'));
			} else {
				parts = headers['dek-info'].split(',');
				assert.ok(parts.length === 2);
				cipher = parts[0].toLowerCase();
				iv = Buffer.from(parts[1], 'hex');
				key = utils.opensslKeyDeriv(cipher, iv,
				    options.passphrase, 1).key;
			}
		}
	}

	if (alg && alg.toLowerCase() === 'encrypted') {
		var eder = new asn1.BerReader(buf);
		var pbesEnd;
		eder.readSequence();

		eder.readSequence();
		pbesEnd = eder.offset + eder.length;

		var method = eder.readOID();
		if (method !== OID_PBES2) {
			throw (new Error('Unsupported PEM/PKCS8 encryption ' +
			    'scheme: ' + method));
		}

		eder.readSequence();	/* PBES2-params */

		eder.readSequence();	/* keyDerivationFunc */
		var kdfEnd = eder.offset + eder.length;
		var kdfOid = eder.readOID();
		if (kdfOid !== OID_PBKDF2)
			throw (new Error('Unsupported PBES2 KDF: ' + kdfOid));
		eder.readSequence();
		var salt = eder.readString(asn1.Ber.OctetString, true);
		var iterations = eder.readInt();
		var hashAlg = 'sha1';
		if (eder.offset < kdfEnd) {
			eder.readSequence();
			var hashAlgOid = eder.readOID();
			hashAlg = OID_TO_HASH[hashAlgOid];
			if (hashAlg === undefined) {
				throw (new Error('Unsupported PBKDF2 hash: ' +
				    hashAlgOid));
			}
		}
		eder._offset = kdfEnd;

		eder.readSequence();	/* encryptionScheme */
		var cipherOid = eder.readOID();
		cipher = OID_TO_CIPHER[cipherOid];
		if (cipher === undefined) {
			throw (new Error('Unsupported PBES2 cipher: ' +
			    cipherOid));
		}
		iv = eder.readString(asn1.Ber.OctetString, true);

		eder._offset = pbesEnd;
		buf = eder.readString(asn1.Ber.OctetString, true);

		if (typeof (options.passphrase) === 'string') {
			options.passphrase = Buffer.from(
			    options.passphrase, 'utf-8');
		}
		if (!Buffer.isBuffer(options.passphrase)) {
			throw (new errors.KeyEncryptedError(
			    options.filename, 'PEM'));
		}

		var cinfo = utils.opensshCipherInfo(cipher);

		cipher = cinfo.opensslName;
		key = utils.pbkdf2(hashAlg, salt, iterations, cinfo.keySize,
		    options.passphrase);
		alg = undefined;
	}

	if (cipher && key && iv) {
		var cipherStream = crypto.createDecipheriv(cipher, key, iv);
		var chunk, chunks = [];
		cipherStream.once('error', function (e) {
			if (e.toString().indexOf('bad decrypt') !== -1) {
				throw (new Error('Incorrect passphrase ' +
				    'supplied, could not decrypt key'));
			}
			throw (e);
		});
		cipherStream.write(buf);
		cipherStream.end();
		while ((chunk = cipherStream.read()) !== null)
			chunks.push(chunk);
		buf = Buffer.concat(chunks);
	}

	/* The new OpenSSH internal format abuses PEM headers */
	if (alg && alg.toLowerCase() === 'openssh')
		return (sshpriv.readSSHPrivate(type, buf, options));
	if (alg && alg.toLowerCase() === 'ssh2')
		return (rfc4253.readType(type, buf, options));

	var der = new asn1.BerReader(buf);
	der.originalInput = input;

	/*
	 * All of the PEM file types start with a sequence tag, so chop it
	 * off here
	 */
	der.readSequence();

	/* PKCS#1 type keys name an algorithm in the banner explicitly */
	if (alg) {
		if (forceType)
			assert.strictEqual(forceType, 'pkcs1');
		return (pkcs1.readPkcs1(alg, type, der));
	} else {
		if (forceType)
			assert.strictEqual(forceType, 'pkcs8');
		return (pkcs8.readPkcs8(alg, type, der));
	}
}
1148129
def _read_proto_resolve(self, length, ptype):
        
        # if ptype == '0800':     # IPv4
        #     _byte = self._read_fileng(4)
        #     _addr = '.'.join([str(_) for _ in _byte])
        # elif ptype == '86dd':   # IPv6
        #     adlt = []       # list of IPv6 hexadecimal address
        #     ctr_ = collections.defaultdict(int)
        #                     # counter for consecutive groups of zero value
        #     ptr_ = 0        # start pointer of consecutive groups of zero value
        #     last = False    # if last hextet/group is zero value
        #     omit = False    # omitted flag, since IPv6 address can omit to `::` only once

        #     for index in range(8):
        #         hex_ = self._read_fileng(2).hex().lstrip('0')

        #         if hex_:    # if hextet is not '', directly append
        #             adlt.append(hex_)
        #             last = False
        #         else:       # if hextet is '', append '0'
        #             adlt.append('0')
        #             if last:    # if last hextet is '', ascend counter
        #                 ctr_[ptr_] += 1
        #             else:       # if last hextet is not '', record pointer
        #                 ptr_ = index
        #                 last = True
        #                 ctr_[ptr_] = 1

        #     ptr_ = max(ctr_, key=ctr_.get) if ctr_ else 0   # fetch start pointer with longest zero values
        #     end_ = ptr_ + ctr_[ptr_]                        # calculate end pointer

        #     if ctr_[ptr_] > 1:      # only omit if zero values are in a consecutive group
        #         del adlt[ptr_:end_] # remove zero values

        #         if ptr_ == 0 and end_ == 8:     # insert `::` if IPv6 unspecified address (::)
        #             adlt.insert(ptr_, '::')
        #         elif ptr_ == 0 or end_ == 8:    # insert `:` if zero values are from start or at end
        #             adlt.insert(ptr_, ':')
        #         else:                           # insert '' otherwise
        #             adlt.insert(ptr_, '')

        #     _addr = ':'.join(adlt)
        # else:
        #     _addr = self._read_fileng(length)
        # return _addr
        if ptype == '0800':     # IPv4
            return ipaddress.ip_address(self._read_fileng(4))
        elif ptype == '86dd':   # IPv6
            return ipaddress.ip_address(self._read_fileng(16))
        else:
            return self._read_fileng(length)
1355242
def to_protobuf(self):
        
        return latlng_pb2.LatLng(latitude=self.latitude, longitude=self.longitude)
609919
def read_block(handle, signal):
    
    signal_len = len(signal)
    it = (x[1] for x in groupby(handle,
        key=lambda row: row.strip()[:signal_len] == signal))
    found_signal = False
    for header in it:
        header = list(header)
        for h in header[:-1]:
            h = h.strip()
            if h[:signal_len] != signal:
                continue
            yield h, []  # Header only, no contents
        header = header[-1].strip()
        if header[:signal_len] != signal:
            continue
        found_signal = True
        seq = list(s.strip() for s in next(it))
        yield header, seq

    if not found_signal:
        handle.seek(0)
        seq = list(s.strip() for s in handle)
        yield None, seq
35092
def _parse_array(self, tensor_proto):
        """"""
        try:
            from onnx.numpy_helper import to_array
        except ImportError:
            raise ImportError("Onnx and protobuf need to be installed. "
                              + "Instructions to install - https://github.com/onnx/onnx")
        if len(tuple(tensor_proto.dims)) > 0:
            np_array = to_array(tensor_proto).reshape(tuple(tensor_proto.dims))
        else:
            # If onnx's params are scalar values without dims mentioned.
            np_array = np.array([to_array(tensor_proto)])
        return nd.array(np_array)
539298
function() {
  /**
   * Protobuf raw bytes stream parser
   * @private {?JsonStreamParser}
   */
  this.jsonStreamParser_ = null;

  /**
   * The current error message, if any.
   * @private {?string}
   */
  this.errorMessage_ = null;

  /**
   * The current position in the streamed data.
   * @private {number}
   */
  this.streamPos_ = 0;

  /**
   * The current parser state.
   * @private {!State}
   */
  this.state_ = State.INIT;

  /**
   * The currently buffered result (parsed JSON objects).
   * @private {!Array<!Object>}
   */
  this.result_ = [];

  /**
   * Whether the status has been parsed.
   * @private {boolean}
   */
  this.statusParsed_ = false;
}
1331522
def parse(self, buffer):
        """"""
        log.debug("parsing a %d byte packet" % len(buffer))
        (opcode,) = struct.unpack(str("!H"), buffer[:2])
        log.debug("opcode is %d" % opcode)
        packet = self.__create(opcode)
        packet.buffer = buffer
        return packet.decode()
1330843
def arp_parse(data):
        
        # Iteratize pkt
        pkt = packet.Packet(data)
        i = iter(pkt)
        eth_pkt = next(i)
        # Ensure it's an ethernet frame.
        assert isinstance(eth_pkt, ethernet.ethernet)

        arp_pkt = next(i)
        if not isinstance(arp_pkt, arp.arp):
            raise ARPPacket.ARPUnknownFormat()

        if arp_pkt.opcode not in (ARP_REQUEST, ARP_REPLY):
            raise ARPPacket.ARPUnknownFormat(
                msg='unsupported opcode %d' % arp_pkt.opcode)

        if arp_pkt.proto != ETH_TYPE_IP:
            raise ARPPacket.ARPUnknownFormat(
                msg='unsupported arp ethtype 0x%04x' % arp_pkt.proto)

        return arp_pkt
180025
public  Structure parsePDBFile(BufferedReader buf)
			throws IOException
			{
		// set the correct max values for parsing...
		loadMaxAtoms = params.getMaxAtoms();
		atomCAThreshold = params.getAtomCaThreshold();


		// (re)set structure

		allModels = new ArrayList<>();
		structure     = new StructureImpl() ;
		currentModel  = null;
		currentChain  = null;
		currentGroup  = null;
		// we initialise to true since at the beginning of the file we are always starting a new molecule
		startOfMolecule = true;
		startOfModel = true;

		seqResChains  = new ArrayList<Chain>();
		siteMap = new LinkedHashMap<String, Site>();
		pdbHeader     = new PDBHeader();
		connects      = new ArrayList<Map<String,Integer>>();
		previousContinuationField = "";
		continuationField = "";
		continuationString = "";
		current_compound = null;
		sourceLines.clear();
		compndLines.clear();
		isLastCompndLine = false;
		isLastSourceLine = false;
		prevMolId = -1;
		entities.clear();
		helixList.clear();
		strandList.clear();
		turnList.clear();
		lengthCheck = -1;
		atomCount = 0;
		atomOverflow = false;
		linkRecords = new ArrayList<LinkRecord>();
		siteToResidueMap.clear();

		blankChainIdsPresent = false;

		parseCAonly = params.isParseCAOnly();

		String line = null;

		while ((line = buf.readLine()) != null) {

			// ignore empty lines
			if ( line.equals("") ||
					(line.equals(NEWLINE))){
				continue;
			}


			// ignore short TER and END lines
			if ( line.startsWith("END")) {
				continue;
			}

			if ( line.length() < 6 && !line.startsWith("TER")) {
				logger.info("Found line length below 6. Ignoring it, line: >" + line +"<" );
				continue;
			}

			String recordName = null;
			if (line.length()<6)
				recordName = line.trim();
			else
				recordName = line.substring (0, 6).trim ();

			try {
				if (recordName.equals("ATOM"))
					pdb_ATOM_Handler(line);
				else if (recordName.equals("SEQRES"))
					pdb_SEQRES_Handler(line);
				else if (recordName.equals("HETATM"))
					pdb_ATOM_Handler(line);
				else if (recordName.equals("MODEL"))
					pdb_MODEL_Handler(line);
				else if (recordName.equals("TER"))
					pdb_TER_Handler();
				else if (recordName.equals("HEADER"))
					pdb_HEADER_Handler(line);
				else if (recordName.equals("AUTHOR"))
					pdb_AUTHOR_Handler(line);
				else if (recordName.equals("TITLE"))
					pdb_TITLE_Handler(line);
				else if (recordName.equals("SOURCE"))
					sourceLines.add(line); //pdb_SOURCE_Handler
				else if (recordName.equals("COMPND"))
					compndLines.add(line); //pdb_COMPND_Handler
				else if (recordName.equals("JRNL"))
					pdb_JRNL_Handler(line);
				else if (recordName.equals("EXPDTA"))
					pdb_EXPDTA_Handler(line);
				else if (recordName.equals("CRYST1"))
					pdb_CRYST1_Handler(line);
				else if (recordName.startsWith("MTRIX"))
					pdb_MTRIXn_Handler(line);
				else if (recordName.equals("REMARK"))
					pdb_REMARK_Handler(line);
				else if (recordName.equals("CONECT"))
					pdb_CONECT_Handler(line);
				else if (recordName.equals("REVDAT"))
					pdb_REVDAT_Handler(line);
				else if (recordName.equals("DBREF"))
					pdb_DBREF_Handler(line);
				else if (recordName.equals("SITE"))
					pdb_SITE_Handler(line);
				else if (recordName.equals("SSBOND"))
					pdb_SSBOND_Handler(line);
				else if (recordName.equals("LINK"))
					pdb_LINK_Handler(line);
				else if ( params.isParseSecStruc()) {
					if ( recordName.equals("HELIX") ) pdb_HELIX_Handler (  line ) ;
					else if (recordName.equals("SHEET")) pdb_SHEET_Handler(line ) ;
					else if (recordName.equals("TURN")) pdb_TURN_Handler(   line ) ;
				}
			} catch (StringIndexOutOfBoundsException | NullPointerException ex) {
				logger.info("Unable to parse [" + line + "]");
			}
		}

		makeCompounds(compndLines, sourceLines);

		triggerEndFileChecks();

		if (params.shouldCreateAtomBonds()) {
			formBonds();
		}

		if ( params.shouldCreateAtomCharges()) {
			addCharges();
		}

		if ( params.isParseSecStruc() && !params.isHeaderOnly())
			setSecStruc();

		// Now correct the alternate location group
		StructureTools.cleanUpAltLocs(structure);

		return structure;

			}
547732
def _DoParse(self):
    
    get4 = lambda x: struct.unpack("<L", self.input_dat[x:x + 4])[0]
    filesize = get4(0x1c)
    offset = get4(0x20)
    coffset = offset
    while coffset < filesize:
      etype = struct.unpack("4s", self.input_dat[coffset:coffset + 4])[0]
      if etype == b"REDR":
        pass
      elif etype in [b"URL "]:
        # Found a valid record
        reclen = get4(coffset + 4) * self.BLOCK_SIZE
        yield self._GetRecord(coffset, reclen)
      coffset += self.BLOCK_SIZE
554378
@Override
    protected void parse() throws ProtocolException {
        cursor = offset;
        optimalEncodingMessageSize = 4;

        // version
        version = readUint32();
        // peek at marker
        byte marker = payload[cursor];
        boolean useSegwit = marker == 0;
        // marker, flag
        if (useSegwit) {
            readBytes(2);
            optimalEncodingMessageSize += 2;
        }
        // txin_count, txins
        parseInputs();
        // txout_count, txouts
        parseOutputs();
        // script_witnesses
        if (useSegwit)
            parseWitnesses();
        // lock_time
        lockTime = readUint32();
        optimalEncodingMessageSize += 4;

        length = cursor - offset;
    }
427780
def _read_block(blocksize, stream):
    
    blockdata = stream.read(blocksize)
    return int.from_bytes(blockdata, 'big')
513649
def _parse_byte_data(self, byte_data):
        """"""
        self.length, self.data_type = unpack('<ii', byte_data[:self.size])
783813
def _parse(self, stream, context, path):
        """"""
        start = stream.tell()
        read_bytes = ""
        if self.max_length:
            read_bytes = stream.read(self.max_length)
        else:
            read_bytes = stream.read()
        skip = read_bytes.find(self.find) + len(self.find)
        stream.seek(start + skip)
        return skip