public static byte[] ToArray(this ZmqMessage message) { var result = new byte[message.Size]; message.CopyTo(result); return(result); }
public void Receive(ZmqMessage message, ZmqSendReceiveFlags flags = ZmqSendReceiveFlags.None) { CheckDisposed(); if (message == null) { throw new ArgumentNullException(nameof(message)); } LibZmq.zmq_msg_recv(message.DangerousGetNativeMessage(), Handle, flags).ThrowIfLastError(); }
public static void Send(this ZmqSocket socket, byte[] message, ZmqSendReceiveFlags flags = ZmqSendReceiveFlags.None) { if (message == null) { throw new ArgumentNullException(nameof(message)); } using var msg = new ZmqMessage(message); socket.Send(msg, flags); }
public static void CopyTo(this ZmqMessage message, byte[] target, int targetOffset = 0, int length = -1) { if (targetOffset < 0 || targetOffset >= target.Length) { throw new ArgumentOutOfRangeException(nameof(targetOffset)); } if (length == -1) { length = target.Length; } if (length <= 0 || targetOffset + length > target.Length || length > message.Size) { throw new ArgumentOutOfRangeException(nameof(length)); } Marshal.Copy(message.DangerousGetData(), target, targetOffset, length); }
public static void CopyFrom(this ZmqMessage message, byte[] source, int sourceOffset = 0, int length = -1) { if (sourceOffset < 0 || sourceOffset >= source.Length) { throw new ArgumentOutOfRangeException(nameof(sourceOffset)); } if (length == -1) { length = source.Length; } if (length <= 0 || sourceOffset + length > source.Length || length > message.Size) { throw new ArgumentOutOfRangeException(nameof(length)); } Marshal.Copy(source, sourceOffset, message.DangerousGetData(), length); }
public static unsafe string ReceiveText(this ZmqSocket socket, ZmqSendReceiveFlags flags = ZmqSendReceiveFlags.None, Encoding encoding = null) { using var result = new ZmqMessage(); socket.Receive(result, flags); return((encoding ?? Encoding.UTF8).GetString((byte *)result.DangerousGetData(), result.Size)); }
public static byte[] Receive(this ZmqSocket socket, ZmqSendReceiveFlags flags = ZmqSendReceiveFlags.None) { using var result = new ZmqMessage(); socket.Receive(result, flags); return(result.ToArray()); }