// Decode decodes the leading bytes in src as a single instruction.
// The mode arguments specifies the assumed processor mode:
// 16, 32, or 64 for 16-, 32-, and 64-bit execution modes.
8326
func Decode(src []byte, mode int) (inst Inst, err error) {
	return decode1(src, mode, false)
}
626309
func (c *CodecMsgpack) Decode(buf []byte, obj interface{}) error {
	err := codec.NewDecoderBytes(buf, c.h).Decode(obj)
	if err != nil {
		return errors.Wrap(err, "failed to decode")
	}
	return nil
}
824841
func (enc *Encoding) decode(dst, src []byte) (n int, end bool, err error) {
	si := 0

	// skip over newlines
	for si < len(src) && (src[si] == '\n' || src[si] == '\r') {
		si++
	}

	for si < len(src) && !end {
		// Decode quantum using the base64 alphabet
		var dbuf [4]byte
		dinc, dlen := 3, 4

		for j := range dbuf {
			if len(src) == si {
				if enc.padChar != NoPadding || j < 2 {
					return n, false, CorruptInputError(si - j)
				}
				dinc, dlen, end = j-1, j, true
				break
			}
			in := src[si]

			si++
			// skip over newlines
			for si < len(src) && (src[si] == '\n' || src[si] == '\r') {
				si++
			}

			if rune(in) == enc.padChar {
				// We've reached the end and there's padding
				switch j {
				case 0, 1:
					// incorrect padding
					return n, false, CorruptInputError(si - 1)
				case 2:
					// "==" is expected, the first "=" is already consumed.
					if si == len(src) {
						// not enough padding
						return n, false, CorruptInputError(len(src))
					}
					if rune(src[si]) != enc.padChar {
						// incorrect padding
						return n, false, CorruptInputError(si - 1)
					}

					si++
					// skip over newlines
					for si < len(src) && (src[si] == '\n' || src[si] == '\r') {
						si++
					}
				}
				if si < len(src) {
					// trailing garbage
					err = CorruptInputError(si)
				}
				dinc, dlen, end = 3, j, true
				break
			}
			dbuf[j] = enc.decodeMap[in]
			if dbuf[j] == 0xFF {
				return n, false, CorruptInputError(si - 1)
			}
		}

		// Convert 4x 6bit source bytes into 3 bytes
		val := uint(dbuf[0])<<18 | uint(dbuf[1])<<12 | uint(dbuf[2])<<6 | uint(dbuf[3])
		switch dlen {
		case 4:
			dst[2] = byte(val >> 0)
			fallthrough
		case 3:
			dst[1] = byte(val >> 8)
			fallthrough
		case 2:
			dst[0] = byte(val >> 16)
		}
		dst = dst[dinc:]
		n += dlen - 1
	}

	return n, end, err
}
868334
func (decoder *redisDecoder) Decode(in *goetty.ByteBuf) (bool, interface{}, error) {
	complete, cmd, err := ReadCommand(in)
	if err != nil {
		return true, nil, err
	}

	if !complete {
		return false, nil, nil
	}

	return true, cmd, nil
}
17159
func (dec *Decoder) decode() error {
	// check if has UnmarshalText method or a custom function to decode it
	if dec.opts.PrefUnmarshalText {
		if ok, err := dec.isUnmarshalText(dec.curr); ok || err != nil {
			return err
		}
		if ok, err := dec.isCustomType(); ok || err != nil {
			return err
		}
	} else {
		if ok, err := dec.isCustomType(); ok || err != nil {
			return err
		}
		if ok, err := dec.isUnmarshalText(dec.curr); ok || err != nil {
			return err
		}
	}

	switch dec.curr.Kind() {
	case reflect.Array:
		if dec.bracket == "" {
			// not has index, so to decode all values in the slice
			if err := dec.setValues(); err != nil {
				return err
			}
		} else {
			// has index, so to decode value by index indicated
			index, err := strconv.Atoi(dec.bracket)
			if err != nil {
				return newError("array index is not a numberf for field %q in path %q: %v", dec.field, dec.path, err)
			}
			dec.curr = dec.curr.Index(index)
			return dec.decode()
		}
	case reflect.Slice:
		if dec.bracket == "" {
			// not has index, so to decode all values in the slice
			// only for slices
			dec.expandSlice(len(dec.values))
			if err := dec.setValues(); err != nil {
				return err
			}
		} else {
			// has index, so to decode value by index indicated
			index, err := strconv.Atoi(dec.bracket)
			if err != nil {
				return newError("slice index is not a number for field %q in path %q: %v", dec.field, dec.path, err)
			}
			// only for slices
			if dec.curr.Len() <= index {
				dec.expandSlice(index + 1)
			}
			dec.curr = dec.curr.Index(index)
			return dec.decode()
		}
	case reflect.String:
		dec.curr.SetString(dec.values[0])
	case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
		if num, err := strconv.ParseInt(dec.values[0], 10, 64); err != nil {
			return newError("could not parse number for field %q in path %q: %v", dec.field, dec.path, err)
		} else {
			dec.curr.SetInt(num)
		}
	case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
		if num, err := strconv.ParseUint(dec.values[0], 10, 64); err != nil {
			return newError("could not parse number for field %q in path %q: %v", dec.field, dec.path, err)
		} else {
			dec.curr.SetUint(num)
		}
	case reflect.Float32, reflect.Float64:
		if num, err := strconv.ParseFloat(dec.values[0], dec.curr.Type().Bits()); err != nil {
			return newError("could not parse float for field %q in path %q: %v", dec.field, dec.path, err)
		} else {
			dec.curr.SetFloat(num)
		}
	case reflect.Bool:
		switch dec.values[0] {
		case "true", "on", "1", "checked":
			dec.curr.SetBool(true)
		default:
			dec.curr.SetBool(false)
			return nil
		}
	case reflect.Interface:
		dec.curr.Set(reflect.ValueOf(dec.values[0]))
	case reflect.Ptr:
		n := reflect.New(dec.curr.Type().Elem())
		if dec.curr.CanSet() {
			dec.curr.Set(n)
		} else {
			dec.curr.Elem().Set(n.Elem())
		}
		dec.curr = dec.curr.Elem()
		return dec.decode()
	case reflect.Struct:
		switch dec.curr.Interface().(type) {
		case time.Time:
			var t time.Time
			// if the value is empty then no to try to parse it and leave "t" as a zero value to set it in the field
			if dec.values[0] != "" {
				var err error
				t, err = time.Parse("2006-01-02", dec.values[0])
				if err != nil {
					return newError("could not parse field %q in path %q: %v", dec.field, dec.path, err)
				}
			}
			dec.curr.Set(reflect.ValueOf(t))
		case url.URL:
			u, err := url.Parse(dec.values[0])
			if err != nil {
				return newError("could not parse field %q in path %q: %v", dec.field, dec.path, err)
			}
			dec.curr.Set(reflect.ValueOf(*u))
		default:
			if dec.opts.IgnoreUnknownKeys {
				return nil
			}
			num := dec.curr.NumField()
			for i := 0; i < num; i++ {
				field := dec.curr.Type().Field(i)
				tag := field.Tag.Get(dec.opts.TagName)
				if tag == "-" {
					// skip this field
					return nil
				}
			}
			return newError("unsupported type for field %q in path %q. Maybe you should to include it the UnmarshalText interface or register it using custom type?", dec.field, dec.path)
		}
	default:
		if dec.opts.IgnoreUnknownKeys {
			return nil
		}

		return newError("unsupported type for field %q in path %q", dec.field, dec.path)
	}

	return nil
}
336970
func (d *Decoder) Decode(v interface{}) (int, error) {
	if v == nil {
		msg := "can't unmarshal to nil interface"
		return 0, unmarshalError("Unmarshal", ErrNilInterface, msg, nil,
			nil)
	}

	vv := reflect.ValueOf(v)
	if vv.Kind() != reflect.Ptr {
		msg := fmt.Sprintf("can't unmarshal to non-pointer '%v' - use "+
			"& operator", vv.Type().String())
		err := unmarshalError("Unmarshal", ErrBadArguments, msg, nil, nil)
		return 0, err
	}
	if vv.IsNil() && !vv.CanSet() {
		msg := fmt.Sprintf("can't unmarshal to unsettable '%v' - use "+
			"& operator", vv.Type().String())
		err := unmarshalError("Unmarshal", ErrNotSettable, msg, nil, nil)
		return 0, err
	}

	return d.decode(vv)
}
173231
func (e MsgPakEncoderDecoder) Decode(buf []byte, out interface{}) error {
	reader := bytes.NewReader(buf)
	handle := codec.MsgpackHandle{}
	decoder := codec.NewDecoder(reader, &handle)
	return decoder.Decode(out)
}
888704
func (s *Shutdown) Decode(r io.Reader, pver uint32) error {
	return ReadElements(r, &s.ChannelID, &s.Address)
}
261297
func Decode(upper, lower byte) Type {
	return Type(binary.BigEndian.Uint16([]byte{upper, lower}))
}
1225626
func (enc Encoding) Decode(dst, src []byte) (int, error) {
	data := ensurePadding(string(src))
	if enc.convert {
		data = convertEncoding(data)
	}
	return enc.encoding.Decode(dst, []byte(data))
}
298907
func (decoder *RawDecoder) Decode(in *ByteBuf) (bool, interface{}, error) {
	_, data, err := in.ReadMarkedBytes()

	if err != nil {
		return true, data, err
	}

	return true, data, nil
}
681304
func Decode(d []byte, v interface{}) error {
	zr, err := zlib.NewReader(bytes.NewReader(d))
	if err != nil {
		return errors.Annotate(err, "failed to create zlib Reader").Err()
	}
	defer zr.Close()

	if err := json.NewDecoder(zr).Decode(v); err != nil {
		return errors.Annotate(err, "failed to JSON-decode").Err()
	}
	return nil
}
1289919
func decode(dst, src []byte) int {
	var d, s, offset, length int
	for s < len(src) {
		switch src[s] & 0x03 {
		case tagLiteral:
			x := uint32(src[s] >> 2)
			switch {
			case x < 60:
				s++
			case x == 60:
				s += 2
				if uint(s) > uint(len(src)) { // The uint conversions catch overflow from the previous line.
					return decodeErrCodeCorrupt
				}
				x = uint32(src[s-1])
			case x == 61:
				s += 3
				if uint(s) > uint(len(src)) { // The uint conversions catch overflow from the previous line.
					return decodeErrCodeCorrupt
				}
				x = uint32(src[s-2]) | uint32(src[s-1])<<8
			case x == 62:
				s += 4
				if uint(s) > uint(len(src)) { // The uint conversions catch overflow from the previous line.
					return decodeErrCodeCorrupt
				}
				x = uint32(src[s-3]) | uint32(src[s-2])<<8 | uint32(src[s-1])<<16
			case x == 63:
				s += 5
				if uint(s) > uint(len(src)) { // The uint conversions catch overflow from the previous line.
					return decodeErrCodeCorrupt
				}
				x = uint32(src[s-4]) | uint32(src[s-3])<<8 | uint32(src[s-2])<<16 | uint32(src[s-1])<<24
			}
			length = int(x) + 1
			if length <= 0 {
				return decodeErrCodeUnsupportedLiteralLength
			}
			if length > len(dst)-d || length > len(src)-s {
				return decodeErrCodeCorrupt
			}
			copy(dst[d:], src[s:s+length])
			d += length
			s += length
			continue

		case tagCopy1:
			s += 2
			if uint(s) > uint(len(src)) { // The uint conversions catch overflow from the previous line.
				return decodeErrCodeCorrupt
			}
			length = 4 + int(src[s-2])>>2&0x7
			offset = int(uint32(src[s-2])&0xe0<<3 | uint32(src[s-1]))

		case tagCopy2:
			s += 3
			if uint(s) > uint(len(src)) { // The uint conversions catch overflow from the previous line.
				return decodeErrCodeCorrupt
			}
			length = 1 + int(src[s-3])>>2
			offset = int(uint32(src[s-2]) | uint32(src[s-1])<<8)

		case tagCopy4:
			s += 5
			if uint(s) > uint(len(src)) { // The uint conversions catch overflow from the previous line.
				return decodeErrCodeCorrupt
			}
			length = 1 + int(src[s-5])>>2
			offset = int(uint32(src[s-4]) | uint32(src[s-3])<<8 | uint32(src[s-2])<<16 | uint32(src[s-1])<<24)
		}

		if offset <= 0 || d < offset || length > len(dst)-d {
			return decodeErrCodeCorrupt
		}
		// Copy from an earlier sub-slice of dst to a later sub-slice. Unlike
		// the built-in copy function, this byte-by-byte copy always runs
		// forwards, even if the slices overlap. Conceptually, this is:
		//
		// d += forwardCopy(dst[d:d+length], dst[d-offset:])
		for end := d + length; d != end; d++ {
			dst[d] = dst[d-offset]
		}
	}
	if d != len(dst) {
		return decodeErrCodeCorrupt
	}
	return 0
}
1270234
func decode(data *C.pn_data_t, bytes []byte) (int, error) {
	n := C.pn_data_decode(data, cPtr(bytes), cLen(bytes))
	if n == C.PN_UNDERFLOW {
		C.pn_error_clear(C.pn_data_error(data))
		return 0, EndOfData
	} else if n <= 0 {
		return 0, &UnmarshalError{s: fmt.Sprintf("unmarshal %v", PnErrorCode(n))}
	}
	return int(n), nil
}
220667
func (dp *Disconnect) Decode(src []byte) (int, error) {
	return nakedDecode(src, DISCONNECT)
}
1110065
func (pr *PagingResult) Decode(v interface{}) (err error) {
	res := Result{
		"data": pr.Data(),
	}
	return res.Decode(v)
}
882596
func Decode(dst, src []byte) ([]byte, error) {

	if len(src) < 4 {
		return nil, ErrCorrupt
	}

	uncompressedLen := binary.LittleEndian.Uint32(src)

	if uncompressedLen == 0 {
		return nil, nil
	}

	if uncompressedLen > MaxInputSize {
		return nil, ErrTooLarge
	}

	if dst == nil || len(dst) < int(uncompressedLen) {
		dst = make([]byte, uncompressedLen)
	}

	d := decoder{src: src, dst: dst[:uncompressedLen], spos: 4}

	decr := []uint32{0, 3, 2, 3}

	for {
		code, err := d.readByte()
		if err != nil {
			return d.dst, d.finish(err)
		}

		length := uint32(code >> mlBits)
		if length == runMask {
			ln, err := d.getLen()
			if err != nil {
				return nil, ErrCorrupt
			}
			length += ln
		}

		if int(d.spos+length) > len(d.src) || int(d.dpos+length) > len(d.dst) {
			return nil, ErrCorrupt
		}

		for ii := uint32(0); ii < length; ii++ {
			d.dst[d.dpos+ii] = d.src[d.spos+ii]
		}

		d.spos += length
		d.dpos += length

		if int(d.spos) == len(d.src) {
			return d.dst, nil
		}

		if int(d.spos+2) >= len(d.src) {
			return nil, ErrCorrupt
		}

		back := uint32(d.src[d.spos]) | uint32(d.src[d.spos+1])<<8

		if back > d.dpos {
			return nil, ErrCorrupt
		}

		d.spos += 2
		d.ref = d.dpos - back

		length = uint32(code & mlMask)
		if length == mlMask {
			ln, err := d.getLen()
			if err != nil {
				return nil, ErrCorrupt
			}
			length += ln
		}

		literal := d.dpos - d.ref

		if literal < 4 {
			if int(d.dpos+4) > len(d.dst) {
				return nil, ErrCorrupt
			}

			d.cp(4, decr[literal])
		} else {
			length += 4
		}

		if d.dpos+length > uncompressedLen {
			return nil, ErrCorrupt
		}

		d.cp(length, 0)
	}
}