tractor.dev/toolkit-go@v0.0.0-20241010005851-214d91207d07/duplex/mux/frame/message_close.go (about)

     1  package frame
     2  
     3  import (
     4  	"bytes"
     5  	"encoding/binary"
     6  	"fmt"
     7  )
     8  
     9  type CloseMessage struct {
    10  	ChannelID uint32
    11  }
    12  
    13  func (msg CloseMessage) String() string {
    14  	return fmt.Sprintf("{CloseMessage ChannelID:%d}", msg.ChannelID)
    15  }
    16  
    17  func (msg CloseMessage) Channel() (uint32, bool) {
    18  	return msg.ChannelID, true
    19  }
    20  
    21  func (msg CloseMessage) Bytes() []byte {
    22  	buf := new(bytes.Buffer)
    23  	buf.WriteByte(msgChannelClose)
    24  	binary.Write(buf, binary.BigEndian, msg)
    25  	return buf.Bytes()
    26  }