36 lines
1.2 KiB
C#
36 lines
1.2 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
namespace BITKit
|
|
{
|
|
public interface INetMessage { }
|
|
public interface INetMessageReader
|
|
{
|
|
void Initialize();
|
|
Type GetMessageType();
|
|
object ReadBinaryAsObject(BinaryReader reader);
|
|
void WriteBinaryAsObject(BinaryWriter writer, Object value);
|
|
}
|
|
public interface INetMessageReader<T> : INetMessageReader
|
|
{
|
|
T ReadBinary(BinaryReader reader);
|
|
void WriteBinary(BinaryWriter writer, T value);
|
|
}
|
|
public abstract class NetMessageReader<T> : INetMessageReader<T>
|
|
{
|
|
public Type GetMessageType() => typeof(T);
|
|
public virtual void Initialize() { }
|
|
public abstract T ReadBinary(BinaryReader reader);
|
|
public object ReadBinaryAsObject(BinaryReader reader) => ReadBinary(reader);
|
|
public abstract void WriteBinary(BinaryWriter writer, T value);
|
|
public void WriteBinaryAsObject(BinaryWriter writer, object value) => WriteBinary(writer, (T)value);
|
|
}
|
|
public interface INetMessager : IDiagnostics
|
|
{
|
|
void Init();
|
|
void Send<T>(T message);
|
|
void Register<T>(Action<T> action);
|
|
void UnRegister<T>(Action<T> action);
|
|
}
|
|
} |