diff --git a/DarkRift/Message.cs b/DarkRift/Message.cs index 44cc453..8680dd1 100644 --- a/DarkRift/Message.cs +++ b/DarkRift/Message.cs @@ -189,13 +189,33 @@ public static Message CreateEmpty(ushort tag) /// The tag the message has. /// The initial data in the message. public static Message Create(ushort tag, DarkRiftWriter writer) + { + return Create(tag, writer.ToBuffer()); + } + + /// + /// Creates a new message with the given tag and data. + /// + /// The tag the message has. + /// The initial data in the message. + public static Message Create(ushort tag, byte[] data) + { + return Create(tag, new UnmanagedMemoryBuffer(data, 0, data.Length)); + } + + /// + /// Creates a new message with the given tag and message buffer. + /// + /// The tag the message has. + /// The initial data in the message. + 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; @@ -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]; @@ -289,7 +309,7 @@ internal static Message Create(IMessageBuffer buffer, bool isReadOnly) /// internal Message() { - + } /// @@ -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;