MCPcopy
hub / github.com/Terry-Mao/goim / WriteTCP

Method WriteTCP

api/comet/grpc/protocol.go:97–120  ·  view source on GitHub ↗

WriteTCP write a proto to TCP writer.

(wr *bufio.Writer)

Source from the content-addressed store, hash-verified

95
96// WriteTCP write a proto to TCP writer.
97func (p *Proto) WriteTCP(wr *bufio.Writer) (err error) {
98 var (
99 buf []byte
100 packLen int32
101 )
102 if p.Op == OpRaw {
103 // write without buffer, job concact proto into raw buffer
104 _, err = wr.WriteRaw(p.Body)
105 return
106 }
107 packLen = _rawHeaderSize + int32(len(p.Body))
108 if buf, err = wr.Peek(_rawHeaderSize); err != nil {
109 return
110 }
111 binary.BigEndian.PutInt32(buf[_packOffset:], packLen)
112 binary.BigEndian.PutInt16(buf[_headerOffset:], int16(_rawHeaderSize))
113 binary.BigEndian.PutInt16(buf[_verOffset:], int16(p.Ver))
114 binary.BigEndian.PutInt32(buf[_opOffset:], p.Op)
115 binary.BigEndian.PutInt32(buf[_seqOffset:], p.Seq)
116 if p.Body != nil {
117 _, err = wr.Write(p.Body)
118 }
119 return
120}
121
122// WriteTCPHeart write TCP heartbeat with room online.
123func (p *Proto) WriteTCPHeart(wr *bufio.Writer, online int32) (err error) {

Callers 2

dispatchTCPMethod · 0.80
authTCPMethod · 0.80

Calls 5

WriteRawMethod · 0.80
PutInt32Method · 0.80
PutInt16Method · 0.80
PeekMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected