// WithMsg returns a copy of err with given new messages.
//  err := gear.Err.WithMsg() // just clone
//  err := gear.ErrBadRequest.WithMsg("invalid email") // 400 Bad Request error with message invalid email"
15928
func (err Error) WithMsg(msgs ...string) *Error {
	if len(msgs) > 0 {
		err.Msg = strings.Join(msgs, ", ")
	}
	return &err
}
227365
func (err Error) WithMsgf(format string, args ...interface{}) *Error {
	return err.WithMsg(fmt.Sprintf(format, args...))
}
539946
func (z uint16Slice) MarshalMsg(b []byte) (o []byte, err error) {
	o = msgp.Require(b, z.Msgsize())
	o = msgp.AppendArrayHeader(o, uint32(len(z)))
	for zzpf := range z {
		o = msgp.AppendUint16(o, z[zzpf])
	}
	return
}
1132318
func (z *roaringArray) MarshalMsg(b []byte) (o []byte, err error) {
	o = msgp.Require(b, z.Msgsize())
	// map header, size 4
	// string "keys"
	o = append(o, 0x84, 0xa4, 0x6b, 0x65, 0x79, 0x73)
	o = msgp.AppendArrayHeader(o, uint32(len(z.keys)))
	for zhct := range z.keys {
		o = msgp.AppendUint16(o, z.keys[zhct])
	}
	// string "needCopyOnWrite"
	o = append(o, 0xaf, 0x6e, 0x65, 0x65, 0x64, 0x43, 0x6f, 0x70, 0x79, 0x4f, 0x6e, 0x57, 0x72, 0x69, 0x74, 0x65)
	o = msgp.AppendArrayHeader(o, uint32(len(z.needCopyOnWrite)))
	for zcua := range z.needCopyOnWrite {
		o = msgp.AppendBool(o, z.needCopyOnWrite[zcua])
	}
	// string "copyOnWrite"
	o = append(o, 0xab, 0x63, 0x6f, 0x70, 0x79, 0x4f, 0x6e, 0x57, 0x72, 0x69, 0x74, 0x65)
	o = msgp.AppendBool(o, z.copyOnWrite)
	// string "conserz"
	o = append(o, 0xa7, 0x63, 0x6f, 0x6e, 0x73, 0x65, 0x72, 0x7a)
	o = msgp.AppendArrayHeader(o, uint32(len(z.conserz)))
	for zxhx := range z.conserz {
		// map header, size 2
		// string "t"
		o = append(o, 0x82, 0xa1, 0x74)
		o = msgp.AppendUint8(o, uint8(z.conserz[zxhx].t))
		// string "r"
		o = append(o, 0xa1, 0x72)
		o, err = z.conserz[zxhx].r.MarshalMsg(o)
		if err != nil {
			return
		}
	}
	return
}
588745
func (z *containerSerz) MarshalMsg(b []byte) (o []byte, err error) {
	o = msgp.Require(b, z.Msgsize())
	// map header, size 2
	// string "t"
	o = append(o, 0x82, 0xa1, 0x74)
	o = msgp.AppendUint8(o, uint8(z.t))
	// string "r"
	o = append(o, 0xa1, 0x72)
	o, err = z.r.MarshalMsg(o)
	if err != nil {
		return
	}
	return
}
509472
func (s *ScrubWriter) WriteMsg(m *dns.Msg) error {
	state := Request{Req: s.req, W: s.ResponseWriter}

	n := state.Scrub(m)
	state.SizeAndDo(n)
	return s.ResponseWriter.WriteMsg(n)
}
366776
func (z MetricsDeleteResp) MarshalMsg(b []byte) (o []byte, err error) {
	o = msgp.Require(b, z.Msgsize())
	// map header, size 1
	// string "DeletedDefs"
	o = append(o, 0x81, 0xab, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x64, 0x44, 0x65, 0x66, 0x73)
	o = msgp.AppendInt(o, z.DeletedDefs)
	return
}
803963
func (z interval16) MarshalMsg(b []byte) (o []byte, err error) {
	o = msgp.Require(b, z.Msgsize())
	// map header, size 2
	// string "start"
	o = append(o, 0x82, 0xa5, 0x73, 0x74, 0x61, 0x72, 0x74)
	o = msgp.AppendUint16(o, z.start)
	// string "last"
	o = append(o, 0xa4, 0x6c, 0x61, 0x73, 0x74)
	o = msgp.AppendUint16(o, z.last())
	return
}
1189551
func (s *Sender) SendWithRetries(msg *Message, to string, retries int) (result *Result, err error) {
	if err := checkUnrecoverableErrors(s, to, nil, msg, retries); err != nil {
		return nil, err
	}
	attempt, backoff := 0, BackoffInitialDelay
	for {
		attempt++
		result, err = s.SendNoRetry(msg, to)
		// NOTE: partial success for a device group message is considered successful

		tryAgain := false
		if attempt <= retries {
			if result != nil && (result.Error == ErrorUnavailable || result.Error == ErrorInternalServerError) {
				tryAgain = true
			} else if err != nil {
				if httpErr, isHTTPErr := err.(httpError); isHTTPErr {
					tryAgain = httpErr.statusCode >= http.StatusInternalServerError && httpErr.statusCode < 600
				}
			}
		}

		if tryAgain {
			sleepTime := backoff/2 + rand.Intn(backoff)
			time.Sleep(time.Duration(sleepTime) * time.Millisecond)
			backoff = min(2*backoff, MaxBackoffDelay)
		} else {
			break
		}
	}
	return
}
1053249
func (n *Notification) EncodeMsg(w *msgp.Writer) error {
	var bm msgp.Encodable

	if n.Body != nil {
		var ok bool
		bm, ok = n.Body.(msgp.Encodable)
		if !ok {
			return ErrNotEncodable
		}
	}

	var err error

	if err = w.WriteArrayHeader(NotificationPackSize); err != nil {
		return err
	}

	if err = w.WriteInt(NotificationType); err != nil {
		return err
	}

	if err = w.WriteString(n.Method); err != nil {
		return err
	}

	// No body to encode. Write a zero-length params array.
	if bm == nil {
		return w.WriteArrayHeader(0)
	}

	// 1-item array containing the body.
	if err = w.WriteArrayHeader(1); err != nil {
		return err
	}

	return msgp.Encode(w, bm)
}
694891
func someParametersBrokenMsg(path, method, operationID string) errors.Error {
	return errors.New(errors.CompositeErrorCode, SomeParametersBrokenError, path, method, operationID)
}
692219
func (z Entry) MarshalMsg(b []byte) (o []byte, err error) {
	o = msgp.Require(b, z.Msgsize())
	// array header, size 2
	o = append(o, 0x92)
	o = msgp.AppendInt64(o, z.Time)
	o, err = msgp.AppendIntf(o, z.Record)
	if err != nil {
		err = msgp.WrapError(err, "Record")
		return
	}
	return
}
1281835
func (is *Is) Msg(format string, args ...interface{}) *Is {
	return &Is{
		TB:         is.TB,
		strict:     is.strict,
		failFormat: format,
		failArgs:   args,
	}
}
551077
func (c *Client) sendMsg(msgType message.Type, route string, data []byte) (uint, error) {
	// TODO mount msg and encode
	m := message.Message{
		Type:  msgType,
		ID:    uint(atomic.AddUint32(&c.nextID, 1)),
		Route: route,
		Data:  data,
		Err:   false,
	}
	p, err := c.buildPacket(m)
	if msgType == message.Request {
		c.pendingChan <- true
		c.pendingReqMutex.Lock()
		if _, ok := c.pendingRequests[m.ID]; !ok {
			c.pendingRequests[m.ID] = &pendingRequest{
				msg:    &m,
				sentAt: time.Now(),
			}
		}
		c.pendingReqMutex.Unlock()
	}

	if err != nil {
		return m.ID, err
	}
	_, err = c.conn.Write(p)
	return m.ID, err
}
410002
func (c *Conn) fixMsg(m *Message, ml int) {
	if m.Header.Length == 0 {
		m.Header.Length = uint32(nlmsgAlign(ml))
	}

	if m.Header.Sequence == 0 {
		m.Header.Sequence = c.nextSequence()
	}

	if m.Header.PID == 0 {
		m.Header.PID = c.pid
	}
}
334517
func (z NestInner) EncodeMsg(en *msgp.Writer) (err error) {
	// map header, size 1
	// write "hello"
	err = en.Append(0x81, 0xa5, 0x68, 0x65, 0x6c, 0x6c, 0x6f)
	if err != nil {
		return
	}
	err = en.WriteString(z.Hello)
	if err != nil {
		return
	}
	return
}
810086
func (z *IterGen) EncodeMsg(en *msgp.Writer) (err error) {
	// map header, size 3
	// write "T0"
	err = en.Append(0x83, 0xa2, 0x54, 0x30)
	if err != nil {
		return
	}
	err = en.WriteUint32(z.T0)
	if err != nil {
		err = msgp.WrapError(err, "T0")
		return
	}
	// write "IntervalHint"
	err = en.Append(0xac, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x76, 0x61, 0x6c, 0x48, 0x69, 0x6e, 0x74)
	if err != nil {
		return
	}
	err = en.WriteUint32(z.IntervalHint)
	if err != nil {
		err = msgp.WrapError(err, "IntervalHint")
		return
	}
	// write "B"
	err = en.Append(0xa1, 0x42)
	if err != nil {
		return
	}
	err = en.WriteBytes(z.B)
	if err != nil {
		err = msgp.WrapError(err, "B")
		return
	}
	return
}