package mtproto

import (
	

	
)

func ( *Conn) ( context.Context,  int64,  int32,  bin.Encoder) error {
	return .write(, , , )
}

func ( *Conn) ( context.Context,  bin.Encoder) error {
	,  := .nextMsgSeq(false)
	return .write(, , , )
}

var bufPool = bin.NewPool(0)

func ( *Conn) ( context.Context,  int64,  int32,  bin.Encoder) error {
	// Grab shared lock for writing.
	// It prevents message sending during key regeneration if server forgot current auth key.
	.exchangeLock.RLock()
	defer .exchangeLock.RUnlock()

	 := bufPool.Get()
	defer bufPool.Put()

	if  := .newEncryptedMessage(, , , );  != nil {
		return 
	}

	if  := .conn.Send(, );  != nil {
		return 
	}

	return nil
}

func ( *Conn) ( bool) ( int64,  int32) {
	.reqMux.Lock()
	defer .reqMux.Unlock()

	 = .newMessageID()

	// Computing current sequence number (seqno).
	// This should be serialized with new message id generation.
	//
	// See https://github.com/gotd/td/issues/245 for reference.
	 = .sentContentMessages * 2
	if  {
		++
		.sentContentMessages++
	}

	return
}