package mtproto

import (
	
	

	
	
	
	
)

func ( *Conn) ( *bin.Buffer) error {
	// Response to an RPC query.
	var  proto.Result
	if  := .Decode();  != nil {
		return errors.Wrap(, "decode")
	}

	// Now b contains result message.
	.ResetTo(.Result)

	 := zap.Int64("msg_id", .RequestMessageID)
	.logWithBuffer().Debug("Handle result", )

	// Handling gzipped results.
	,  := .PeekID()
	if  != nil {
		return 
	}
	if  == proto.GZIPTypeID {
		,  := gzip()
		if  != nil {
			return errors.Wrap(, "decompress")
		}

		// Replacing buffer so callback will deal with uncompressed data.
		 = 
		.logWithBuffer().Debug("Decompressed", )

		// Replacing id with inner id if error is compressed for any reason.
		if ,  = .PeekID();  != nil {
			return errors.Wrap(, "peek id")
		}
	}

	if  == mt.RPCErrorTypeID {
		var  mt.RPCError
		if  := .Decode();  != nil {
			return errors.Wrap(, "error decode")
		}

		.log.Debug("Got error", ,
			zap.Int("err_code", .ErrorCode),
			zap.String("err_msg", .ErrorMessage),
		)
		.rpc.NotifyError(.RequestMessageID, tgerr.New(.ErrorCode, .ErrorMessage))

		return nil
	}
	if  == mt.PongTypeID {
		return .handlePong()
	}

	return .rpc.NotifyResult(.RequestMessageID, )
}