gecko/network/msg.go

27 lines
684 B
Go
Raw Normal View History

2020-03-10 12:20:34 -07:00
// (c) 2019-2020, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
2020-05-17 20:47:43 -07:00
package network
2020-03-10 12:20:34 -07:00
// Msg represents a set of fields that can be serialized into a byte stream
type Msg interface {
2020-05-25 13:02:03 -07:00
Op() Op
2020-03-10 12:20:34 -07:00
Get(Field) interface{}
2020-05-17 20:47:43 -07:00
Bytes() []byte
2020-03-10 12:20:34 -07:00
}
type msg struct {
2020-05-25 13:02:03 -07:00
op Op
2020-03-10 12:20:34 -07:00
fields map[Field]interface{}
2020-05-17 20:47:43 -07:00
bytes []byte
2020-03-10 12:20:34 -07:00
}
// Field returns the value of the specified field in this message
2020-05-25 13:02:03 -07:00
func (msg *msg) Op() Op { return msg.op }
2020-03-10 12:20:34 -07:00
// Field returns the value of the specified field in this message
func (msg *msg) Get(field Field) interface{} { return msg.fields[field] }
// Bytes returns this message in bytes
2020-05-17 20:47:43 -07:00
func (msg *msg) Bytes() []byte { return msg.bytes }