// encode is our main function for
// base64 encoding a passed []byte
772941
func encode(bin []byte) []byte {
	e64 := base64.StdEncoding

	maxEncLen := e64.EncodedLen(len(bin))
	encBuf := make([]byte, maxEncLen)

	e64.Encode(encBuf, bin)
	return encBuf
}
138771
func Encode(b []byte, v int64) int {
	u := uint64(v)
	switch {
	case u < 0x80:
		b[0] = byte(u)
		return 1
	case u < 0x4000:
		_ = b[1]
		b[0] = byte(u>>8)&0x3f | 0x80
		b[1] = byte(u)
		return 2
	case u < 0x200000:
		_ = b[2]
		b[0] = byte(u>>16)&0x1f | 0xc0
		b[1] = byte(u >> 8)
		b[2] = byte(u)
		return 3
	case u < 0x10000000:
		_ = b[3]
		b[0] = byte(u>>24)&0x0f | 0xe0
		b[1] = byte(u >> 16)
		b[2] = byte(u >> 8)
		b[3] = byte(u)
		return 4
	case u < 0x800000000:
		_ = b[4]
		b[0] = byte(u>>32)&0x07 | 0xf0
		b[1] = byte(u >> 24)
		b[2] = byte(u >> 16)
		b[3] = byte(u >> 8)
		b[4] = byte(u)
		return 5
	case u < 0x40000000000:
		_ = b[5]
		b[0] = byte(u>>40)&0x03 | 0xf8
		b[1] = byte(u >> 32)
		b[2] = byte(u >> 24)
		b[3] = byte(u >> 16)
		b[4] = byte(u >> 8)
		b[5] = byte(u)
		return 6
	case u < 0x2000000000000:
		_ = b[6]
		b[0] = byte(u>>48)&0x01 | 0xfc
		b[1] = byte(u >> 40)
		b[2] = byte(u >> 32)
		b[3] = byte(u >> 24)
		b[4] = byte(u >> 16)
		b[5] = byte(u >> 8)
		b[6] = byte(u)
		return 7
	case u < 0x100000000000000:
		_ = b[7]
		b[0] = 0xfe
		b[1] = byte(u >> 48)
		b[2] = byte(u >> 40)
		b[3] = byte(u >> 32)
		b[4] = byte(u >> 24)
		b[5] = byte(u >> 16)
		b[6] = byte(u >> 8)
		b[7] = byte(u)
		return 8
	default:
		_ = b[8]
		b[0] = 0xff
		b[1] = byte(u >> 56)
		b[2] = byte(u >> 48)
		b[3] = byte(u >> 40)
		b[4] = byte(u >> 32)
		b[5] = byte(u >> 24)
		b[6] = byte(u >> 16)
		b[7] = byte(u >> 8)
		b[8] = byte(u)
		return 9
	}
}
355239
func base64Decode(b []byte) []byte {
	n, _ := base64.StdEncoding.Decode(b, b)
	return b[:n]
}
730372
func Encode(in []byte) string {
	out := Client().Encode(in)
	Trace("Encode", nil, logrus.Fields{"in": in, "out": out})
	return out
}
573738
func (b *Buffer) Base64Decode(v []byte) error {
	enc := base64.RawURLEncoding
	out := make([]byte, enc.DecodedLen(len(v)))
	n, err := enc.Decode(out, v)
	if err != nil {
		return errors.Wrap(err, "failed to decode from base64")
	}
	out = out[:n]
	*b = Buffer(out)
	return nil
}
969453
func (e StringEncoder) Encode(data interface{}, out *goetty.ByteBuf) error {
	msg, _ := data.(string)
	bytes := []byte(msg)
	out.WriteInt(len(bytes))
	out.Write(bytes)
	return nil
}
1046887
func Encode(w io.Writer, v interface{}, order binary.ByteOrder) (int, error) {
	b, err := json.Marshal(v)
	if err != nil {
		return 0, err
	}
	return Write(w, bytes.NewReader(b), order)
}
1107322
func (ns *Namespace) Base64Encode(content interface{}) (string, error) {
	conv, err := cast.ToStringE(content)
	if err != nil {
		return "", err
	}

	return base64.StdEncoding.EncodeToString([]byte(conv)), nil
}
476301
func (m *Marshaller) Encode(obj interface{}, w io.Writer) error {
	m.writer.w = w
	err := m.marshal.Marshal(obj)
	m.writer.w = nil
	return err
}
1102564
func (jsonEncoder) Encode(v ...interface{}) string {
	var data interface{} = v
	if v == nil {
		// So that empty results produces `[]` and not `null`
		data = []interface{}{}
	} else if len(v) == 1 {
		data = v[0]
	}
	b, err := json.Marshal(data)
	if err != nil {
		panic(err)
	}
	log.Printf("%s", b)
	return string(b)
}
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
}
549875
func Encode(b []byte, value int64) int {
	// 111111xx Byte-inverted negative two bit number (~xx)
	if value <= -1 && value >= -4 {
		b[0] = 0xFC | byte(^value&0xFF)
		return 1
	}
	// 111110__ + varint Negative recursive varint
	if value < 0 {
		b[0] = 0xF8
		return 1 + Encode(b[1:], -value)
	}
	// 0xxxxxxx 7-bit positive number
	if value <= 0x7F {
		b[0] = byte(value)
		return 1
	}
	// 10xxxxxx + 1 byte 14-bit positive number
	if value <= 0x3FFF {
		b[0] = byte(((value >> 8) & 0x3F) | 0x80)
		b[1] = byte(value & 0xFF)
		return 2
	}
	// 110xxxxx + 2 bytes 21-bit positive number
	if value <= 0x1FFFFF {
		b[0] = byte((value>>16)&0x1F | 0xC0)
		b[1] = byte((value >> 8) & 0xFF)
		b[2] = byte(value & 0xFF)
		return 3
	}
	// 1110xxxx + 3 bytes 28-bit positive number
	if value <= 0xFFFFFFF {
		b[0] = byte((value>>24)&0xF | 0xE0)
		b[1] = byte((value >> 16) & 0xFF)
		b[2] = byte((value >> 8) & 0xFF)
		b[3] = byte(value & 0xFF)
		return 4
	}
	// 111100__ + int (32-bit) 32-bit positive number
	if value <= math.MaxInt32 {
		b[0] = 0xF0
		binary.BigEndian.PutUint32(b[1:], uint32(value))
		return 5
	}
	// 111101__ + long (64-bit) 64-bit number
	if value <= math.MaxInt64 {
		b[0] = 0xF4
		binary.BigEndian.PutUint64(b[1:], uint64(value))
		return 9
	}

	return 0
}
130497
func Base64Decode(raw []byte) []byte {
	var buf bytes.Buffer
	buf.Write(raw)
	decoder := base64.NewDecoder(base64.StdEncoding, &buf)
	decoded, _ := ioutil.ReadAll(decoder)
	return decoded
}
581141
func encode(src interface{}) ([]byte, error) {
	jsoninsh, err := json.Marshal(src)
	if err != nil {
		return nil, err
	}

	var buf bytes.Buffer
	gsw := gzip.NewWriter(&buf)
	_, err = gsw.Write(jsoninsh)
	if err != nil {
		return nil, err
	}
	err = gsw.Close()
	if err != nil {
		return nil, err
	}
	return buf.Bytes(), nil
}
909884
func Encode(content string) (barcode.Barcode, error) {
	checkValid, _ := regexp.Compile(`[ABCD][0123456789\-\$\:/\.\+]*[ABCD]$`)
	if content == "!" || checkValid.ReplaceAllString(content, "!") != "!" {
		return nil, fmt.Errorf("can not encode \"%s\"", content)
	}
	resBits := new(utils.BitList)
	for i, r := range content {
		if i > 0 {
			resBits.AddBit(false)
		}
		resBits.AddBit(encodingTable[r]...)
	}
	return utils.New1DCode(barcode.TypeCodabar, content, resBits), nil
}
1157808
func (e *Encoder) Encode(v interface{}) error {
	val := reflect.ValueOf(v)
	return e.encode(val)
}
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)
}