internal static MalockNnsMessage Deserialize(Stream stream) { if (stream == null) { throw new ArgumentNullException("stream"); } BinaryReader br = new BinaryReader(stream); var m = new MalockNnsMessage(); if (!MalockMessage.DeserializeTo(m, br)) { return(null); } string s; if (!MalockMessage.TryFromStringInReadStream(br, out s)) { return(null); } m.Key = s; if (!MalockMessage.TryFromStringInReadStream(br, out s)) { return(null); } m.Identity = s; return(m); }
internal static string FromStringInReadStream(BinaryReader reader) { string s; if (!MalockMessage.TryFromStringInReadStream(reader, out s)) { throw new EndOfStreamException(); } return(s); }
internal static bool TrySendMessage(IMalockSocket socket, MalockMessage message, byte[] buffer, int ofs, int len) { if (socket == null || message == null) { return(false); } using (MemoryStream ms = (MemoryStream)message.Serialize()) { if (buffer != null) { ms.Write(buffer, ofs, len); } return(socket.Send(ms.GetBuffer(), 0, Convert.ToInt32(ms.Position))); } }
protected MalockNetworkMessage(IMalockSocket socket, Stream stream, MalockMessage message) { if (socket == null) { throw new ArgumentNullException("socket"); } if (stream == null) { throw new ArgumentNullException("stream"); } if (message == null) { throw new ArgumentNullException("message"); } this.socket = socket; this.Stream = stream; this.Message = message; }
internal static bool TrySendMessage(IMalockSocket malock, MalockMessage message, ref Exception exception) { if (malock == null) { throw new ArgumentNullException("malock"); } if (message == null) { throw new ArgumentNullException("message"); } using (MemoryStream ms = (MemoryStream)message.Serialize()) { if (!malock.Send(ms.GetBuffer(), 0, unchecked ((int)ms.Position))) { exception = new InvalidOperationException("The malock send returned results do not match the expected"); return(false); } } return(true); }
internal static bool DeserializeTo(MalockMessage message, BinaryReader reader) { if (message == null) { throw new ArgumentNullException("message"); } if (reader == null) { throw new ArgumentNullException("reader"); } Stream stream = reader.BaseStream; if (!MalockMessage.StreamIsReadable(stream, sizeof(byte))) { return(false); } message.Command = reader.ReadByte(); if (!MalockMessage.StreamIsReadable(stream, sizeof(int))) { return(false); } message.Sequence = reader.ReadInt32(); return(true); }
internal static MalockNodeMessage New(string key, string identity, byte command, int timeout) { return(New(key, identity, command, MalockMessage.NewId(), timeout)); }
internal static bool TryInvokeAsync(IMalockSocket malock, MalockMessage message, int timeout, Action <int, MalockMessage, Stream> callback) { Exception exception = null; return(TryInvokeAsync(malock, message, timeout, callback, ref exception)); }
internal static bool TrySendMessage(IMalockSocket malock, MalockMessage message) { Exception exception = null; return(TrySendMessage(malock, message, ref exception)); }