// Encode writes the Index to the stream of the encoder.
438753
func (e *Encoder) Encode(idx *Index) error {
	// TODO: support versions v3 and v4
	// TODO: support extensions
	if idx.Version != EncodeVersionSupported {
		return ErrUnsupportedVersion
	}

	if err := e.encodeHeader(idx); err != nil {
		return err
	}

	if err := e.encodeEntries(idx); err != nil {
		return err
	}

	return e.encodeFooter()
}
843107
func Encode(dst, src []byte) ([]byte, error) {

	if len(src) >= MaxInputSize {
		return nil, ErrTooLarge
	}

	if n := CompressBound(len(src)); len(dst) < n {
		dst = make([]byte, n)
	}

	e := encoder{src: src, dst: dst, hashTable: make([]uint32, hashTableSize)}

	binary.LittleEndian.PutUint32(dst, uint32(len(src)))
	e.dpos = 4

	var (
		step  uint32 = 1
		limit        = incompressible
	)

	for {
		if int(e.pos)+12 >= len(e.src) {
			e.writeLiterals(uint32(len(e.src))-e.anchor, 0, e.anchor)
			return e.dst[:e.dpos], nil
		}

		sequence := uint32(e.src[e.pos+3])<<24 | uint32(e.src[e.pos+2])<<16 | uint32(e.src[e.pos+1])<<8 | uint32(e.src[e.pos+0])

		hash := (sequence * 2654435761) >> hashShift
		ref := e.hashTable[hash] + uninitHash
		e.hashTable[hash] = e.pos - uninitHash

		if ((e.pos-ref)>>16) != 0 || uint32(e.src[ref+3])<<24|uint32(e.src[ref+2])<<16|uint32(e.src[ref+1])<<8|uint32(e.src[ref+0]) != sequence {
			if e.pos-e.anchor > limit {
				limit <<= 1
				step += 1 + (step >> 2)
			}
			e.pos += step
			continue
		}

		if step > 1 {
			e.hashTable[hash] = ref - uninitHash
			e.pos -= step - 1
			step = 1
			continue
		}
		limit = incompressible

		ln := e.pos - e.anchor
		back := e.pos - ref

		anchor := e.anchor

		e.pos += minMatch
		ref += minMatch
		e.anchor = e.pos

		for int(e.pos) < len(e.src)-5 && e.src[e.pos] == e.src[ref] {
			e.pos++
			ref++
		}

		mlLen := e.pos - e.anchor

		e.writeLiterals(ln, mlLen, anchor)
		e.dst[e.dpos] = uint8(back)
		e.dst[e.dpos+1] = uint8(back >> 8)
		e.dpos += 2

		if mlLen > mlMask-1 {
			mlLen -= mlMask
			for mlLen > 254 {
				mlLen -= 255

				e.dst[e.dpos] = 255
				e.dpos++
			}

			e.dst[e.dpos] = byte(mlLen)
			e.dpos++
		}

		e.anchor = e.pos
	}
}
1030255
func (e *Error) Encode(w io.Writer, prver uint32) error {
	return WriteElements(w,
		e.Code,
		e.Data,
	)
}
730372
func Encode(in []byte) string {
	out := Client().Encode(in)
	Trace("Encode", nil, logrus.Fields{"in": in, "out": out})
	return out
}
539982
func (e *HeaderEncoder) Encode(s string) string {
	if !needsEncoding(s) {
		return s
	}

	return e.encodeWord(s)
}
456630
func (f *FailUnknownPaymentHash) Encode(w io.Writer, pver uint32) error {
	return WriteElement(w, f.amount)
}
495507
func (codec *StringCodec) Encode(data interface{}, out *ByteBuf) error {
	if msg, ok := data.(string); ok {
		return out.WriteString(msg)
	}

	return fmt.Errorf("not string: %+v", data)
}
726761
func (e *Encoder) Encode(v interface{}) error {
	b, err := e.marshal(v)
	if err != nil {
		return err
	}
	if _, err := e.w.Write(b); err != nil {
		return err
	}
	return nil
}
425650
func (v BytesValue) encode(w io.Writer) error {
	raw := rawValue{
		Type: v.valueType(),
	}

	return raw.encodeBytes(w, []byte(v))
}
979592
func (c Cap) Encode(w io.Writer) error {
	e := &encoder{w: w}
	c.encode(e)
	return e.err
}
657476
func (enc *Encoder) Encode(v interface{}) error {
	if enc.err != nil {
		return enc.err
	}
	e := newEncodeState(enc.canonical)
	err := e.marshal(v)
	if err != nil {
		return err
	}

	if !enc.canonical {
		// Terminate each value with a newline.
		// This makes the output look a little nicer
		// when debugging, and some kind of space
		// is required if the encoded value was a number,
		// so that the reader knows there aren't more
		// digits coming.
		e.WriteByte('\n')
	}

	if _, err = enc.w.Write(e.Bytes()); err != nil {
		enc.err = err
	}
	encodeStatePool.Put(e)
	return err
}
1111503
func (oc *OutputChange) Encode() (*OutputChangeSrc, error) {
	cs, err := oc.Change.Encode(cty.DynamicPseudoType)
	if err != nil {
		return nil, err
	}
	return &OutputChangeSrc{
		Addr:      oc.Addr,
		ChangeSrc: *cs,
		Sensitive: oc.Sensitive,
	}, err
}
962452
func (e *encoder) Encode(obj runtime.Object) error {
	if err := e.encoder.Encode(obj, e.buf); err != nil {
		return err
	}
	_, err := e.writer.Write(e.buf.Bytes())
	e.buf.Reset()
	return err
}
128023
func (u *UploadRequest) Encode(w io.Writer) error {
	e := newUlReqEncoder(w)
	return e.Encode(u)
}
836090
func (b *Commit) Encode(o plumbing.EncodedObject) error {
	return b.encode(o, true)
}
1223940
func (enc *Encoder) Encode(w io.Writer, nim image.Image, params imageserver.Params) error {
	e := &png.Encoder{CompressionLevel: enc.CompressionLevel}
	return e.Encode(w, nim)
}
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)
}