You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Zero/ZeroLevel/Services/Network/Services/FrameBuilder.cs

77 lines
2.4 KiB

using ZeroLevel.Services.Serialization;
namespace ZeroLevel.Network
{
public static class FrameBuilder
{
public static Frame BuildFrame<T>(T obj, string inbox)
{
var frame = Frame.FromPool();
frame.FrameId = Frame.GetMessageId();
frame.IsRequest = false;
frame.Inbox = inbox;
frame.Payload = MessageSerializer.SerializeCompatible(obj);
return frame;
}
public static Frame BuildFrame(string inbox)
{
var frame = Frame.FromPool();
frame.FrameId = Frame.GetMessageId();
frame.IsRequest = false;
frame.Inbox = inbox;
frame.Payload = null;
return frame;
}
public static Frame BuildRequestFrame<T>(T obj, string inbox)
{
var frame = Frame.FromPool();
frame.FrameId = Frame.GetMessageId();
frame.IsRequest = true;
frame.Inbox = inbox;
frame.Payload = MessageSerializer.SerializeCompatible(obj);
return frame;
}
public static Frame BuildRequestFrame(string inbox)
{
var frame = Frame.FromPool();
frame.FrameId = Frame.GetMessageId();
frame.IsRequest = true;
frame.Inbox = inbox;
frame.Payload = null;
return frame;
}
public static Frame BuildResponseFrame(object obj, Frame request)
{
var frame = Frame.FromPool();
frame.IsRequest = true;
frame.FrameId = request.FrameId;
frame.Inbox = request.Inbox;
frame.Payload = MessageSerializer.SerializeCompatible(obj);
return frame;
}
public static Frame BuildResponseFrame<T>(T obj, Frame request)
{
var frame = Frame.FromPool();
frame.IsRequest = true;
frame.FrameId = request.FrameId;
frame.Inbox = request.Inbox;
frame.Payload = MessageSerializer.SerializeCompatible(obj);
return frame;
}
public static Frame BuildResponseFrame<T>(T obj, Frame request, string inbox)
{
var frame = Frame.FromPool();
frame.IsRequest = true;
frame.FrameId = request.FrameId;
frame.Inbox = inbox;
frame.Payload = MessageSerializer.SerializeCompatible(obj);
return frame;
}
}
}

Powered by TurnKey Linux.