Exemple #1
0
        public static ConsensusMessage DeserializeFrom(byte[] data)
        {
            ConsensusMessageType type = (ConsensusMessageType)data[0];
            string           typeName = $"{typeof(ConsensusMessage).Namespace}.{type}";
            ConsensusMessage message  = typeof(ConsensusMessage).GetTypeInfo().Assembly.CreateInstance(typeName) as ConsensusMessage;

            using (MemoryStream ms = new MemoryStream(data, false))
                using (BinaryReader r = new BinaryReader(ms))
                {
                    message.Deserialize(r);
                }
            return(message);
        }
        public static ConsensusMessage DeserializeFrom(byte[] data)
        {
            ConsensusMessage message = ReflectionCache.CreateInstance <ConsensusMessage>(data[0]);

            if (message == null)
            {
                throw new FormatException();
            }

            using (MemoryStream ms = new MemoryStream(data, false))
                using (BinaryReader r = new BinaryReader(ms))
                {
                    message.Deserialize(r);
                }
            return(message);
        }