Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        internal static string FromStringInReadStream(BinaryReader reader)
        {
            string s;

            if (!MalockMessage.TryFromStringInReadStream(reader, out s))
            {
                throw new EndOfStreamException();
            }
            return(s);
        }
Ejemplo n.º 3
0
 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)));
     }
 }
Ejemplo n.º 4
0
 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;
 }
Ejemplo n.º 5
0
 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);
 }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
 internal static MalockNodeMessage New(string key, string identity, byte command, int timeout)
 {
     return(New(key, identity, command, MalockMessage.NewId(), timeout));
 }
Ejemplo n.º 8
0
        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));
        }
Ejemplo n.º 9
0
        internal static bool TrySendMessage(IMalockSocket malock, MalockMessage message)
        {
            Exception exception = null;

            return(TrySendMessage(malock, message, ref exception));
        }