2021-03-11 07:42:42 +03:00
|
|
|
package codec
|
|
|
|
|
2024-12-23 21:17:32 +03:00
|
|
|
import "gopkg.in/yaml.v3"
|
|
|
|
|
2021-03-11 07:42:42 +03:00
|
|
|
// 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
|
|
|
}
|
|
|
|
|
2024-12-23 18:38:01 +03:00
|
|
|
// MarshalYAML returns frame data
|
|
|
|
func (m *Frame) MarshalYAML() ([]byte, error) {
|
|
|
|
return m.Marshal()
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnmarshalYAML set frame data
|
2024-12-23 21:17:32 +03:00
|
|
|
func (m *Frame) UnmarshalYAML(n *yaml.Node) error {
|
|
|
|
m.Data = []byte(n.Value)
|
|
|
|
return nil
|
2024-12-23 18:38:01 +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
|
|
|
|
}
|