Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions DarkRift/Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,33 @@ public static Message CreateEmpty(ushort tag)
/// <param name="tag">The tag the message has.</param>
/// <param name="writer">The initial data in the message.</param>
public static Message Create(ushort tag, DarkRiftWriter writer)
{
return Create(tag, writer.ToBuffer());
}

/// <summary>
/// Creates a new message with the given tag and data.
/// </summary>
/// <param name="tag">The tag the message has.</param>
/// <param name="data">The initial data in the message.</param>
public static Message Create(ushort tag, byte[] data)
{
return Create(tag, new UnmanagedMemoryBuffer(data, 0, data.Length));
}

/// <summary>
/// Creates a new message with the given tag and message buffer.
/// </summary>
/// <param name="tag">The tag the message has.</param>
/// <param name="buffer">The initial data in the message.</param>
private static Message Create(ushort tag, IMessageBuffer buffer)
{
Message message = ObjectCache.GetMessage();

message.isCurrentlyLoungingInAPool = false;

message.IsReadOnly = false;
message.buffer = writer.ToBuffer();
message.buffer = buffer;
message.tag = tag;
message.flags = 0;
message.PingCode = 0;
Expand Down Expand Up @@ -268,7 +288,7 @@ internal static Message Create(IMessageBuffer buffer, bool isReadOnly)

// We clone the message buffer so we can modify it's properties safely
message.buffer = buffer.Clone();

//Get flags first so we can query it
message.flags = buffer.Buffer[buffer.Offset];

Expand All @@ -289,7 +309,7 @@ internal static Message Create(IMessageBuffer buffer, bool isReadOnly)
/// </summary>
internal Message()
{

}

/// <summary>
Expand Down Expand Up @@ -448,7 +468,7 @@ public Message Clone()

//We don't want to give a reference to our buffer so we need to clone it
message.buffer = buffer.Clone();

message.flags = flags;
message.tag = tag;
message.PingCode = PingCode;
Expand Down