2021-03-11 07:42:42 +03:00
|
|
|
package codec
|
|
|
|
|
|
|
|
// Frame gives us the ability to define raw data to send over the pipes
|
|
|
|
type Frame struct {
|
|
|
|
Data []byte
|
|
|
|
}
|
2021-09-22 16:59:52 +03:00
|
|
|
|
2021-11-19 09:22:13 +03:00
|
|
|
// NewFrame returns new frame with data
|
|
|
|
func NewFrame(data []byte) *Frame {
|
|
|
|
return &Frame{Data: data}
|
|
|
|
}
|
|
|
|
|
|
|
|
// MarshalJSON returns frame data
|
2021-09-22 16:59:52 +03:00
|
|
|
func (m *Frame) MarshalJSON() ([]byte, error) {
|
2021-11-19 09:22:13 +03:00
|
|
|
return m.Marshal()
|
2021-09-22 16:59:52 +03:00
|
|
|
}
|
|
|
|
|
2021-11-19 09:22:13 +03:00
|
|
|
// UnmarshalJSON set frame data
|
2021-09-22 16:59:52 +03:00
|
|
|
func (m *Frame) UnmarshalJSON(data []byte) error {
|
2021-11-19 09:22:13 +03:00
|
|
|
return m.Unmarshal(data)
|
2021-09-22 16:59:52 +03:00
|
|
|
}
|
|
|
|
|
2021-11-19 09:22:13 +03:00
|
|
|
// ProtoMessage noop func
|
2021-09-22 16:59:52 +03:00
|
|
|
func (m *Frame) ProtoMessage() {}
|
|
|
|
|
2021-11-19 09:22:13 +03:00
|
|
|
// Reset resets frame
|
2021-09-22 16:59:52 +03:00
|
|
|
func (m *Frame) Reset() {
|
|
|
|
*m = Frame{}
|
|
|
|
}
|
|
|
|
|
2021-11-19 09:22:13 +03:00
|
|
|
// String returns frame as string
|
2021-09-22 16:59:52 +03:00
|
|
|
func (m *Frame) String() string {
|
|
|
|
return string(m.Data)
|
|
|
|
}
|
|
|
|
|
2021-11-19 09:22:13 +03:00
|
|
|
// Marshal returns frame data
|
2021-09-22 16:59:52 +03:00
|
|
|
func (m *Frame) Marshal() ([]byte, error) {
|
|
|
|
return m.Data, nil
|
|
|
|
}
|
|
|
|
|
2021-11-19 09:22:13 +03:00
|
|
|
// Unmarshal set frame data
|
2021-09-22 16:59:52 +03:00
|
|
|
func (m *Frame) Unmarshal(data []byte) error {
|
|
|
|
m.Data = data
|
|
|
|
return nil
|
|
|
|
}
|