Exemple #1
0
// MarshalBinary encodes the object to a binary format.
func (c *Conversation) MarshalBinary() ([]byte, error) {
	var pb internal.Conversation
	pb.Key = &c.Key
	for k, v := range c.Tags {
		key := k
		value := v
		pb.Tags = append(pb.Tags, &internal.Tag{Key: &key, Value: &value})
	}
	return proto.Marshal(&pb)
}
Exemple #2
0
// UnmarshalBinary decodes the object from a binary format.
func (c *Conversation) UnmarshalBinary(buf []byte) error {
	var pb internal.Conversation
	if err := proto.Unmarshal(buf, &pb); err != nil {
		return err
	}
	c.Key = pb.GetKey()
	c.Tags = make(map[string]string)
	for _, t := range pb.Tags {
		c.Tags[t.GetKey()] = t.GetValue()
	}
	return nil
}