// Encode encodes the passed object to the given writer using the pool of
// marshallers.
960973
func (p *PooledMarshaller) Encode(obj interface{}, w io.Writer) error {
	m := p.pool.Get().(*Marshaller)
	err := m.Encode(obj, w)
	p.pool.Put(m)
	return err
}
1224457
func (enc *encoder) Encode(vs ...interface{}) (err error) {
	defer func() {
		err, _ = recover().(error)
	}()
	for _, v := range vs {
		enc.encode(reflect.ValueOf(v), 0)
	}
	return nil
}
704055
func (e *Encoder) Encode(v interface{}) error {
	f, ok := v.(marshalerFaster)
	if ok {
		e.buf.Reset()
		err := f.MarshalJSONBuf(&e.buf)
		if err != nil {
			return err
		}

		_, err = io.Copy(e.w, &e.buf)
		return err
	}

	return e.enc.Encode(v)
}
451408
func (a *AES) Encode(r io.Reader, w io.Writer) error {
	iv := make([]byte, aes.BlockSize)

	block, err := aes.NewCipher(a.Key)
	if err != nil {
		return err
	} else if _, err = rand.Read(iv[:]); err != nil {
		return err
	} else if _, err = w.Write(iv); err != nil {
		return err
	}
	stream := cipher.NewCFBEncrypter(block, iv)
	writer := &cipher.StreamWriter{S: stream, W: w}
	_, err = io.Copy(writer, r)
	return err
}
914882
func (e *encodeBuild) Encode(r io.Writer, b interface{}) (int, error) {
	return e.handler(r, b)
}
867066
func (c *FundingLocked) Encode(w io.Writer, pver uint32) error {
	return WriteElements(w,
		c.ChanID,
		c.NextPerCommitmentPoint)
}
230683
func (resp *RequestVoteResponse) Encode(w io.Writer) (int, error) {
	pb := &protobuf.RequestVoteResponse{
		Term:        proto.Uint64(resp.Term),
		VoteGranted: proto.Bool(resp.VoteGranted),
	}

	p, err := proto.Marshal(pb)
	if err != nil {
		return -1, err
	}

	return w.Write(p)
}
456675
func (c *UpdateFee) Encode(w io.Writer, pver uint32) error {
	return WriteElements(w,
		c.ChanID,
		c.FeePerKw,
	)
}
155118
func (e *Encoder) Encode(idx *MemoryIndex) (int, error) {
	flow := []func(*MemoryIndex) (int, error){
		e.encodeHeader,
		e.encodeFanout,
		e.encodeHashes,
		e.encodeCRC32,
		e.encodeOffsets,
		e.encodeChecksums,
	}

	sz := 0
	for _, f := range flow {
		i, err := f(idx)
		sz += i

		if err != nil {
			return sz, err
		}
	}

	return sz, nil
}
1271714
func (j *JSON) Encode(mfs []*dto.MetricFamily) ([]byte, error) {
	return EncodeJSON(mfs)
}
515452
func (resp *SnapshotResponse) Encode(w io.Writer) (int, error) {
	pb := &protobuf.SnapshotResponse{
		Success: proto.Bool(resp.Success),
	}
	p, err := proto.Marshal(pb)
	if err != nil {
		return -1, err
	}

	return w.Write(p)
}
782057
func Encode(e Encoder, obj Object) ([]byte, error) {
	return e.Encode(obj)
}
214429
func (p *Pong) Encode(w io.Writer, pver uint32) error {
	return WriteElements(w,
		p.PongBytes,
	)
}
118045
func (e *Erasure) Encode(ctx context.Context, src io.Reader, writers []io.Writer, buf []byte, quorum int) (total int64, err error) {
	writer := &parallelWriter{
		writers:     writers,
		writeQuorum: quorum,
		errs:        make([]error, len(writers)),
	}

	for {
		var blocks [][]byte
		n, err := io.ReadFull(src, buf)
		if err != nil && err != io.EOF && err != io.ErrUnexpectedEOF {
			logger.LogIf(ctx, err)
			return 0, err
		}
		eof := err == io.EOF || err == io.ErrUnexpectedEOF
		if n == 0 && total != 0 {
			// Reached EOF, nothing more to be done.
			break
		}
		// We take care of the situation where if n == 0 and total == 0 by creating empty data and parity files.
		blocks, err = e.EncodeData(ctx, buf[:n])
		if err != nil {
			logger.LogIf(ctx, err)
			return 0, err
		}

		if err = writer.Write(ctx, blocks); err != nil {
			logger.LogIf(ctx, err)
			return 0, err
		}
		total += int64(n)
		if eof {
			break
		}
	}
	return total, nil
}
1228899
func (todo *Todo) Encode() (*bytes.Buffer, error) {
	b, err := json.Marshal(todo)
	if err != nil {
		return &bytes.Buffer{}, err
	}
	return bytes.NewBuffer(b), nil
}
1205387
func (w *Stream) Encode(m JSONMessage) error {
	return w.enc.Encode(m)
}
767295
func (v Values) Encode(w io.Writer) error {
	//return yaml.NewEncoder(w).Encode(v)
	out, err := yaml.Marshal(v)
	if err != nil {
		return err
	}
	_, err = w.Write(out)
	return err
}