tractor.dev/toolkit-go@v0.0.0-20241010005851-214d91207d07/duplex/mux/frame/message_data.go (about) 1 package frame 2 3 import ( 4 "encoding/binary" 5 "fmt" 6 ) 7 8 type DataMessage struct { 9 ChannelID uint32 10 Length uint32 11 Data []byte 12 } 13 14 func (msg DataMessage) String() string { 15 return fmt.Sprintf("{DataMessage ChannelID:%d Length:%d Data: ... }", 16 msg.ChannelID, msg.Length) 17 } 18 19 func (msg DataMessage) Channel() (uint32, bool) { 20 return msg.ChannelID, true 21 } 22 23 func (msg DataMessage) Bytes() []byte { 24 packet := make([]byte, 9) 25 packet[0] = msgChannelData 26 binary.BigEndian.PutUint32(packet[1:5], msg.ChannelID) 27 binary.BigEndian.PutUint32(packet[5:9], msg.Length) 28 return append(packet, msg.Data...) 29 }