Esempio n. 1
0
        internal static bool TryFromStringInReadStream(BinaryReader reader, out string s)
        {
            s = null;
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }
            Stream stream = reader.BaseStream;

            if (!MalockMessage.StreamIsReadable(stream, sizeof(short)))
            {
                return(false);
            }
            int len = reader.ReadInt16();

            if (len < 0)
            {
                return(true);
            }
            if (len == 0)
            {
                s = string.Empty;
                return(true);
            }
            if (!MalockMessage.StreamIsReadable(stream, len))
            {
                return(false);
            }
            s = Encoding.UTF8.GetString(reader.ReadBytes(len));
            return(true);
        }
Esempio n. 2
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);
        }