using System;
namespace Unity.Netcode
{
///
/// Used to react to different events in the messaging system. Primary use case is for
/// collecting profiling data and metrics data. Additionally, it provides OnVerifyCanSend and OnVerifyCanReceive
/// to allow for networking implementations to put limits on when certain messages can or can't be sent or received.
///
internal interface INetworkHooks
{
///
/// Called before an individual message is sent.
///
/// The destination clientId
/// The message being sent
///
void OnBeforeSendMessage(ulong clientId, ref T message, NetworkDelivery delivery) where T : INetworkMessage;
///
/// Called after an individual message is sent.
///
/// The destination clientId
/// The message being sent
///
/// Number of bytes in the message, not including the message header
void OnAfterSendMessage(ulong clientId, ref T message, NetworkDelivery delivery, int messageSizeBytes) where T : INetworkMessage;
///
/// Called before an individual message is received.
///
/// The source clientId
/// The type of the message being sent
/// Number of bytes in the message, not including the message header
void OnBeforeReceiveMessage(ulong senderId, Type messageType, int messageSizeBytes);
///
/// Called after an individual message is received.
///
/// The source clientId
/// The type of the message being sent
/// Number of bytes in the message, not including the message header
void OnAfterReceiveMessage(ulong senderId, Type messageType, int messageSizeBytes);
///
/// Called before a batch of messages is sent
///
/// The destination clientId
/// Number of messages in the batch
/// Number of bytes in the batch, including the batch header
///
void OnBeforeSendBatch(ulong clientId, int messageCount, int batchSizeInBytes, NetworkDelivery delivery);
///
/// Called after a batch of messages is sent
///
/// The destination clientId
/// Number of messages in the batch
/// Number of bytes in the batch, including the batch header
///
void OnAfterSendBatch(ulong clientId, int messageCount, int batchSizeInBytes, NetworkDelivery delivery);
///
/// Called before a batch of messages is received
///
/// The source clientId
/// Number of messages in the batch
/// Number of bytes in the batch, including the batch header
void OnBeforeReceiveBatch(ulong senderId, int messageCount, int batchSizeInBytes);
///
/// Called after a batch of messages is received
///
/// The source clientId
/// Number of messages in the batch
/// Number of bytes in the batch, including the batch header
void OnAfterReceiveBatch(ulong senderId, int messageCount, int batchSizeInBytes);
///
/// Called before a message is sent. If this returns false, the message will be discarded.
///
/// The destination clientId
/// The type of the message
///
///
bool OnVerifyCanSend(ulong destinationId, Type messageType, NetworkDelivery delivery);
///
/// Called before a message is received. If this returns false, the message will be discarded.
///
/// The source clientId
/// The type of the message
/// The FastBufferReader containing the message
/// The NetworkContext the message is being processed in
///
bool OnVerifyCanReceive(ulong senderId, Type messageType, FastBufferReader messageContent, ref NetworkContext context);
///
/// Called after a message is serialized, but before it's handled.
/// Differs from OnBeforeReceiveMessage in that the actual message object is passed and can be inspected.
///
/// The message object
/// The network context the message is being ahandled in
///
void OnBeforeHandleMessage(ref T message, ref NetworkContext context) where T : INetworkMessage;
///
/// Called after a message is serialized and handled.
/// Differs from OnAfterReceiveMessage in that the actual message object is passed and can be inspected.
///
/// The message object
/// The network context the message is being ahandled in
///
void OnAfterHandleMessage(ref T message, ref NetworkContext context) where T : INetworkMessage;
}
}