// WriteMsg implements the dns.ResponseWriter interface.
964491
func (w *ResponseWriter) WriteMsg(res *dns.Msg) error {
	do := false
	mt, opt := response.Typify(res, time.Now().UTC())
	if opt != nil {
		do = opt.Do()
	}

	// key returns empty string for anything we don't want to cache.
	key := key(res, mt, do)

	duration := w.pttl
	if mt == response.NameError || mt == response.NoData {
		duration = w.nttl
	}

	msgTTL := minMsgTTL(res, mt)
	if msgTTL < duration {
		duration = msgTTL
	}

	if key != -1 && duration > 0 {
		w.set(res, key, mt, duration)

		cacheSize.WithLabelValues(Success).Set(float64(w.pcache.Len()))
		cacheSize.WithLabelValues(Denial).Set(float64(w.ncache.Len()))
	}

	if w.prefetch {
		return nil
	}

	// Apply capped TTL to this reply to avoid jarring TTL experience 1799 -> 8 (e.g.)
	ttl := uint32(duration.Seconds())
	for i := range res.Answer {
		res.Answer[i].Header().Ttl = ttl
	}
	for i := range res.Ns {
		res.Ns[i].Header().Ttl = ttl
	}
	for i := range res.Extra {
		if res.Extra[i].Header().Rrtype != dns.TypeOPT {
			res.Extra[i].Header().Ttl = ttl
		}
	}
	return w.ResponseWriter.WriteMsg(res)
}
354372
func (r *Request) EncodeMsg(w *msgp.Writer) error {
	var bm msgp.Encodable

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

	var err error

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

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

	if err = w.WriteString(r.ID); err != nil {
		return err
	}

	if err = w.WriteString(r.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)
}
809937
func (z *IndexFindByTagResp) EncodeMsg(en *msgp.Writer) (err error) {
	// map header, size 1
	// write "Metrics"
	err = en.Append(0x81, 0xa7, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73)
	if err != nil {
		return
	}
	err = en.WriteArrayHeader(uint32(len(z.Metrics)))
	if err != nil {
		err = msgp.WrapError(err, "Metrics")
		return
	}
	for za0001 := range z.Metrics {
		err = z.Metrics[za0001].EncodeMsg(en)
		if err != nil {
			err = msgp.WrapError(err, "Metrics", za0001)
			return
		}
	}
	return
}
851477
func (z *arrayContainer) MarshalMsg(b []byte) (o []byte, err error) {
	o = msgp.Require(b, z.Msgsize())
	// map header, size 1
	// string "content"
	o = append(o, 0x81, 0xa7, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74)
	o = msgp.AppendArrayHeader(o, uint32(len(z.content)))
	for zxvk := range z.content {
		o = msgp.AppendUint16(o, z.content[zxvk])
	}
	return
}
617671
func (z *Series) EncodeMsg(en *msgp.Writer) (err error) {
	// map header, size 9
	// write "Target"
	err = en.Append(0x89, 0xa6, 0x54, 0x61, 0x72, 0x67, 0x65, 0x74)
	if err != nil {
		return
	}
	err = en.WriteString(z.Target)
	if err != nil {
		err = msgp.WrapError(err, "Target")
		return
	}
	// write "Datapoints"
	err = en.Append(0xaa, 0x44, 0x61, 0x74, 0x61, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x73)
	if err != nil {
		return
	}
	err = en.WriteArrayHeader(uint32(len(z.Datapoints)))
	if err != nil {
		err = msgp.WrapError(err, "Datapoints")
		return
	}
	for za0001 := range z.Datapoints {
		err = z.Datapoints[za0001].EncodeMsg(en)
		if err != nil {
			err = msgp.WrapError(err, "Datapoints", za0001)
			return
		}
	}
	// write "Tags"
	err = en.Append(0xa4, 0x54, 0x61, 0x67, 0x73)
	if err != nil {
		return
	}
	err = en.WriteMapHeader(uint32(len(z.Tags)))
	if err != nil {
		err = msgp.WrapError(err, "Tags")
		return
	}
	for za0002, za0003 := range z.Tags {
		err = en.WriteString(za0002)
		if err != nil {
			err = msgp.WrapError(err, "Tags")
			return
		}
		err = en.WriteString(za0003)
		if err != nil {
			err = msgp.WrapError(err, "Tags", za0002)
			return
		}
	}
	// write "Interval"
	err = en.Append(0xa8, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x76, 0x61, 0x6c)
	if err != nil {
		return
	}
	err = en.WriteUint32(z.Interval)
	if err != nil {
		err = msgp.WrapError(err, "Interval")
		return
	}
	// write "QueryPatt"
	err = en.Append(0xa9, 0x51, 0x75, 0x65, 0x72, 0x79, 0x50, 0x61, 0x74, 0x74)
	if err != nil {
		return
	}
	err = en.WriteString(z.QueryPatt)
	if err != nil {
		err = msgp.WrapError(err, "QueryPatt")
		return
	}
	// write "QueryFrom"
	err = en.Append(0xa9, 0x51, 0x75, 0x65, 0x72, 0x79, 0x46, 0x72, 0x6f, 0x6d)
	if err != nil {
		return
	}
	err = en.WriteUint32(z.QueryFrom)
	if err != nil {
		err = msgp.WrapError(err, "QueryFrom")
		return
	}
	// write "QueryTo"
	err = en.Append(0xa7, 0x51, 0x75, 0x65, 0x72, 0x79, 0x54, 0x6f)
	if err != nil {
		return
	}
	err = en.WriteUint32(z.QueryTo)
	if err != nil {
		err = msgp.WrapError(err, "QueryTo")
		return
	}
	// write "QueryCons"
	err = en.Append(0xa9, 0x51, 0x75, 0x65, 0x72, 0x79, 0x43, 0x6f, 0x6e, 0x73)
	if err != nil {
		return
	}
	err = z.QueryCons.EncodeMsg(en)
	if err != nil {
		err = msgp.WrapError(err, "QueryCons")
		return
	}
	// write "Consolidator"
	err = en.Append(0xac, 0x43, 0x6f, 0x6e, 0x73, 0x6f, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72)
	if err != nil {
		return
	}
	err = z.Consolidator.EncodeMsg(en)
	if err != nil {
		err = msgp.WrapError(err, "Consolidator")
		return
	}
	return
}
783017
func (r *gRPCresponse) Write(b []byte) (int, error) {
	r.Msg = new(dns.Msg)
	return len(b), r.Msg.Unpack(b)
}
1204122
func (z MetricsDeleteResp) EncodeMsg(en *msgp.Writer) (err error) {
	// map header, size 1
	// write "DeletedDefs"
	err = en.Append(0x81, 0xab, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x64, 0x44, 0x65, 0x66, 0x73)
	if err != nil {
		return
	}
	err = en.WriteInt(z.DeletedDefs)
	if err != nil {
		err = msgp.WrapError(err, "DeletedDefs")
		return
	}
	return
}
706418
func (*MsgCodec) EncodeMsg(msg api.Message, msgID uint16) (data []byte, err error) {
	if msg == nil {
		return nil, errors.New("nil message passed in")
	}

	// try to recover panic which might possibly occur in struc.Pack call
	defer func() {
		if r := recover(); r != nil {
			var ok bool
			if err, ok = r.(error); !ok {
				err = fmt.Errorf("%v", r)
			}
			err = fmt.Errorf("panic occurred: %v", err)
		}
	}()

	var header interface{}

	// encode message header
	switch msg.GetMessageType() {
	case api.RequestMessage:
		header = &VppRequestHeader{VlMsgID: msgID}
	case api.ReplyMessage:
		header = &VppReplyHeader{VlMsgID: msgID}
	case api.EventMessage:
		header = &VppEventHeader{VlMsgID: msgID}
	default:
		header = &VppOtherHeader{VlMsgID: msgID}
	}

	buf := new(bytes.Buffer)

	// encode message header
	if err := struc.Pack(buf, header); err != nil {
		return nil, fmt.Errorf("failed to encode message header: %+v, error: %v", header, err)
	}

	// encode message content
	if reflect.TypeOf(msg).Elem().NumField() > 0 {
		if err := struc.Pack(buf, msg); err != nil {
			return nil, fmt.Errorf("failed to encode message data: %+v, error: %v", data, err)
		}
	}

	return buf.Bytes(), nil
}
356369
func (wsConn *WSConn) WriteMsg(args ...[]byte) error {
	wsConn.Lock()
	defer wsConn.Unlock()
	if wsConn.closeFlag {
		return nil
	}

	// get len
	var msgLen uint32
	for i := 0; i < len(args); i++ {
		msgLen += uint32(len(args[i]))
	}

	// check len
	if msgLen > wsConn.maxMsgLen {
		return errors.New("message too long")
	} else if msgLen < 1 {
		return errors.New("message too short")
	}

	// don't copy
	if len(args) == 1 {
		wsConn.doWrite(args[0])
		return nil
	}

	// merge the args
	msg := make([]byte, msgLen)
	l := 0
	for i := 0; i < len(args); i++ {
		copy(msg[l:], args[i])
		l += len(args[i])
	}

	wsConn.doWrite(msg)

	return nil
}
28171
func (z *roaringArray) EncodeMsg(en *msgp.Writer) (err error) {
	// map header, size 4
	// write "keys"
	err = en.Append(0x84, 0xa4, 0x6b, 0x65, 0x79, 0x73)
	if err != nil {
		return err
	}
	err = en.WriteArrayHeader(uint32(len(z.keys)))
	if err != nil {
		return
	}
	for zhct := range z.keys {
		err = en.WriteUint16(z.keys[zhct])
		if err != nil {
			return
		}
	}
	// write "needCopyOnWrite"
	err = en.Append(0xaf, 0x6e, 0x65, 0x65, 0x64, 0x43, 0x6f, 0x70, 0x79, 0x4f, 0x6e, 0x57, 0x72, 0x69, 0x74, 0x65)
	if err != nil {
		return err
	}
	err = en.WriteArrayHeader(uint32(len(z.needCopyOnWrite)))
	if err != nil {
		return
	}
	for zcua := range z.needCopyOnWrite {
		err = en.WriteBool(z.needCopyOnWrite[zcua])
		if err != nil {
			return
		}
	}
	// write "copyOnWrite"
	err = en.Append(0xab, 0x63, 0x6f, 0x70, 0x79, 0x4f, 0x6e, 0x57, 0x72, 0x69, 0x74, 0x65)
	if err != nil {
		return err
	}
	err = en.WriteBool(z.copyOnWrite)
	if err != nil {
		return
	}
	// write "conserz"
	err = en.Append(0xa7, 0x63, 0x6f, 0x6e, 0x73, 0x65, 0x72, 0x7a)
	if err != nil {
		return err
	}
	err = en.WriteArrayHeader(uint32(len(z.conserz)))
	if err != nil {
		return
	}
	for zxhx := range z.conserz {
		// map header, size 2
		// write "t"
		err = en.Append(0x82, 0xa1, 0x74)
		if err != nil {
			return err
		}
		err = en.WriteUint8(uint8(z.conserz[zxhx].t))
		if err != nil {
			return
		}
		// write "r"
		err = en.Append(0xa1, 0x72)
		if err != nil {
			return err
		}
		err = z.conserz[zxhx].r.EncodeMsg(en)
		if err != nil {
			return
		}
	}
	return
}
934021
func (w *FileLogWriter) WriteMsg(msg string, level int) error {
	if level > w.Level {
		return nil
	}
	n := 24 + len(msg) // 24 stand for the length "2013/06/23 21:00:22 [T] "
	w.docheck(n)
	w.Logger.Println(msg)
	return nil
}
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)
}
829495
func (z *GraphiteTagDelSeries) MarshalMsg(b []byte) (o []byte, err error) {
	o = msgp.Require(b, z.Msgsize())
	// map header, size 2
	// string "Paths"
	o = append(o, 0x82, 0xa5, 0x50, 0x61, 0x74, 0x68, 0x73)
	o = msgp.AppendArrayHeader(o, uint32(len(z.Paths)))
	for za0001 := range z.Paths {
		o = msgp.AppendString(o, z.Paths[za0001])
	}
	// string "Propagate"
	o = append(o, 0xa9, 0x50, 0x72, 0x6f, 0x70, 0x61, 0x67, 0x61, 0x74, 0x65)
	o = msgp.AppendBool(o, z.Propagate)
	return
}
1262603
func (r *RoundRobinResponseWriter) WriteMsg(res *dns.Msg) error {
	if res.Rcode != dns.RcodeSuccess {
		return r.ResponseWriter.WriteMsg(res)
	}

	res.Answer = roundRobin(res.Answer)
	res.Ns = roundRobin(res.Ns)
	res.Extra = roundRobin(res.Extra)

	return r.ResponseWriter.WriteMsg(res)
}
516051
func (z Entry) EncodeMsg(en *msgp.Writer) (err error) {
	// array header, size 2
	err = en.Append(0x92)
	if err != nil {
		return
	}
	err = en.WriteInt64(z.Time)
	if err != nil {
		err = msgp.WrapError(err, "Time")
		return
	}
	err = en.WriteIntf(z.Record)
	if err != nil {
		err = msgp.WrapError(err, "Record")
		return
	}
	return
}
959339
func (z *runContainer16) MarshalMsg(b []byte) (o []byte, err error) {
	o = msgp.Require(b, z.Msgsize())
	// map header, size 2
	// string "iv"
	o = append(o, 0x82, 0xa2, 0x69, 0x76)
	o = msgp.AppendArrayHeader(o, uint32(len(z.iv)))
	for zxpk := range z.iv {
		// map header, size 2
		// string "start"
		o = append(o, 0x82, 0xa5, 0x73, 0x74, 0x61, 0x72, 0x74)
		o = msgp.AppendUint16(o, z.iv[zxpk].start)
		// string "last"
		o = append(o, 0xa4, 0x6c, 0x61, 0x73, 0x74)
		o = msgp.AppendUint16(o, z.iv[zxpk].last())
	}
	// string "card"
	o = append(o, 0xa4, 0x63, 0x61, 0x72, 0x64)
	o = msgp.AppendInt64(o, z.card)
	return
}
1001118
func (b *Builder) Msg(m *dns.Msg) *Builder {
	if b.err != nil {
		return b
	}

	b.Packed, b.err = m.Pack()
	return b
}