package mtproto
import (
"context"
"github.com/gotd/td/bin"
)
func (c *Conn ) writeContentMessage (ctx context .Context , msgID int64 , seqNo int32 , message bin .Encoder ) error {
return c .write (ctx , msgID , seqNo , message )
}
func (c *Conn ) writeServiceMessage (ctx context .Context , message bin .Encoder ) error {
msgID , seqNo := c .nextMsgSeq (false )
return c .write (ctx , msgID , seqNo , message )
}
var bufPool = bin .NewPool (0 )
func (c *Conn ) write (ctx context .Context , msgID int64 , seqNo int32 , message bin .Encoder ) error {
c .exchangeLock .RLock ()
defer c .exchangeLock .RUnlock ()
b := bufPool .Get ()
defer bufPool .Put (b )
if err := c .newEncryptedMessage (msgID , seqNo , message , b ); err != nil {
return err
}
if err := c .conn .Send (ctx , b ); err != nil {
return err
}
return nil
}
func (c *Conn ) nextMsgSeq (content bool ) (msgID int64 , seqNo int32 ) {
c .reqMux .Lock ()
defer c .reqMux .Unlock ()
msgID = c .newMessageID ()
seqNo = c .sentContentMessages * 2
if content {
seqNo ++
c .sentContentMessages ++
}
return
}
The pages are generated with Golds v0.6.7 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds .