Пример #1
0
        public static bool Deserialize(IReadableStreamSync stream, ref Int32 i)
        {
            var  bytes          = new byte[sizeof(Int32)];
            bool stillConnected = stream.ReadAll(bytes, 0, bytes.Length);

            if (!stillConnected)
            {
                return(false);
            }

            Int32 iNetworkOrder = BitConverter.ToInt32(bytes, 0);

            i = IPAddress.NetworkToHostOrder(iNetworkOrder);
            return(true);
        }
Пример #2
0
        public static bool Deserialize(IReadableStreamSync stream, ref string s)
        {
            // first read length of string
            Int32 length         = 0;
            bool  stillConnected = Deserialize(stream, ref length);

            if (!stillConnected)
            {
                return(false);
            }

            // length check
            if (length < 0 || length > MAX_STRING_LEN)
            {
                // if other end sends bad length, we can't currently handle it  DEV: improve
                return(false);
            }

            var bytes = new byte[length];

            stillConnected = stream.ReadAll(bytes, 0, bytes.Length);
            if (!stillConnected)
            {
                return(false);
            }
            try
            {
                s = m_asciiEncoder.GetString(bytes);
                return(true);
            }
            catch
            {
                // if other end sends bad info, we can't currently handle it  DEV: improve
                return(false);
            }
        }
 public DeserializationAdapter(IReadableStreamSync stream)
 {
     m_inStream = stream;
 }