package mtproto

import (
	
	

	
	
	
)

func ( *Conn) ( int64,  int32,  bin.Encoder,  *bin.Buffer) error {
	 := .session()

	// TODO(tdakkota): Smarter gzip.
	// 	1) Generate Length() method for every encoder, to count length without encoding.
	// 	2) Re-use buffer instead of using yet one.
	// 	3) Do not send proto.GZIP if gzipped size is equal or bigger.
	var (
		   crypto.EncryptedMessageData
		 = .log
	)
	if .compressThreshold <= 0 {
		if ,  := .(interface{ () uint32 });  {
			 = .logWithTypeID(.())
		}
		 = crypto.EncryptedMessageData{
			SessionID: .ID,
			Salt:      .Salt,
			MessageID: ,
			SeqNo:     ,
			Message:   ,
		}
	} else {
		 := bufPool.Get()
		defer bufPool.Put()
		if  := .Encode();  != nil {
			return errors.Wrap(, "encode payload")
		}

		 = .logWithType()
		if .Len() > .compressThreshold {
			 = crypto.EncryptedMessageData{
				SessionID: .ID,
				Salt:      .Salt,
				MessageID: ,
				SeqNo:     ,
				Message:   proto.GZIP{Data: .Raw()},
			}
		} else {
			 = crypto.EncryptedMessageData{
				SessionID:              .ID,
				Salt:                   .Salt,
				MessageID:              ,
				SeqNo:                  ,
				MessageDataLen:         int32(.Len()),
				MessageDataWithPadding: .Buf,
			}
		}
	}

	.Debug("Request", zap.Int64("msg_id", ))
	if  := .cipher.Encrypt(.Key, , );  != nil {
		return errors.Wrap(, "encrypt")
	}

	return nil
}