// magicRequestDecoder performs a request on an endpoint, and decodes the response into the passed in Type
516797
func (c *Client) magicRequestDecoder(method, path string, body io.Reader, v interface{}) error {
	req, err := c.NewRequest(method, path, body)
	if err != nil {
		return err
	}

	debug("Request: %+v \n", req)
	res, err := c.Do(req, v)
	if res != nil {
		defer res.Body.Close()
	}
	debug("Response: %+v \n", res)
	if err != nil {
		return err
	}
	return err
}
965522
func decodeAppendEntriesRequest(
	b []byte,
	args *raft.AppendEntriesRequest,
) bool {
	if len(b) < 40 {
		return false
	}
	args.Term = binary.LittleEndian.Uint64(b[0:8])
	args.PrevLogEntry = binary.LittleEndian.Uint64(b[8:16])
	args.PrevLogTerm = binary.LittleEndian.Uint64(b[16:24])
	args.LeaderCommitIndex = binary.LittleEndian.Uint64(b[24:32])
	args.Leader = make([]byte, int(binary.LittleEndian.Uint64(b[32:40])))
	b = b[40:]
	if len(b) < len(args.Leader) {
		return false
	}
	copy(args.Leader, b[:len(args.Leader)])
	b = b[len(args.Leader):]
	if len(b) < 8 {
		return false
	}
	args.Entries = make([]*raft.Log, int(binary.LittleEndian.Uint64(b)))
	b = b[8:]
	for i := 0; i < len(args.Entries); i++ {
		if len(b) < 25 {
			return false
		}
		args.Entries[i] = &raft.Log{}
		args.Entries[i].Index = binary.LittleEndian.Uint64(b[0:8])
		args.Entries[i].Term = binary.LittleEndian.Uint64(b[8:16])
		args.Entries[i].Type = raft.LogType(b[16])
		args.Entries[i].Data = make([]byte,
			int(binary.LittleEndian.Uint64(b[17:25])))
		b = b[25:]
		if len(b) < len(args.Entries[i].Data) {
			return false
		}
		copy(args.Entries[i].Data, b[:len(args.Entries[i].Data)])
		b = b[len(args.Entries[i].Data):]
	}
	return len(b) == 0
}
387707
func (ctx *Context) DecodeGQL() (*GQLRequest, error) {
	r := &GQLRequest{}

	if string(ctx.Method()) == GET {
		query := ctx.GETParam("query")
		if len(query) == 0 {
			return nil, ErrInvalidGQLRequest
		}
		r.Query = query[0]

		if operationName := ctx.GETParam("operationName"); len(operationName) != 0 {
			r.OperationName = operationName[0]
		}

		if variables := ctx.GETParam("variables"); len(variables) != 0 {
			if _, err := ctx.UnJSONBytes([]byte(variables[0]), &r.Variables); err != nil {
				return nil, ErrInvalidGQLRequest
			}
		}

		return r, nil
	}

	ctSplitParams := strings.Split(ctx.ContentType(), delimiterCTParams)

	switch ctSplitParams[0] {
	case jsonCTshort:
		if err := ctx.UnJSON(&r); err != nil {
			return nil, err
		}
	case gqlCT:
		r.Query = string(ctx.PostBody())
	}

	return r, nil
}
1037288
func NewDecoder(r io.Reader) *Decoder {
	return &Decoder{r, defaultDelimiter, defaultEscape, false, false}
}
366668
func unmarshalerDecoder(d *decodeState, v reflect.Value, opts decOpts) int {
	um, ok := v.Interface().(Unmarshaler)
	if !ok {
		panic(fmt.Errorf("Non-Unmarshaler passed to unmarshalerEncoder"))
	}

	read, err := um.UnmarshalTLS(d.Bytes())
	if err != nil {
		panic(err)
	}

	if read > d.Len() {
		panic(fmt.Errorf("Invalid return value from UnmarshalTLS"))
	}

	d.Next(read)
	return read
}
1209669
func (c *Charmap) NewDecoder() *encoding.Decoder {
	c.Init()
	return &encoding.Decoder{Transformer: &cmapDecoder{runes: c.runes}}
}
533975
func (c *Context) DecodeJSON(v interface{}) error {
	defer c.Request().Body.Close()
	return json.NewDecoder(c.Request().Body).Decode(v)
}
443192
func (c *Client) DecodeErrorResponse(resp *http.Response) (*goa.ErrorResponse, error) {
	var decoded goa.ErrorResponse
	err := c.Decoder.Decode(&decoded, resp.Body, resp.Header.Get("Content-Type"))
	return &decoded, err
}
916402
func DecodeHTTPRedirectRequest(requestURLHeader string) httptransport.DecodeRequestFunc {
	return func(_ context.Context, r *http.Request) (interface{}, error) {
		hostname := ""
		requestURL := r.Header.Get(requestURLHeader)
		if u, err := url.ParseRequestURI(requestURL); err == nil {
			hostname = u.Host
		}
		return redirectRequest{
			RequestURL: requestURL,
			Hostname:   hostname,
		}, nil
	}
}
765904
func GenHelperDecoder(d *Decoder) (gd genHelperDecoder, dd genHelperDecDriver) {
	gd = genHelperDecoder{d: d}
	dd = genHelperDecDriver{decDriver: d.d}
	return
}
325947
func NewDecoder(opts ...func(*Decoder)) *Decoder {
	d := &Decoder{
		MarshalOptions: MarshalOptions{
			SupportJSONTags: true,
		},
	}
	for _, o := range opts {
		o(d)
	}

	return d
}
640736
func decodeGRPCConcatRequest(_ context.Context, grpcReq interface{}) (interface{}, error) {
	req := grpcReq.(*pb.ConcatRequest)
	return addendpoint.ConcatRequest{A: req.A, B: req.B}, nil
}
1367906
func NewDecoder(enc *Encoding, r io.Reader) io.Reader {
	return &decoder{enc: enc, r: r}
}
123341
func DecodeHTTPCreateSessionRequest(_ context.Context, r *http.Request) (interface{}, error) {
	session := &sessions.Session{}
	if err := json.NewDecoder(r.Body).Decode(session); err != nil {
		return nil, kitty.WithErrBodyDecoding(errors.Wrap(err, "could not decode the session"))
	}
	return createSessionRequest{
		Session: session,
	}, nil
}
918797
func NewDecoder(rd io.Reader) Decoder {
	dec := gob.NewDecoder(rd)
	return func(r *Result) error { return dec.Decode(r) }
}
420397
func EntityDecoder() Decoder {
	var leftover rune // leftover rune from two-rune entity
	return func(p []byte) (r rune, size int, status Status) {
		if leftover != 0 {
			r = leftover
			leftover = 0
			return r, 0, SUCCESS
		}

		if len(p) == 0 {
			return 0, 0, NO_ROOM
		}

		if p[0] != '&' {
			return 0xfffd, 1, INVALID_CHAR
		}

		if len(p) < 3 {
			return 0, 1, NO_ROOM
		}

		r, size, status = 0xfffd, 1, INVALID_CHAR
		n := 1 // number of bytes read so far

		if p[n] == '#' {
			n++
			c := p[n]
			hex := false
			if c == 'x' || c == 'X' {
				hex = true
				n++
			}

			var x rune
			for n < len(p) {
				c = p[n]
				n++
				if hex {
					if '0' <= c && c <= '9' {
						x = 16*x + rune(c) - '0'
						continue
					} else if 'a' <= c && c <= 'f' {
						x = 16*x + rune(c) - 'a' + 10
						continue
					} else if 'A' <= c && c <= 'F' {
						x = 16*x + rune(c) - 'A' + 10
						continue
					}
				} else if '0' <= c && c <= '9' {
					x = 10*x + rune(c) - '0'
					continue
				}
				if c != ';' {
					n--
				}
				break
			}

			if n == len(p) && p[n-1] != ';' {
				return 0, 0, NO_ROOM
			}

			size = n
			if p[n-1] == ';' {
				n--
			}
			if hex {
				n--
			}
			n--
			// Now n is the number of actual digits read.
			if n == 0 {
				return 0xfffd, 1, INVALID_CHAR
			}

			if 0x80 <= x && x <= 0x9F {
				// Replace characters from Windows-1252 with UTF-8 equivalents.
				x = replacementTable[x-0x80]
			} else if x == 0 || (0xD800 <= x && x <= 0xDFFF) || x > 0x10FFFF {
				// Replace invalid characters with the replacement character.
				return 0xfffd, size, INVALID_CHAR
			}

			r = x
			status = SUCCESS
			return
		}

		// Look for a named entity in EntityList.

		possible := entityList
		for len(possible) > 0 {
			if len(p) <= n {
				leftover = 0
				return 0, 0, NO_ROOM
			}

			c := p[n]

			// Narrow down the selection in possible to those items that have c in the
			// appropriate byte.
			first := sort.Search(len(possible), func(i int) bool {
				e := possible[i].name
				if len(e) < n {
					return false
				}
				return e[n-1] >= c
			})
			possible = possible[first:]
			last := sort.Search(len(possible), func(i int) bool {
				return possible[i].name[n-1] > c
			})
			possible = possible[:last]

			n++
			if len(possible) > 0 && len(possible[0].name) == n-1 {
				r, leftover = possible[0].r1, possible[0].r2
				size = n
				status = SUCCESS
				// but don't return yet, since we need the longest match
			}
		}

		return
	}
}
859354
func Decode(context *qor.Context, result interface{}, res Resourcer) error {
	var errors qor.Errors
	var err error
	var metaValues *MetaValues
	metaors := res.GetMetas([]string{})

	if strings.Contains(context.Request.Header.Get("Content-Type"), "json") {
		metaValues, err = ConvertJSONToMetaValues(context.Request.Body, metaors)
		context.Request.Body.Close()
	} else {
		metaValues, err = ConvertFormToMetaValues(context.Request, metaors, "QorResource.")
	}

	errors.AddError(err)
	errors.AddError(DecodeToResource(res, result, metaValues, context).Start())
	return errors
}