// DecodeRawBytes reads a count-delimited byte buffer from the Buffer.
// This is the format used for the bytes protocol buffer
// type and for embedded messages.
8967
func (p *Buffer) DecodeRawBytes(alloc bool) (buf []byte, err error) {
	n, err := p.DecodeVarint()
	if err != nil {
		return nil, err
	}

	nb := int(n)
	if nb < 0 {
		return nil, fmt.Errorf("proto: bad byte length %d", nb)
	}
	end := p.index + nb
	if end < p.index || end > len(p.buf) {
		return nil, io.ErrUnexpectedEOF
	}

	if !alloc {
		// todo: check if can get more uses of alloc=false
		buf = p.buf[p.index:end]
		p.index += nb
		return
	}

	buf = make([]byte, nb)
	copy(buf, p.buf[p.index:])
	p.index += nb
	return
}
1263888
func (parser *Parser) ParseBytes(contents []byte) error {
	if !parser.initialised {
		if err := parser.init(); err != nil {
			return err
		}
	}

	return parser.rt.run(string(contents))
}
781219
func (c *Client) DecodeRawTransaction(serializedTx []byte) (*btcjson.TxRawResult, error) {
	return c.DecodeRawTransactionAsync(serializedTx).Receive()
}
1056434
func (b *Buffer) ReadBytes(p []byte) {
	copy(p, b.Consume(len(p)))
}
225559
func (jd *JSONDecoder) Decode(byteSet []byte) ([]*FileDataEntry, error) {
	if len(byteSet) == 0 {
		return []*FileDataEntry{}, nil
	}
	// Decode to type-specific structure
	jsonFile := jsonFile{}
	err := json.Unmarshal(byteSet, &jsonFile)
	if err != nil {
		return nil, fmt.Errorf("failed to decode json file: %v", err)
	}
	// Convert to common file data entry list structure
	var dataEntries []*FileDataEntry
	for _, dataEntry := range jsonFile.Data {
		dataEntries = append(dataEntries, &FileDataEntry{Key: dataEntry.Key, Value: dataEntry.Value})
	}
	return dataEntries, nil
}
787919
func DecodeBytes(b []byte, val interface{}) error {
	r := bytes.NewReader(b)

	stream := streamPool.Get().(*Stream)
	defer streamPool.Put(stream)

	stream.Reset(r, uint64(len(b)))
	if err := stream.Decode(val); err != nil {
		return err
	}
	if r.Len() > 0 {
		return ErrMoreThanOneValue
	}
	return nil
}
872988
func (pool *ByteSlicePool) decodeBytes(b PacketReader) []byte {
	fieldLength := decodeUint16(b)
	field := pool.getByteSlice(int(fieldLength))
	b.Read(field)
	return field
}
153853
func (p *Buffer) DecodeStringBytes() (s string, err error) {
	buf, err := p.DecodeRawBytes(false)
	if err != nil {
		return
	}
	return string(buf), nil
}
511124
func (pl *Payload) DecodeBinary(dec *gob.Decoder) error {
	return dec.Decode(pl)
}
913146
func decode(reply []byte, dest interface{}) error {
	// Check the type of dest and make sure it is a pointer to something,
	// otherwise we can't set its value in any meaningful way.
	val := reflect.ValueOf(dest)
	if val.Kind() != reflect.Ptr {
		return fmt.Errorf("Argument to decode must be pointer. Got %T", dest)
	}

	// Use the gob package to decode the reply and write the result into
	// dest.
	buf := bytes.NewBuffer(reply)
	dec := gob.NewDecoder(buf)
	if err := dec.DecodeValue(val.Elem()); err != nil {
		return err
	}
	return nil
}
691013
func ReadBytes(data []byte, opts ...Option) (Node, error) {
	return Read(bytes.NewBuffer(data), opts...)
}
1272739
func (e *Error) GobDecode(data []byte) error {
	buf := bytes.NewBuffer(data)
	dec := gob.NewDecoder(buf)
	var msg messageType
	err := dec.Decode(&msg)
	if err != nil {
		return err
	}
	switch msg {
	case ErrorLocal:
		var er *Error
		err := dec.Decode(&er)
		if err != nil {
			return err
		}
		e.err = er
	case ErrorGo:
		var er GoError
		err := dec.Decode(&er)
		if err != nil {
			return err
		}
		e.err = er
	default:
		return errors.New("protocol error")
	}
	err = dec.Decode(&e.args)
	if err != nil {
		return err
	}
	err = dec.Decode(&e.pkg)
	if err != nil {
		return err
	}
	err = dec.Decode(&e.file)
	if err != nil {
		return err
	}
	err = dec.Decode(&e.line)
	if err != nil {
		return err
	}
	err = dec.Decode(&e.debugInfo)
	if err != nil {
		return err
	}
	err = dec.Decode(&msg)
	if err != nil {
		return err
	}
	switch msg {
	case NextIsNill:
		return nil
	case Next:
		err = dec.Decode(&e.next)
		if err != nil {
			return err
		}
	default:
		return errors.New("protocol error")
	}
	return nil
}
1328415
func decodeNetworkByteOrder(orderBytes []byte) (n uint32) {
	return uint32(orderBytes[0])<<24 |
		uint32(orderBytes[1])<<16 |
		uint32(orderBytes[2])<<8 |
		uint32(orderBytes[3])
}
516038
func (d *Decoder) ResetBytes(in []byte) {
	if in == nil {
		return
	}
	d.bytes = true
	d.bufio = false
	// d.typ = entryTypeBytes
	d.rb.reset(in)
	// d.r = &d.rb
	d.resetCommon()
}
472149
func Decode(data []byte) (result interface{}, err error) {
	result, _, err = decodeItem(data, 0)
	return
}
760313
func decodeCompoundMessage(buf []byte) (trunc int, parts [][]byte, err error) {
	if len(buf) < 1 {
		err = fmt.Errorf("missing compound length byte")
		return
	}
	numParts := uint8(buf[0])
	buf = buf[1:]

	// Check we have enough bytes
	if len(buf) < int(numParts*2) {
		err = fmt.Errorf("truncated len slice")
		return
	}

	// Decode the lengths
	lengths := make([]uint16, numParts)
	for i := 0; i < int(numParts); i++ {
		lengths[i] = binary.BigEndian.Uint16(buf[i*2 : i*2+2])
	}
	buf = buf[numParts*2:]

	// Split each message
	for idx, msgLen := range lengths {
		if len(buf) < int(msgLen) {
			trunc = int(numParts) - idx
			return
		}

		// Extract the slice, seek past on the buffer
		slice := buf[:msgLen]
		buf = buf[msgLen:]
		parts = append(parts, slice)
	}
	return
}
153102
func (r *Encoder) EncodeBytes(b []byte) error {
	if len(b) < STR_FIXED_COUNT {
		_, err := r.w.Write([]byte{byte(STR_FIXED_START + len(b))})
		if err != nil {
			return err
		}
		_, err = r.w.Write(b)
		return err
	}

	prefix := []byte(fmt.Sprintf("%d:", len(b)))

	_, err := r.w.Write(prefix)
	if err != nil {
		return err
	}

	_, err = r.w.Write(b)
	return err
}