초기커밋
This commit is contained in:
152
Protocol/Marshaler.cs
Normal file
152
Protocol/Marshaler.cs
Normal file
@@ -0,0 +1,152 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
using Nettention.Proud;
|
||||
|
||||
|
||||
#pragma warning disable 8981
|
||||
|
||||
using pb = global::Google.Protobuf;
|
||||
using pbc = global::Google.Protobuf.Collections;
|
||||
using pbr = global::Google.Protobuf.Reflection;
|
||||
using scg = global::System.Collections.Generic;
|
||||
|
||||
|
||||
#pragma warning disable 8625
|
||||
|
||||
|
||||
namespace Protocol
|
||||
{
|
||||
public class CaliMarshaler : Nettention.Proud.Marshaler
|
||||
{
|
||||
static bool ReadMessage(Message msg, out ByteArray arr)
|
||||
{
|
||||
if (msg.Read(out arr) == false)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void WriteMessage(Message msg, MemoryStream stream)
|
||||
{
|
||||
ByteArray by = ByteArray.CopyFrom(stream.ToArray());
|
||||
msg.Write(by);
|
||||
}
|
||||
|
||||
public static bool Read(Message msg, out ClientToLogin packet)
|
||||
{
|
||||
packet = null;
|
||||
ByteArray arr;
|
||||
if (ReadMessage(msg, out arr) == false)
|
||||
return false;
|
||||
|
||||
packet = ClientToLogin.Parser.ParseFrom(arr.data);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool Read(Message msg, out ClientToGame packet)
|
||||
{
|
||||
try
|
||||
{
|
||||
packet = null;
|
||||
ByteArray arr;
|
||||
if (ReadMessage(msg, out arr) == false)
|
||||
return false;
|
||||
|
||||
packet = ClientToGame.Parser.ParseFrom(arr.data);
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
var err_msg = $"Exception !!!, Failed to perform in CaliMarshaler.Read() !!! : exception:{e} - {msg.ToString()}";
|
||||
throw new System.Runtime.InteropServices.MarshalDirectiveException(err_msg);
|
||||
}
|
||||
}
|
||||
|
||||
public static bool Read(Message msg, out ClientToChat packet)
|
||||
{
|
||||
packet = null;
|
||||
ByteArray arr;
|
||||
if (ReadMessage(msg, out arr) == false)
|
||||
return false;
|
||||
|
||||
packet = ClientToChat.Parser.ParseFrom(arr.data);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void Write(Message msg, ClientToLogin packet)
|
||||
{
|
||||
using (MemoryStream stream = new MemoryStream())
|
||||
{
|
||||
using (pb::CodedOutputStream output = new pb::CodedOutputStream(stream))
|
||||
{
|
||||
packet.WriteTo(output);
|
||||
}
|
||||
|
||||
WriteMessage(msg, stream);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Write(Message msg, ClientToGame packet)
|
||||
{
|
||||
using (MemoryStream stream = new MemoryStream())
|
||||
{
|
||||
using (pb::CodedOutputStream output = new pb::CodedOutputStream(stream))
|
||||
{
|
||||
packet.WriteTo(output);
|
||||
}
|
||||
|
||||
WriteMessage(msg, stream);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Write(Message msg, ClientToChat packet)
|
||||
{
|
||||
using (MemoryStream stream = new MemoryStream())
|
||||
{
|
||||
using (pb::CodedOutputStream output = new pb::CodedOutputStream(stream))
|
||||
{
|
||||
packet.WriteTo(output);
|
||||
}
|
||||
|
||||
WriteMessage(msg, stream);
|
||||
}
|
||||
}
|
||||
|
||||
public static bool Read(Message msg, out GameProtocol packet)
|
||||
{
|
||||
try
|
||||
{
|
||||
packet = null;
|
||||
ByteArray arr;
|
||||
if (ReadMessage(msg, out arr) == false)
|
||||
return false;
|
||||
|
||||
packet = GameProtocol.Parser.ParseFrom(arr.data);
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
var err_msg = $"Exception !!!, Failed to perform in CaliMarshaler.Read() !!! : exception:{e} - {msg.ToString()}";
|
||||
throw new System.Runtime.InteropServices.MarshalDirectiveException(err_msg);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Write(Message msg, GameProtocol packet)
|
||||
{
|
||||
using (MemoryStream stream = new MemoryStream())
|
||||
{
|
||||
using (pb::CodedOutputStream output = new pb::CodedOutputStream(stream))
|
||||
{
|
||||
packet.WriteTo(output);
|
||||
}
|
||||
|
||||
WriteMessage(msg, stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user