//  Encodes the response before sending it back down to the client.
//  We don't change anything here, just let the underlying codec handle it.
770367
func (a *AuthServerCodec) WriteResponse(r *rpc.Response, body interface{}) error {
	// We do need a lock here, because the ServerCodec interface specifies
	//  that WriteResponse must be safe for concurrent use by multiple goroutines
	a.wBuffMutex.Lock()
	defer a.wBuffMutex.Unlock()

	a.buff.WriteBuff.Reset()

	// Let the underlying codec write the response to the buffer
	if err := a.wrappedcodec.WriteResponse(r, body); err != nil {
		return err
	}

	// Get the response from the buffer and write it to the actual connection
	response := a.buff.WriteBuff.Bytes()
	if err := auth.WriteLengthAndBytes(response, a.conn); err != nil {
		return err
	}

	return nil
}
1162224
func encodeReply(call Call, reply Reply, wr io.Writer, indent bool) error {
	// copy jsonrpc fields from call to reply
	reply.Jsonrpc = call.Jsonrpc
	reply.ID = call.ID

	enc := json.NewEncoder(wr)
	if indent {
		enc.SetIndent("", "    ")
	}
	return enc.Encode(reply)
}
347510
func (mr *MockEncoderMockRecorder) Encode(message interface{}) *gomock.Call {
	return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Encode", reflect.TypeOf((*MockEncoder)(nil).Encode), message)
}
1199211
func EncodeBody(res *sawyer.Response, bodyWriter io.Writer) error {
	if res.ContentLength == 0 {
		return nil
	}

	buf := &bytes.Buffer{}
	writer := io.MultiWriter(bodyWriter, buf)
	_, err := io.Copy(writer, res.Body)
	if err == nil {
		res.Body = ioutil.NopCloser(buf)
	}

	return err
}
764093
func (s ISO88595) Encode() []byte {
	e := charmap.ISO8859_5.NewEncoder()
	es, _, err := transform.Bytes(e, s)
	if err != nil {
		return s
	}
	return es
}
1117934
func (res *Response) Encode(w io.Writer) error {
	var buf [16]byte
	binary.BigEndian.PutUint64(buf[0:8], uint64(res.Physical))
	binary.BigEndian.PutUint64(buf[8:16], uint64(res.Logical))
	_, err := w.Write(buf[0:16])
	return errors.Trace(err)
}
847616
func Encode(res *sawyer.Response, writer io.Writer) error {
	resCopy := CachedResponse{
		Expires:          expiration(res.Response),
		Status:           res.Status,
		StatusCode:       res.StatusCode,
		Proto:            res.Proto,
		ProtoMajor:       res.ProtoMajor,
		ProtoMinor:       res.ProtoMinor,
		Header:           res.Header,
		ContentLength:    res.ContentLength,
		TransferEncoding: res.TransferEncoding,
		Trailer:          res.Trailer,
	}

	if res.MediaType != nil {
		resCopy.MediaType = *res.MediaType
	}

	return EncodeResponse(&resCopy, writer)
}
731021
func (res *Response) Encoding() (encoding.Encoding, error) {
	enc, _ := charset.Lookup(res.Charset)
	if enc == nil {
		return nil, fmt.Errorf("no encoding found for %s", res.Charset)
	}
	return enc, nil
}
210378
func encodeErr(call Call, err error, wr io.Writer, indent bool) error {
	reply := Reply{Error: &CallError{Message: err.Error()}}
	return encodeReply(call, reply, wr, indent)
}
1339496
func (m *MockPacketEncoder) Encode(typ packet.Type, data []byte) ([]byte, error) {
	ret := m.ctrl.Call(m, "Encode", typ, data)
	ret0, _ := ret[0].([]byte)
	ret1, _ := ret[1].(error)
	return ret0, ret1
}
140704
func (m *MockEncoder) Encode(message *message.Message) ([]byte, error) {
	ret := m.ctrl.Call(m, "Encode", message)
	ret0, _ := ret[0].([]byte)
	ret1, _ := ret[1].(error)
	return ret0, ret1
}
782489
func (b TCP) Encode(t *TCPFields) {
	b.encodeSubset(t.SeqNum, t.AckNum, t.Flags, t.WindowSize)
	binary.BigEndian.PutUint16(b[TCPSrcPortOffset:], t.SrcPort)
	binary.BigEndian.PutUint16(b[TCPDstPortOffset:], t.DstPort)
	b[TCPDataOffset] = (t.DataOffset / 4) << 4
	binary.BigEndian.PutUint16(b[TCPChecksumOffset:], t.Checksum)
	binary.BigEndian.PutUint16(b[TCPUrgentPtrOffset:], t.UrgentPointer)
}
1120852
func (r EnvelopeV0Responder) EncodeResponse(v wire.Value, t wire.EnvelopeType, w io.Writer) error {
	writer := binary.BorrowWriter(w)
	err := writer.WriteLegacyEnveloped(wire.Envelope{
		Name:  r.Name,
		Type:  t,
		SeqID: r.SeqID,
		Value: v,
	})
	binary.ReturnWriter(writer)
	return err
}
908520
func (sp *Subscribe) Encode(dst []byte) (int, error) {
	total := 0

	// check packet id
	if !sp.ID.Valid() {
		return total, makeError(sp.Type(), "packet id must be grater than zero")
	}

	// encode header
	n, err := headerEncode(dst[total:], 0, sp.len(), sp.Len(), SUBSCRIBE)
	total += n
	if err != nil {
		return total, err
	}

	// write packet id
	binary.BigEndian.PutUint16(dst[total:], uint16(sp.ID))
	total += 2

	for _, t := range sp.Subscriptions {
		// write topic
		n, err := writeLPString(dst[total:], t.Topic, sp.Type())
		total += n
		if err != nil {
			return total, err
		}

		// check qos
		if !t.QOS.Successful() {
			return total, makeError(sp.Type(), "invalid QOS level (%d)", t.QOS)
		}

		// write qos
		dst[total] = byte(t.QOS)

		total++
	}

	return total, nil
}
940795
func (c *ReplyChannelRange) Encode(w io.Writer, pver uint32) error {
	if err := c.QueryChannelRange.Encode(w, pver); err != nil {
		return err
	}

	if err := WriteElements(w, c.Complete); err != nil {
		return err
	}

	return encodeShortChanIDs(w, c.EncodingType, c.ShortChanIDs)
}
928499
func (enc *Encoder) Encode(m *Message) (err error) {

	_, err = enc.Write(m.Bytes())

	return
}
1309163
func (mock *Mock) Encode(data []*FileDataEntry) ([]byte, error) {
	items := mock.getReturnValues("Decode")
	if len(items) == 1 {
		switch typed := items[0].(type) {
		case []byte:
			return typed, nil
		case error:
			return []byte{}, typed
		}
	} else if len(items) == 2 {
		return items[0].([]byte), items[1].(error)
	}
	return []byte{}, nil
}