Parse a given Buffer
@param {Buffer} buffer
@param {Number} [offset=0]
@return {CHS}
488889
function( buffer, offset ) {

    if( !Buffer.isBuffer( buffer ) )
      throw new TypeError( 'Value must be a buffer' )

    offset = offset || 0

    return this.fromNumber( buffer.readUIntLE( offset, 3 ) )

  }
1279439
private boolean parseLine(ByteBuffer buffer) {
        boolean handle = false;

        // Process headers
        while (_state.ordinal() < State.HEADER.ordinal() && buffer.hasRemaining() && !handle) {
            // process each character
            HttpTokens.Token t = next(buffer);
            if (t == null)
                break;

            if (_maxHeaderBytes > 0 && ++_headerBytes > _maxHeaderBytes) {
                if (_state == State.URI) {
                    LOG.warn("URI is too large >" + _maxHeaderBytes);
                    throw new BadMessageException(HttpStatus.URI_TOO_LONG_414);
                } else {
                    if (_requestHandler != null)
                        LOG.warn("request is too large >" + _maxHeaderBytes);
                    else
                        LOG.warn("response is too large >" + _maxHeaderBytes);
                    throw new BadMessageException(HttpStatus.REQUEST_HEADER_FIELDS_TOO_LARGE_431);
                }
            }

            switch (_state) {
                case METHOD:
                    switch (t.getType()) {
                        case SPACE:
                            _length = _string.length();
                            _methodString = takeString();

                            if (_compliances.contains(HttpComplianceSection.METHOD_CASE_SENSITIVE)) {
                                HttpMethod method = HttpMethod.CACHE.get(_methodString);
                                if (method != null)
                                    _methodString = method.asString();
                            } else {
                                HttpMethod method = HttpMethod.INSENSITIVE_CACHE.get(_methodString);

                                if (method != null) {
                                    if (!method.asString().equals(_methodString))
                                        handleViolation(HttpComplianceSection.METHOD_CASE_SENSITIVE, _methodString);
                                    _methodString = method.asString();
                                }
                            }

                            setState(State.SPACE1);
                            break;

                        case LF:
                            throw new BadMessageException("No URI");

                        case ALPHA:
                        case DIGIT:
                        case TCHAR:
                            _string.append(t.getChar());
                            break;

                        default:
                            throw new IllegalCharacterException(_state, t, buffer);
                    }
                    break;

                case RESPONSE_VERSION:
                    switch (t.getType()) {
                        case SPACE:
                            _length = _string.length();
                            String version = takeString();
                            _version = HttpVersion.CACHE.get(version);
                            checkVersion();
                            setState(State.SPACE1);
                            break;

                        case ALPHA:
                        case DIGIT:
                        case TCHAR:
                        case VCHAR:
                        case COLON:
                            _string.append(t.getChar());
                            break;
                        default:
                            throw new IllegalCharacterException(_state, t, buffer);
                    }
                    break;

                case SPACE1:
                    switch (t.getType()) {
                        case SPACE:
                            break;

                        case ALPHA:
                        case DIGIT:
                        case TCHAR:
                        case VCHAR:
                        case COLON:
                            if (_responseHandler != null) {
                                if (t.getType() != HttpTokens.Type.DIGIT)
                                    throw new IllegalCharacterException(_state, t, buffer);
                                setState(State.STATUS);
                                setResponseStatus(t.getByte() - '0');
                            } else {
                                _uri.reset();
                                setState(State.URI);
                                // quick scan for space or EoBuffer
                                if (buffer.hasArray()) {
                                    byte[] array = buffer.array();
                                    int p = buffer.arrayOffset() + buffer.position();
                                    int l = buffer.arrayOffset() + buffer.limit();
                                    int i = p;
                                    while (i < l && array[i] > HttpTokens.SPACE)
                                        i++;

                                    int len = i - p;
                                    _headerBytes += len;

                                    if (_maxHeaderBytes > 0 && ++_headerBytes > _maxHeaderBytes) {
                                        LOG.warn("URI is too large >" + _maxHeaderBytes);
                                        throw new BadMessageException(HttpStatus.URI_TOO_LONG_414);
                                    }
                                    _uri.append(array, p - 1, len + 1);
                                    buffer.position(i - buffer.arrayOffset());
                                } else
                                    _uri.append(t.getByte());
                            }
                            break;

                        default:
                            throw new BadMessageException(HttpStatus.BAD_REQUEST_400, _requestHandler != null ? "No URI" : "No Status");
                    }
                    break;

                case STATUS:
                    switch (t.getType()) {
                        case SPACE:
                            setState(State.SPACE2);
                            break;

                        case DIGIT:
                            _responseStatus = _responseStatus * 10 + (t.getByte() - '0');
                            if (_responseStatus >= 1000)
                                throw new BadMessageException("Bad status");
                            break;

                        case LF:
                            setState(State.HEADER);
                            handle = _responseHandler.startResponse(_version, _responseStatus, null) || handle;
                            break;

                        default:
                            throw new IllegalCharacterException(_state, t, buffer);
                    }
                    break;

                case URI:
                    switch (t.getType()) {
                        case SPACE:
                            setState(State.SPACE2);
                            break;

                        case LF:
                            // HTTP/0.9
                            if (complianceViolation(HttpComplianceSection.NO_HTTP_0_9, "No request version"))
                                throw new BadMessageException("HTTP/0.9 not supported");
                            handle = _requestHandler.startRequest(_methodString, _uri.toString(), HttpVersion.HTTP_0_9);
                            setState(State.END);
                            BufferUtils.clear(buffer);
                            handle = handleHeaderContentMessage() || handle;
                            break;

                        case ALPHA:
                        case DIGIT:
                        case TCHAR:
                        case VCHAR:
                        case COLON:
                        case OTEXT:
                            _uri.append(t.getByte());
                            break;

                        default:
                            throw new IllegalCharacterException(_state, t, buffer);
                    }
                    break;

                case SPACE2:
                    switch (t.getType()) {
                        case SPACE:
                            break;

                        case ALPHA:
                        case DIGIT:
                        case TCHAR:
                        case VCHAR:
                        case COLON:
                            _string.setLength(0);
                            _string.append(t.getChar());
                            if (_responseHandler != null) {
                                _length = 1;
                                setState(State.REASON);
                            } else {
                                setState(State.REQUEST_VERSION);

                                // try quick look ahead for HTTP Version
                                HttpVersion version;
                                if (buffer.position() > 0 && buffer.hasArray())
                                    version = HttpVersion.lookAheadGet(buffer.array(), buffer.arrayOffset() + buffer.position() - 1, buffer.arrayOffset() + buffer.limit());
                                else
                                    version = HttpVersion.CACHE.getBest(buffer, 0, buffer.remaining());

                                if (version != null) {
                                    int pos = buffer.position() + version.asString().length() - 1;
                                    if (pos < buffer.limit()) {
                                        byte n = buffer.get(pos);
                                        if (n == HttpTokens.CARRIAGE_RETURN) {
                                            _cr = true;
                                            _version = version;
                                            checkVersion();
                                            _string.setLength(0);
                                            buffer.position(pos + 1);
                                        } else if (n == HttpTokens.LINE_FEED) {
                                            _version = version;
                                            checkVersion();
                                            _string.setLength(0);
                                            buffer.position(pos);
                                        }
                                    }
                                }
                            }
                            break;

                        case LF:
                            if (_responseHandler != null) {
                                setState(State.HEADER);
                                handle = _responseHandler.startResponse(_version, _responseStatus, null) || handle;
                            } else {
                                // HTTP/0.9
                                if (complianceViolation(HttpComplianceSection.NO_HTTP_0_9, "No request version"))
                                    throw new BadMessageException("HTTP/0.9 not supported");

                                handle = _requestHandler.startRequest(_methodString, _uri.toString(), HttpVersion.HTTP_0_9);
                                setState(State.END);
                                BufferUtils.clear(buffer);
                                handle = handleHeaderContentMessage() || handle;
                            }
                            break;

                        default:
                            throw new IllegalCharacterException(_state, t, buffer);
                    }
                    break;

                case REQUEST_VERSION:
                    switch (t.getType()) {
                        case LF:
                            if (_version == null) {
                                _length = _string.length();
                                _version = HttpVersion.CACHE.get(takeString());
                            }
                            checkVersion();

                            // Should we try to cache header fields?
                            if (_fieldCache == null && _version.getVersion() >= HttpVersion.HTTP_1_1.getVersion() && _handler.getHeaderCacheSize() > 0) {
                                int header_cache = _handler.getHeaderCacheSize();
                                _fieldCache = new ArrayTernaryTrie<>(header_cache);
                            }

                            setState(State.HEADER);

                            handle = _requestHandler.startRequest(_methodString, _uri.toString(), _version) || handle;
                            continue;

                        case ALPHA:
                        case DIGIT:
                        case TCHAR:
                        case VCHAR:
                        case COLON:
                            _string.append(t.getChar());
                            break;

                        default:
                            throw new IllegalCharacterException(_state, t, buffer);
                    }
                    break;

                case REASON:
                    switch (t.getType()) {
                        case LF:
                            String reason = takeString();
                            setState(State.HEADER);
                            handle = _responseHandler.startResponse(_version, _responseStatus, reason) || handle;
                            continue;

                        case ALPHA:
                        case DIGIT:
                        case TCHAR:
                        case VCHAR:
                        case COLON:
                        case OTEXT: // TODO should this be UTF8
                            _string.append(t.getChar());
                            _length = _string.length();
                            break;

                        case SPACE:
                        case HTAB:
                            _string.append(t.getChar());
                            break;

                        default:
                            throw new IllegalCharacterException(_state, t, buffer);
                    }
                    break;

                default:
                    throw new IllegalStateException(_state.toString());
            }
        }

        return handle;
    }
