Ejemplo n.º 1
0
        /// <summary>
        /// Deserializes raw data of a known message type to a <see cref="MessageContainer"/>.
        /// </summary>
        /// <param name="sender">The <see cref="IPEndPoint"/> of the sender.</param>
        /// <param name="payload">The raw data.</param>
        /// <param name="messageType">The message type as a <see cref="byte"/>.
        /// Has to be one of the supported <see cref="MessageType">MessageTypes</see></param>
        /// <returns>The deserialized <see cref="MessageContainer"/>.</returns>
        public static MessageContainer Deserialize(IPEndPoint sender, byte[] payload, byte messageType)
        {
            MessageType type    = (MessageType)messageType;
            var         message = new MessageContainer(type, payload)
            {
                Sender = sender
            };

            return(message);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Unpacks a <see cref="MessageContainer"/> of the type <see cref="MessageDeleteAllVisContainers"/>.
        /// </summary>
        /// <param name="container">The container of the message.</param>
        /// <returns>The unpacked message.</returns>
        public static MessageDeleteAllVisContainers Unpack(MessageContainer container)
        {
            if (container.Type != Type)
            {
                return(null);
            }

            var result = JsonConvert.DeserializeObject <MessageDeleteAllVisContainers>(Encoding.UTF8.GetString(container.Payload));

            return(result);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Unpacks a <see cref="MessageContainer"/> of the type <see cref="MessageUpdateTimeFilter"/>.
        /// </summary>
        /// <param name="container">The container of the message.</param>
        /// <returns>The unpacked message.</returns>
        public static MessageUpdateTimeFilter Unpack(MessageContainer container)
        {
            if (container.Type != Type)
            {
                return(null);
            }

            var result = JsonConvert.DeserializeObject <MessageUpdateTimeFilter>(Encoding.UTF8.GetString(container.Payload));

            return(result);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Unpacks a <see cref="MessageContainer"/> of the type <see cref="MessageUpdateAnnotation"/>.
        /// </summary>
        /// <param name="container">The container of the message.</param>
        /// <returns>The unpacked message.</returns>
        public static MessageUpdateAnnotation Unpack(MessageContainer container)
        {
            if (container.Type != Type)
            {
                return(null);
            }

            try
            {
                var result = JsonConvert.DeserializeObject <MessageUpdateAnnotation>(Encoding.UTF8.GetString(container.Payload));
                return(result);
            }
            catch (Exception)
            {
                return(null);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Unpacks a <see cref="MessageContainer"/> of the type <see cref="MessageCreateVisualization"/>.
        /// </summary>
        /// <param name="container">The container of the message.</param>
        /// <returns>The unpacked message.</returns>
        public static MessageCreateVisualization Unpack(MessageContainer container)
        {
            if (container.Type != Type)
            {
                return(null);
            }

            var jsonSettings = new JsonSerializerSettings
            {
                TypeNameHandling = TypeNameHandling.Auto
#if UNITY_STANDALONE || UNITY_EDITOR
                , SerializationBinder = new NetworkManagerJson.CustomSerializationBinder()
#endif
            };

            string payload = Encoding.UTF8.GetString(container.Payload);
            var    result  = JsonConvert.DeserializeObject <MessageCreateVisualization>(payload, jsonSettings);

            return(result);
        }