public void ApplyMessage(BLIPMessage message) { blip_message_t *msg = this; if (message.Body != null) { _hasExtra = true; var newBody = Marshal.AllocHGlobal(message.Body?.Length ?? 0); Marshal.Copy(message.Body !, 0, newBody, message.Body !.Length); msg->body_size = (ulong)message.Body.Length; msg->body = (byte *)newBody.ToPointer(); } else { msg->body = null; msg->body_size = 0; } if (message.Properties != null) { _hasExtra = true; var newProps = Marshal.StringToCoTaskMemUTF8(message.Properties); msg->properties = (byte *)newProps.ToPointer(); } else { msg->properties = null; } msg->msg_no = message.MessageNumber; msg->flags = message.Flags; msg->type = message.Type; }
public BLIPMessage CreateMessage() { blip_message_t *msg = this; var retVal = new BLIPMessage { Body = new byte[msg->body_size], Checksum = msg->checksum, Flags = msg->flags, MessageNumber = msg->msg_no, Type = msg->type }; if (msg->properties != null) { retVal.Properties = Marshal.PtrToStringUTF8((IntPtr)msg->properties); } Marshal.Copy((IntPtr)msg->body, retVal.Body, 0, (int)msg->body_size); return(retVal); }
public BLIPMessageContainer(blip_message_t *messageHandle) : base((IntPtr)messageHandle) { }