// NewResponses creates an object of type Responses if possible, returning an error if not.
489452
func NewResponses(in interface{}, context *compiler.Context) (*Responses, error) {
	errors := make([]error, 0)
	x := &Responses{}
	m, ok := compiler.UnpackMap(in)
	if !ok {
		message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)
		errors = append(errors, compiler.NewError(context, message))
	} else {
		allowedKeys := []string{"default"}
		allowedPatterns := []*regexp.Regexp{pattern3, pattern1}
		invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
		if len(invalidKeys) > 0 {
			message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
			errors = append(errors, compiler.NewError(context, message))
		}
		// ResponseOrReference default = 1;
		v1 := compiler.MapValueForKey(m, "default")
		if v1 != nil {
			var err error
			x.Default, err = NewResponseOrReference(v1, compiler.NewContext("default", context))
			if err != nil {
				errors = append(errors, err)
			}
		}
		// repeated NamedResponseOrReference response_or_reference = 2;
		// MAP: ResponseOrReference ^([0-9X]{3})$
		x.ResponseOrReference = make([]*NamedResponseOrReference, 0)
		for _, item := range m {
			k, ok := compiler.StringValue(item.Key)
			if ok {
				v := item.Value
				if pattern3.MatchString(k) {
					pair := &NamedResponseOrReference{}
					pair.Name = k
					var err error
					pair.Value, err = NewResponseOrReference(v, compiler.NewContext(k, context))
					if err != nil {
						errors = append(errors, err)
					}
					x.ResponseOrReference = append(x.ResponseOrReference, pair)
				}
			}
		}
		// repeated NamedAny specification_extension = 3;
		// MAP: Any ^x-
		x.SpecificationExtension = make([]*NamedAny, 0)
		for _, item := range m {
			k, ok := compiler.StringValue(item.Key)
			if ok {
				v := item.Value
				if strings.HasPrefix(k, "x-") {
					pair := &NamedAny{}
					pair.Name = k
					result := &Any{}
					handled, resultFromExt, err := compiler.HandleExtension(context, v, k)
					if handled {
						if err != nil {
							errors = append(errors, err)
						} else {
							bytes, _ := yaml.Marshal(v)
							result.Yaml = string(bytes)
							result.Value = resultFromExt
							pair.Value = result
						}
					} else {
						pair.Value, err = NewAny(v, compiler.NewContext(k, context))
						if err != nil {
							errors = append(errors, err)
						}
					}
					x.SpecificationExtension = append(x.SpecificationExtension, pair)
				}
			}
		}
	}
	return x, compiler.NewErrorGroupOrNil(errors)
}
223190
func NewGetResponse(
	key string,
	status ResponseStatus,
	flags uint32,
	value []byte,
	version uint64) GetResponse {

	resp := &genericResponse{
		status:        status,
		allowNotFound: true,
	}
	resp.item.Key = key
	if status == StatusNoError {
		if value == nil {
			resp.item.Value = []byte{}
		} else {
			resp.item.Value = value
		}
		resp.item.Flags = flags
		resp.item.DataVersionId = version
	}
	return resp
}
1082013
func NewResultFromResponse(response *abci.ResponseDeliverTx) ABCIResult {
	return ABCIResult{
		Code: response.Code,
		Data: response.Data,
	}
}
523936
func NewResponse(i http.ResponseWriter, f *Fibre) *Response {
	return &Response{i, f, 0, 0, false}
}
225048
func NewResponseDefinitions(in interface{}, context *compiler.Context) (*ResponseDefinitions, error) {
	errors := make([]error, 0)
	x := &ResponseDefinitions{}
	m, ok := compiler.UnpackMap(in)
	if !ok {
		message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)
		errors = append(errors, compiler.NewError(context, message))
	} else {
		// repeated NamedResponse additional_properties = 1;
		// MAP: Response
		x.AdditionalProperties = make([]*NamedResponse, 0)
		for _, item := range m {
			k, ok := compiler.StringValue(item.Key)
			if ok {
				v := item.Value
				pair := &NamedResponse{}
				pair.Name = k
				var err error
				pair.Value, err = NewResponse(v, compiler.NewContext(k, context))
				if err != nil {
					errors = append(errors, err)
				}
				x.AdditionalProperties = append(x.AdditionalProperties, pair)
			}
		}
	}
	return x, compiler.NewErrorGroupOrNil(errors)
}
1320227
func NewCountResponse(
	key string,
	status ResponseStatus,
	count uint64) CountResponse {

	resp := &genericResponse{
		status: status,
	}
	resp.item.Key = key
	if status == StatusNoError {
		resp.count = count
	}
	return resp
}
1115883
func NewResults(responses []*abci.ResponseDeliverTx) ABCIResults {
	res := make(ABCIResults, len(responses))
	for i, d := range responses {
		res[i] = NewResultFromResponse(d)
	}
	return res
}
478686
func NewResponse(success bool, message string, data interface{}) *Response {
	return &Response{
		Success: success,
		Message: message,
		Data:    data,
	}
}
47546
func createResponse(req *http.Request) *http.Response {
	return &http.Response{
		ProtoMajor: 1,
		ProtoMinor: 1,
		Proto:      "HTTP/1.1",
		Request:    req,
		Header:     make(http.Header),
		Body:       createReadCloser([]byte{}),
	}
}
610528
func (c *Client) newResponse(res *http.Response, maxBodySize int64) (*Response, error) {
	r := &Response{
		StatusCode: res.StatusCode,
		Header:     res.Header,
	}
	if res.Body != nil {
		body := io.Reader(res.Body)
		if maxBodySize > 0 {
			if res.ContentLength > maxBodySize {
				return nil, ErrResponseSize
			}
			body = io.LimitReader(body, maxBodySize+1)
		}
		slurp, err := ioutil.ReadAll(body)
		if err != nil {
			return nil, err
		}
		if maxBodySize > 0 && int64(len(slurp)) > maxBodySize {
			return nil, ErrResponseSize
		}
		// HEAD requests return a body but no content
		if len(slurp) > 0 {
			r.Body = json.RawMessage(slurp)
		}
	}
	return r, nil
}
167827
func NewValidationResponse(validation ValidationModel, warnings ...string) ValidateResponseModel {
	return ValidateResponseModel{
		Data:     &validation,
		Warnings: warnings,
	}
}
1231835
func (fw *Framework) NewReply(request protocol.Request) (reply protocol.Reply, err error) {
	switch request.Version() {
	case protocol.RequestV1:
		reply, err = v1.NewReply(request, fw.Config.Identity)
	default:
		err = fmt.Errorf("Do not know how to create a Reply version %s", request.Version())
	}

	return
}
938345
func (m *Method) inheritResponses(parent map[HTTPCode]Response, dicts map[string]interface{},
	apiDef *APIDefinition) {
	if len(m.Responses) == 0 { // allocate if needed
		m.Responses = map[HTTPCode]Response{}
	}
	for code, rParent := range parent {
		resp, ok := m.Responses[code]
		if !ok {
			if optionalTraitProperty(fmt.Sprintf("%v", code)) { // don't inherit optional property if not exist
				continue
			}
			resp = Response{HTTPCode: code}
		}
		resp.inherit(rParent, dicts, m.resourceTypeName, apiDef)
		m.Responses[code] = resp
	}

}
250252
func NewResponseWriter(rw http.ResponseWriter) ResponseWriter {
	newRw := responseWriter{rw, 0, 0, nil}
	if cn, ok := rw.(http.CloseNotifier); ok {
		return &closeNotifyResponseWriter{newRw, cn}
	}
	return &newRw
}
549462
func (s *Server) NewResponse() *Response {
	r := NewResponse(s.Storage)
	r.ErrorStatusCode = s.Config.ErrorStatusCode
	return r
}
34523
func NewResponse(code int, body interface{}, headers ...map[string]string) *Response {
	response := &Response{
		Code: code,
		Body: body,
	}
	if len(headers) != 0 {
		response.Headers = make(map[string]string)
		for _, eachHeaderMap := range headers {
			for eachKey, eachValue := range eachHeaderMap {
				response.Headers[eachKey] = eachValue
			}
		}
	}
	return response
}
1306629
func (b *Driver) HandleResponses(data []byte, e error) {
	//fmt.Println("response data:", data, e)

	b.handleCollisionDetected(data)
}