118305
function parse (metadata) {
  var rtn = {};
  if (Buffer.isBuffer(metadata)) {
    metadata = metadata.toString('utf8');
  }
  var pieces = metadata.replace(/\0*$/, '').split(';');

  for (var i = 0; i < pieces.length; i++) {
    var piece = pieces[i].trim();
    if (piece.length > 0) {
      var delimiter = /\=(['"])/.exec(piece);
      var name = piece.substring(0, delimiter.index);
      var value = piece.substring(delimiter.index + 2, piece.length - 1);
      rtn[name] = value;
    }
  }
  return rtn;
}
1903
function unparse(buf, offset) {
  var i = offset || 0;
  return buf[i++].toString(16) + buf[i++].toString(16) +
         buf[i++].toString(16) + buf[i++].toString(16) + '-' +
         buf[i++].toString(16) + buf[i++].toString(16) + '-' +
         buf[i++].toString(16) + buf[i++].toString(16) + '-' +
         buf[i++].toString(16) + buf[i++].toString(16) + '-' +
         buf[i++].toString(16) + buf[i++].toString(16) +
         buf[i++].toString(16) + buf[i++].toString(16) +
         buf[i++].toString(16) + buf[i++].toString(16);
}
999657
function parse(string) {

    var buffer = newBufferFromSize(16);
    var j = 0;
    for (var i = 0; i < 16; i++) {
        buffer[i] = hex2byte[string[j++] + string[j++]];
        if (i === 3 || i === 5 || i === 7 || i === 9) {
            j += 1;
        }
    }

    return buffer;
}
679651
function set (buffer, offset, value) {
  debug('Array "type" setter for buffer at offset', buffer, offset, value)
  var array = this.get(buffer, offset)
  var isInstance = value instanceof this
  if (isInstance || isArray(value)) {
    for (var i = 0; i < value.length; i++) {
      array[i] = value[i]
    }
  } else {
    throw new Error('not sure how to set into Array: ' + value)
  }
}
1339115
function unparse(buf, offset) {
  var i = offset || 0;
  return '03020100-0504-0706-0809-101112131415'.replace(/\d{2}/g, function (num) {
    var j = parseInt(num, 10);
    return _byteToHex[buf[i+j]];
  })
}
546438
function convert (buffer, from, to) {
	//ensure formats are full
	if (!isNormalized(from)) from = normalize(from)
	if (!isNormalized(to)) to = normalize(to)

	//convert buffer/alike to arrayBuffer
	var data
	if (buffer instanceof ArrayBuffer) {
		data = buffer
	}
	else if (ArrayBuffer.isView(buffer)) {
		if (buffer.byteOffset != null) data = buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength);
		else data = buffer.buffer;
	}
	else {
		data = (new Uint8Array(buffer.length != null ? buffer : [buffer])).buffer
	}

	//ignore needless conversion
	if (equal(from ,to)) {
		return data
	}

	//create containers for conversion
	var fromArray = new (arrayClass(from))(data)

	//toArray is automatically filled with mapped values
	//but in some cases mapped badly, e. g. float → int(round + rotate)
	var toArray = new (arrayClass(to))(fromArray)

	//if range differ, we should apply more thoughtful mapping
	if (from.max !== to.max) {
		fromArray.forEach(function (value, idx) {
			//ignore not changed range
			//bring to 0..1
			var normalValue = (value - from.min) / (from.max - from.min)

			//bring to new format ranges
			value = normalValue * (to.max - to.min) + to.min

			//clamp (buffers does not like values outside of bounds)
			toArray[idx] = Math.max(to.min, Math.min(to.max, value))
		})
	}

	//reinterleave, if required
	if (from.interleaved != to.interleaved) {
		var channels = from.channels
		var len = Math.floor(fromArray.length / channels)

		//deinterleave
		if (from.interleaved && !to.interleaved) {
			toArray = toArray.map(function (value, idx, data) {
				var targetOffset = idx % len
				var targetChannel = ~~(idx / len)

				return data[targetOffset * channels + targetChannel]
			})
		}
		//interleave
		else if (!from.interleaved && to.interleaved) {
			toArray = toArray.map(function (value, idx, data) {
				var targetOffset = ~~(idx / channels)
				var targetChannel = idx % channels

				return data[targetChannel * len + targetOffset]
			})
		}
	}

	//ensure endianness
	if (!to.float && from.byteOrder !== to.byteOrder) {
		var le = to.byteOrder === 'LE'
		var view = new DataView(toArray.buffer)
		var step = to.bitDepth / 8
		var methodName = 'set' + getDataViewSuffix(to)
		for (var i = 0, l = toArray.length; i < l; i++) {
			view[methodName](i*step, toArray[i], le)
		}
	}

	return toArray.buffer
}
319734
function parseFrame(&$buffer)
    {
        //$this->log("PaserFrame. BufferLen=".strlen($buffer));
        //websocket
        $ws  = array();
        $ws['finish'] = false;

        $data_offset = 0;

        //fin:1 rsv1:1 rsv2:1 rsv3:1 opcode:4
        $handle        = ord($buffer[$data_offset]);
        $ws['fin']    = ($handle >> 7) & 0x1;
        $ws['rsv1']   = ($handle >> 6) & 0x1;
        $ws['rsv2']   = ($handle >> 5) & 0x1;
        $ws['rsv3']   = ($handle >> 4) & 0x1;
        $ws['opcode'] =  $handle       & 0xf;
        $data_offset ++;

        //mask:1 length:7
        $handle        = ord($buffer[$data_offset]);
        $ws['mask']    = ($handle >> 7) & 0x1;
        //0-125
        $ws['length']  =  $handle       & 0x7f;
        $length        =  &$ws['length'];
        $data_offset ++;

        //126 short
        if($length == 0x7e)
        {
            //2
            $handle = unpack('nl', substr($buffer, $data_offset, 2));
            $data_offset += 2;
            $length = $handle['l'];
        }
        //127 int64
        elseif($length > 0x7e)
        {
            //8
            $handle = unpack('N*l', substr($buffer, $data_offset, 8));
            $data_offset += 8;
            $length = $handle['l'];

            //超过最大允许的长度了
            if ($length > $this->max_frame_size)
            {
                $this->log('Message is too long.');
                return false;
            }
        }

        //mask-key: int32
        if (0x0 !== $ws['mask'])
        {
            $ws['mask'] = array_map('ord', str_split(substr($buffer, $data_offset, 4)));
            $data_offset += 4;
        }

        //把头去掉
        $buffer = substr($buffer, $data_offset);

        //数据长度为0的帧
        if (0 === $length)
        {
            $ws['finish'] = true;
            $ws['message'] = '';
            return $ws;
        }

        //完整的一个数据帧
        if (strlen($buffer) >= $length)
        {
            $ws['finish'] = true;
            $ws['data'] =  substr($buffer, 0, $length);
            $ws['message'] = $this->parseMessage($ws);
            //截取数据
            $buffer = substr($buffer, $length);
            return $ws;
        }
        //需要继续等待数据
        else
        {
            $ws['finish'] = false;
            $ws['data'] = $buffer;
            $buffer = "";
            return $ws;
        }
    }
579638
function parseBulkString (parser) {
  const length = parseLength(parser)
  if (length === undefined) {
    return
  }
  if (length < 0) {
    return null
  }
  const offset = parser.offset + length
  if (offset + 2 > parser.buffer.length) {
    parser.bigStrSize = offset + 2
    parser.totalChunkSize = parser.buffer.length
    parser.bufferCache.push(parser.buffer)
    return
  }
  const start = parser.offset
  parser.offset = offset + 2
  if (parser.optionReturnBuffers === true) {
    return parser.buffer.slice(start, offset)
  }
  return parser.buffer.toString('utf8', start, offset)
}
1168968
def parser_from_buffer(cls, fp):
        """"""
        yaml = YAML(typ="safe")
        return cls(yaml.load(fp))
684149
def parse_buffer(stream, separator=None):
    
    rows = []
    lines = []
    for line, row in parse_lines(stream, separator):
        lines.append(line)
        rows.append(row)
    cols = zip(*rows)
    return {
        'rows': rows,
        'lines': lines,
        'cols': cols,
        }
1091079
function readToken(data, offset) {
        var token = '', ch = data[offset];
        while (ch !== 13 && ch !== 10) {
          if (++offset >= data.length) {
            break;
          }
          token += String.fromCharCode(ch);
          ch = data[offset];
        }
        return token;
      }
947137
function _reverseBuffer(buffer) {
        var tmp, len = buffer.length - 1, half = Math.floor(buffer.length / 2);
        for (var i = len; i >= half; i--) {
            tmp = buffer[i];
            buffer[i] = buffer[len - i];
            buffer[len - i] = tmp;
        }
    }
1136384
function parse(expression, _mem) {
  if (_.isNil(expression)) { // null or undefined
    expression = {};
  } else if (
    _.isNumber(expression) ||
    _.isString(expression) ||
    _.isDate(expression) ||
    _.isBoolean(expression) ||
    Buffer.isBuffer(expression)) {
    expression = { $id: { $eq: expression } };
  } else if (_.isArray(expression)) {
    expression = { $or: expression };
  } else if (!_.isPlainObject(expression)) {
    throw new TypeError('Invalid selection argument; ' +
      `expected number, string, date, boolean, buffer, array or plain object, received ${type(expression)}`);
  }

  // extract object keys
  const keys = _.keys(expression);

  // check if expression is empty
  if (keys.length === 0) {
    return ['SELECTION', null];
  }

  // check if expression has more than 1 keys
  if (keys.length > 1) {
    // split in key-value pairs, e.g. {a: 1, b: 2} => [{a: 1}, {b: 2}]
    const arr = keys.map((k) => {
      return { [k]: expression[k] };
    });

    return parse({ $and: arr });
  }

  // check if expression has exactly 1 key
  if (keys.length === 1) {
    const k = keys[0];
    const v = expression[k];

    switch (k) {
      case '$eq':
        return ['SELECTION', parseEqual(_mem, v)];
      case '$ne':
        return ['SELECTION', parseNotEqual(_mem, v)];
      case '$gt':
        return ['SELECTION', parseGreaterThan(_mem, v)];
      case '$gte':
        return ['SELECTION', parseGreaterThanOrEqual(_mem, v)];
      case '$lt':
        return ['SELECTION', parseLessThan(_mem, v)];
      case '$lte':
        return ['SELECTION', parseLessThanOrEqual(_mem, v)];
      case '$like':
        return ['SELECTION', parseLike(_mem, v)];
      case '$nlike':
        return ['SELECTION', parseNotLike(_mem, v)];
      case '$in':
        return ['SELECTION', parseIn(_mem, v)];
      case '$nin':
        return ['SELECTION', parseNotIn(_mem, v)];
      case '$and':
        return ['SELECTION', parseAnd(v)];
      case '$or':
        return ['SELECTION', parseOr(v)];
      default:
        // check if value is a nested object
        if (_.isPlainObject(v)) {
          return parse(v, k);
        }

        // handle simple key-value assignment
        return parse({ [k]: { $eq: v } });
    }
  }

  throw new TypeError('Invalid selection argument; object must have at least 1 property');
}
300735
public function parse($buffer)
    {
        // strip BOM (byte order marker)
        if (substr($buffer, 0, 3) === "\xef\xbb\xbf") {
            $buffer = substr($buffer, 3);
        }

        $this->buffer          = rtrim($buffer, "\x00..\x1f");
        $this->count           = 0;
        $this->env             = null;
        $this->inParens        = false;
        $this->eatWhiteDefault = true;

        $this->saveEncoding();
        $this->extractLineNumbers($buffer);

        $this->pushBlock(null); // root block
        $this->whitespace();
        $this->pushBlock(null);
        $this->popBlock();

        while ($this->parseChunk()) {
            ;
        }

        if ($this->count !== strlen($this->buffer)) {
            $this->throwParseError();
        }

        if (! empty($this->env->parent)) {
            $this->throwParseError('unclosed block');
        }

        if ($this->charset) {
            array_unshift($this->env->children, $this->charset);
        }

        $this->env->isRoot    = true;

        $this->restoreEncoding();

        return $this->env;
    }
851631
public final T readBuffer(byte[] buffer) {
        if (buffer == null) {
            throw new InvalidArgument("buffer", buffer);
        } else if (buffer.length != recordSize) {
            final String fmt = "invalid buffer (%d bytes, expected %d)";
            final String msg = format(fmt, buffer.length, recordSize);
            throw new InvalidArgument(msg);
        }
        return read(buffer);
    }