using System;
using System.Collections.Generic;
using System.Text;
namespace BCG
{
///
/// Type of messages that can be sent over the transport.
///
public enum RemoteMessageType
{
Heartbeat, Data, Connection, Disconnection
}
///
/// Every message from a remote peer, is represented as a RemoteMessage.
/// This can be a transport generated message (heartbeat) or user generated
/// message (data)
///
public class RemoteMessage
{
private byte[]? myMsg;
private RemoteMessageType myMsgType;
private RemoteConnectionInfo myConnInfo;
public RemoteMessage(byte[]? message, RemoteMessageType messageType, RemoteConnectionInfo connInfo)
{
myMsg = message;
myMsgType = messageType;
myConnInfo = connInfo;
}
public byte[]? message
{
get { return myMsg; }
}
public RemoteMessageType messageType
{
get { return myMsgType; }
}
public RemoteConnectionInfo remoteConnectionInfo
{
get { return myConnInfo; }
}
override public string ToString()
{
Func len = (byte[] m) => { return m == null ? 0 : m.Length; };
return $"type: {myMsgType} conn: {myConnInfo} msg: {len(myMsg)}";
}
}
}