// encodeArray encodes a BSON Array.
485075
func encodeArray(buf *bytes.Buffer, path, name string, val Array) error {
	// Array is encoded as a document with incrementing numeric keys.
	if len(val) == 0 {
		return nil
	}

	// type
	if err := buf.WriteByte(_ARRAY); err != nil {
		return err
	}

	// name
	if err := writeCstring(buf, name); err != nil {
		return err
	}

	// Create array doc.
	tmp := bytes.NewBuffer(make([]byte, 0))

	// This will be replaced by the size of the doc later.
	if err := binary.Write(tmp, binary.LittleEndian, uint32(0)); err != nil {
		return err
	}
	for i := 0; i < len(val); i++ {
		name := strconv.Itoa(i)
		var newpath string
		if path == "" {
			newpath = name
		} else {
			newpath = strings.Join([]string{path, name}, ".")
		}
		if err := encodeVal(tmp, newpath, name, val[i]); err != nil {
			return err
		}
	}

	// End of BSON null byte.
	if err := tmp.WriteByte(0x00); err != nil {
		return err
	}

	// Write size of document at start of BSON.
	binary.LittleEndian.PutUint32(tmp.Bytes(), uint32(tmp.Len()))
	buf.Write(tmp.Bytes())

	return nil
}
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
}
112523
func (enc *Encoder) EncodeObject(v MarshalerJSONObject) error {
	if enc.isPooled == 1 {
		panic(InvalidUsagePooledEncoderError("Invalid usage of pooled encoder"))
	}
	_, err := enc.encodeObject(v)
	if err != nil {
		enc.err = err
		return err
	}
	_, err = enc.Write()
	if err != nil {
		enc.err = err
		return err
	}
	return nil
}
45463
func encode(data interface{}) ([]byte, error) {
	if data == nil {
		return nil, nil
	}
	buf := bytes.NewBuffer([]byte{})
	enc := gob.NewEncoder(buf)
	if err := enc.Encode(data); err != nil {
		return nil, err
	}
	return buf.Bytes(), nil
}
1333769
func Encode(in []byte) (string, error) {
	return b64.StdEncoding.EncodeToString(in), nil
}
1206269
func Encode(ctx context.Context) ([]byte, error) {
	m := ToMap(ctx)
	if len(m) > 0 {
		return json.Marshal(m)
	}
	return nil, nil
}
718525
func (enc *Encoder) Encode(v interface{}) error {
	err := enc.p.marshalValue(reflect.ValueOf(v), nil, nil)
	if err != nil {
		return err
	}
	return enc.p.Flush()
}
433971
func (v *VARIANT) ToArray() *SafeArrayConversion {
	if v.VT != VT_SAFEARRAY {
		if v.VT&VT_ARRAY == 0 {
			return nil
		}
	}
	var safeArray *SafeArray = (*SafeArray)(unsafe.Pointer(uintptr(v.Val)))
	return &SafeArrayConversion{safeArray}
}
63306
func (b *Base) TransformArray(entities interface{}) ([]map[string]interface{}, error) {
	s := reflect.ValueOf(entities)
	if s.Kind() != reflect.Slice && s.Kind() != reflect.Array {
		return nil, fmt.Errorf("TransformArray() given a non-slice type")
	}
	result := []map[string]interface{}{}
	for i := 0; i < s.Len(); i++ {
		result = append(result, b.Transform(s.Index(i).Interface()))
	}
	return result, nil
}
855835
func (e *Encoder) StructAsArray(flag bool) *Encoder {
	e.structAsArray = flag
	return e
}
1351998
func (i *InverseBloomFilter) decodeToArray(stream io.Reader) ([][]byte, uint64, uint64, error) {
	var capacity, size uint64

	err := binary.Read(stream, binary.BigEndian, &capacity)
	if err != nil {
		return nil, 0, 0, err
	}

	err = binary.Read(stream, binary.BigEndian, &size)
	if err != nil {
		return nil, 0, 0, err
	}

	// Read the encoded slice and decode into [][]byte
	encoded := make([]byte, size)
	stream.Read(encoded)
	buf := bytes.NewBuffer(encoded)
	dec := gob.NewDecoder(buf)
	decoded := make([][]byte, capacity)
	dec.Decode(&decoded)

	return decoded, capacity, size, nil
}
1186353
func (g GobEncoder) Encode(v interface{}) ([]byte, error) {
	var buf bytes.Buffer
	e := gob.NewEncoder(&buf)
	err := e.Encode(v)
	return buf.Bytes(), err
}
704367
func JSONArray(in string) ([]interface{}, error) {
	obj := make([]interface{}, 1)
	return unmarshalArray(obj, in, yaml.Unmarshal)
}
1353404
func Base64Encode(b []byte) []byte {
	buf := make([]byte, base64.RawURLEncoding.EncodedLen(len(b)))
	base64.RawURLEncoding.Encode(buf, b)
	return buf
}
679909
func Encode(b []byte) string {
	enc := make([]byte, len(b)*2+2)
	copy(enc, "0x")
	hex.Encode(enc[2:], b)
	return string(enc)
}
528405
func ToArray(value interface{}) (values []string) {
	switch value := value.(type) {
	case []string:
		values = []string{}
		for _, v := range value {
			if v != "" {
				values = append(values, v)
			}
		}
	case []interface{}:
		for _, v := range value {
			values = append(values, fmt.Sprint(v))
		}
	default:
		if value := fmt.Sprint(value); value != "" {
			values = []string{value}
		}
	}
	return
}
826712
func EncodeJSON(in interface{}) ([]byte, error) {
	if in == nil {
		return nil, fmt.Errorf("input for encoding is nil")
	}
	var buf bytes.Buffer
	enc := json.NewEncoder(&buf)
	if err := enc.Encode(in); err != nil {
		return nil, err
	}
	return buf.Bytes(), nil
}