37 lines
905 B
Go
37 lines
905 B
Go
|
package frame
|
||
|
|
||
|
import (
|
||
|
coder "git.hpds.cc/Component/mq_coder"
|
||
|
)
|
||
|
|
||
|
// AcceptedFrame is encoded bytes, Tag is a fixed value TYPE_ID_ACCEPTED_FRAME
|
||
|
type AcceptedFrame struct{}
|
||
|
|
||
|
// NewAcceptedFrame creates a new AcceptedFrame with a given TagId of user's data
|
||
|
func NewAcceptedFrame() *AcceptedFrame {
|
||
|
return &AcceptedFrame{}
|
||
|
}
|
||
|
|
||
|
// Type gets the type of Frame.
|
||
|
func (m *AcceptedFrame) Type() Type {
|
||
|
return TagOfAcceptedFrame
|
||
|
}
|
||
|
|
||
|
// Encode to coder encoded bytes.
|
||
|
func (m *AcceptedFrame) Encode() []byte {
|
||
|
accepted := coder.NewNodePacketEncoder(byte(m.Type()))
|
||
|
accepted.AddBytes(nil)
|
||
|
|
||
|
return accepted.Encode()
|
||
|
}
|
||
|
|
||
|
// DecodeToAcceptedFrame decodes coder encoded bytes to AcceptedFrame.
|
||
|
func DecodeToAcceptedFrame(buf []byte) (*AcceptedFrame, error) {
|
||
|
nodeBlock := coder.NodePacket{}
|
||
|
_, err := coder.DecodeToNodePacket(buf, &nodeBlock)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
return &AcceptedFrame{}, nil
|
||
|
}
|