Beispiel #1
0
// Encode encodes the in interface into a msgpack streamed to the file  or
// into a bytes buffer configured inside the encoder struct
func Encode(in interface{}) (msgpack []byte, err error) {
	var b bytes.Buffer
	w := bufio.NewWriter(&b)
	h := new(codec.MsgpackHandle)
	Encoder := codec.NewEncoder(w, h)
	s := structs.New(in)
	lowerCased := s.LowerCaseMap() // Get a map[string]interface{}
	err = Encoder.Encode(lowerCased)
	w.Flush()
	msgpack = b.Bytes()
	return
}
Beispiel #2
0
// Serialize serialize an interface (which must be struct) into msgpack
// using the encoder m. Field names are lowercased.
func (m *Msgpack) Serialize(in interface{}) (err error) {
	s := structs.New(in)
	lowerCased := s.LowerCaseMap() // Get a map[string]interface{}
	err = m.E.Encode(lowerCased)
	return
}
Beispiel #3
0
// LogMsgPack encodes the in interface into a msgpack streamed to the file  or
// into a bytes buffer configured inside the encoder struct
func (m *Msgpack) LogMsgPack(in interface{}) error {
	s := structs.New(in)
	lowerCased := s.LowerCaseMap() // Get a map[string]interface{}
	err := m.Encoder.Encode(lowerCased)
	return err
}