public MessageColor Deserialize(byte[] serializedData)
        {
            serializedData.ThrowIfNull("serializedData");

            var serializer = new CompactSerializer(serializedData);
            Color color = ColorSerializer.Instance.Deserialize(serializer[0]);

            return new MessageColor(color);
        }
        public byte[] Seralize(Size size)
        {
            var serializer = new CompactSerializer();

            serializer[0] = BitConverter.GetBytes(size.Width);
            serializer[1] = BitConverter.GetBytes(size.Height);

            return serializer.Serialize();
        }
        public byte[] Serialize(Coordinate coordinate)
        {
            var serializer = new CompactSerializer();

            serializer[0] = BitConverter.GetBytes(coordinate.X);
            serializer[1] = BitConverter.GetBytes(coordinate.Y);

            return serializer.Serialize();
        }
        public MessageText Deserialize(byte[] serializedData)
        {
            serializedData.ThrowIfNull("serializedData");

            var serializer = new CompactSerializer(serializedData);
            string text = Encoding.UTF8.GetString(serializer[0]);

            return new MessageText(text);
        }
        public byte[] Serialize(MessageText messageText)
        {
            messageText.ThrowIfNull("messageText");

            var serializer = new CompactSerializer();

            serializer[0] = Encoding.UTF8.GetBytes(messageText.Text);

            return serializer.Serialize();
        }
        public Size Deserialize(byte[] serializedData)
        {
            serializedData.ThrowIfNull("serializedData");

            var serializer = new CompactSerializer(serializedData);
            int width = BitConverter.ToInt32(serializer[0], 0);
            int height = BitConverter.ToInt32(serializer[1], 0);

            return new Size(width, height);
        }
        public Sprite Deserialize(byte[] serializedData)
        {
            serializedData.ThrowIfNull("serializedData");

            var serializer = new CompactSerializer(serializedData);
            Coordinate coordinate = CoordinateSerializer.Instance.Deserialize(serializer[0]);
            Character character = CharacterSerializer.Instance.Deserialize(serializer[1]);

            return new Sprite(coordinate, character);
        }
        public byte[] Serialize(MessageColor messageColor)
        {
            messageColor.ThrowIfNull("messageColor");

            var serializer = new CompactSerializer();

            serializer[0] = ColorSerializer.Instance.Serialize(messageColor.Color);

            return serializer.Serialize();
        }
        public Coordinate Deserialize(byte[] serializedData)
        {
            serializedData.ThrowIfNull("serializedData");

            var serializer = new CompactSerializer(serializedData);
            int x = BitConverter.ToInt32(serializer[0], 0);
            int y = BitConverter.ToInt32(serializer[1], 0);

            return new Coordinate(x, y);
        }
        public byte[] Serialize(Character character)
        {
            var serializer = new CompactSerializer();

            serializer[0] = new[] { character.Symbol };
            serializer[1] = ColorSerializer.Instance.Serialize(character.ForegroundColor);
            serializer[2] = ColorSerializer.Instance.Serialize(character.BackgroundColor);

            return serializer.Serialize();
        }
        public byte[] Serialize(Sprite sprite)
        {
            sprite.ThrowIfNull("sprite");

            var serializer = new CompactSerializer();

            serializer[0] = CoordinateSerializer.Instance.Serialize(sprite.Coordinate);
            serializer[1] = CharacterSerializer.Instance.Serialize(sprite.Character);

            return serializer.Serialize();
        }
예제 #12
0
        public byte[] Serialize(Color color)
        {
            var serializer = new CompactSerializer();

            serializer[0] = BitConverter.GetBytes(color.R);
            serializer[1] = BitConverter.GetBytes(color.G);
            serializer[2] = BitConverter.GetBytes(color.B);
            serializer[3] = BitConverter.GetBytes(color.A);

            return serializer.Serialize();
        }
        public Character Deserialize(byte[] serializedData)
        {
            serializedData.ThrowIfNull("serializedData");

            var serializer = new CompactSerializer(serializedData);
            byte symbol = serializer[0][0];
            Color foregroundColor = ColorSerializer.Instance.Deserialize(serializer[1]);
            Color backgroundColor = ColorSerializer.Instance.Deserialize(serializer[2]);

            return new Character(symbol, foregroundColor, backgroundColor);
        }
예제 #14
0
        public BoardExit Deserialize(byte[] serializedData)
        {
            serializedData.ThrowIfNull("serializedData");

            var serializer = new CompactSerializer(serializedData);
            Coordinate coordinate = CoordinateSerializer.Instance.Deserialize(serializer[0]);
            BoardExitDirection direction = Enum<BoardExitDirection>.Parse(Encoding.UTF8.GetString(serializer[1]));
            var destinationBoardId = new Guid(serializer[2]);
            Coordinate destinationCoordinate = CoordinateSerializer.Instance.Deserialize(serializer[3]);

            return new BoardExit(coordinate, direction, destinationBoardId, destinationCoordinate);
        }
예제 #15
0
        public Actor Deserialize(byte[] serializedData)
        {
            serializedData.ThrowIfNull("serializedData");

            var serializer = new CompactSerializer(serializedData);
            var id = new Guid(serializer[0]);
            string name = Encoding.UTF8.GetString(serializer[1]);
            string description = Encoding.UTF8.GetString(serializer[2]);
            Character character = CharacterSerializer.Instance.Deserialize(serializer[3]);

            return new Actor(id, name, description, character);
        }
예제 #16
0
        public Song Deserialize(byte[] serializedData)
        {
            serializedData.ThrowIfNull("serializedData");

            var serializer = new CompactSerializer(serializedData);
            var id = new Guid(serializer[0]);
            string name = Encoding.UTF8.GetString(serializer[1]);
            string description = Encoding.UTF8.GetString(serializer[2]);
            byte[] data = serializer[3];

            return new Song(id, name, description, data);
        }
예제 #17
0
        public Color Deserialize(byte[] serializedData)
        {
            serializedData.ThrowIfNull("serializedData");

            var serializer = new CompactSerializer(serializedData);
            float r = BitConverter.ToSingle(serializer[0], 0);
            float g = BitConverter.ToSingle(serializer[1], 0);
            float b = BitConverter.ToSingle(serializer[2], 0);
            float a = BitConverter.ToSingle(serializer[3], 0);

            return new Color(r, g, b, a);
        }
        public SpriteLayer Deserialize(byte[] serializedData)
        {
            serializedData.ThrowIfNull("serializedData");

            var serializer = new CompactSerializer(serializedData);
            var boardId = new Guid(serializer[0]);
            Size size = SizeSerializer.Instance.Deserialize(serializer[1]);
            var spriteSerializer = new CompactSerializer(serializer[2]);
            IEnumerable<Sprite> sprites = spriteSerializer.FieldIndices.Select(arg => SpriteSerializer.Instance.Deserialize(spriteSerializer[arg]));

            return new SpriteLayer(boardId, size, sprites);
        }
        public ActorInstanceLayer Deserialize(byte[] serializedData)
        {
            serializedData.ThrowIfNull("serializedData");

            var serializer = new CompactSerializer(serializedData);
            var boardId = new Guid(serializer[0]);
            Size size = SizeSerializer.Instance.Deserialize(serializer[1]);
            var actorInstanceSerializer = new CompactSerializer(serializer[2]);
            IEnumerable<ActorInstance> actorInstances = actorInstanceSerializer.FieldIndices.Select(arg => ActorInstanceSerializer.Instance.Deserialize(actorInstanceSerializer[arg]));

            return new ActorInstanceLayer(boardId, size, actorInstances);
        }
예제 #20
0
        public byte[] Serialize(Actor actor)
        {
            actor.ThrowIfNull("actor");

            var serializer = new CompactSerializer();

            serializer[0] = actor.Id.ToByteArray();
            serializer[1] = Encoding.UTF8.GetBytes(actor.Name);
            serializer[2] = Encoding.UTF8.GetBytes(actor.Description);
            serializer[3] = CharacterSerializer.Instance.Serialize(actor.Character);

            return serializer.Serialize();
        }
        public MessageAnswer Deserialize(byte[] serializedData)
        {
            serializedData.ThrowIfNull("serializedData");

            var serializer = new CompactSerializer(serializedData);
            var id = new Guid(serializer[0]);
            string text = Encoding.UTF8.GetString(serializer[1]);
            var partSerializer = new CompactSerializer(serializer[2]);
            IEnumerable<IMessagePart> parts = partSerializer.FieldIndices.Select(arg => MessagePartSerializer.Instance.Deserialize(partSerializer[arg]));
            EventHandlerCollection eventHandlerCollection = EventHandlerCollectionSerializer.Instance.Deserialize(serializer[3]);

            return new MessageAnswer(id, text, parts, eventHandlerCollection);
        }
예제 #22
0
        public byte[] Serialize(BoardExit boardExit)
        {
            boardExit.ThrowIfNull("boardExit");

            var serializer = new CompactSerializer();

            serializer[0] = CoordinateSerializer.Instance.Serialize(boardExit.Coordinate);
            serializer[1] = Encoding.UTF8.GetBytes(boardExit.Direction.ToString());
            serializer[2] = boardExit.DestinationBoardId.ToByteArray();
            serializer[3] = CoordinateSerializer.Instance.Serialize(boardExit.DestinationCoordinate);

            return serializer.Serialize();
        }
예제 #23
0
        public byte[] Serialize(Song song)
        {
            song.ThrowIfNull("song");

            var serializer = new CompactSerializer();

            serializer[0] = song.Id.ToByteArray();
            serializer[1] = Encoding.UTF8.GetBytes(song.Name);
            serializer[2] = Encoding.UTF8.GetBytes(song.Description);
            serializer[3] = song.Data;

            return serializer.Serialize();
        }
예제 #24
0
        public Player Deserialize(byte[] serializedData)
        {
            serializedData.ThrowIfNull("serializedData");

            var serializer = new CompactSerializer(serializedData);
            var id = new Guid(serializer[0]);
            var boardId = new Guid(serializer[1]);
            Coordinate coordinate = CoordinateSerializer.Instance.Deserialize(serializer[2]);
            Character character = CharacterSerializer.Instance.Deserialize(serializer[3]);
            EventHandlerCollection eventHandlerCollection = EventHandlerCollectionSerializer.Instance.Deserialize(serializer[4]);

            return new Player(id, boardId, coordinate, character, eventHandlerCollection);
        }
예제 #25
0
        public byte[] Serialize(Player player)
        {
            player.ThrowIfNull("player");

            var serializer = new CompactSerializer();

            serializer[0] = player.Id.ToByteArray();
            serializer[1] = player.BoardId.ToByteArray();
            serializer[2] = CoordinateSerializer.Instance.Serialize(player.Coordinate);
            serializer[3] = CharacterSerializer.Instance.Serialize(player.Character);
            serializer[4] = EventHandlerCollectionSerializer.Instance.Serialize(player.EventHandlerCollection);

            return serializer.Serialize();
        }
        public Message Deserialize(byte[] serializedData)
        {
            serializedData.ThrowIfNull("serializedData");

            var serializer = new CompactSerializer(serializedData);
            var id = new Guid(serializer[0]);
            string name = Encoding.UTF8.GetString(serializer[1]);
            string description = Encoding.UTF8.GetString(serializer[2]);
            Color backgroundColor = ColorSerializer.Instance.Deserialize(serializer[3]);
            var partSerializer = new CompactSerializer(serializer[4]);
            IEnumerable<IMessagePart> parts = partSerializer.FieldIndices.Select(arg => MessagePartSerializer.Instance.Deserialize(partSerializer[arg]));

            return new Message(id, name, description, backgroundColor, parts);
        }
        public byte[] Serialize(EventHandlerCollection eventHandlerCollection)
        {
            var serializer = new CompactSerializer();
            int index = 0;

            if (eventHandlerCollection != null)
            {
                foreach (IEventHandler eventHandler in eventHandlerCollection.EventHandlers)
                {
                    serializer[index++] = Encoding.ASCII.GetBytes(eventHandler.EventHandlerTypeName);
                }
            }

            return serializer.Serialize();
        }
        public Timer Deserialize(byte[] serializedData)
        {
            serializedData.ThrowIfNull("serializedData");

            var serializer = new CompactSerializer(serializedData);
            var id = new Guid(serializer[0]);
            string name = Encoding.UTF8.GetString(serializer[1]);
            string description = Encoding.UTF8.GetString(serializer[2]);
            TimeSpan interval = TimeSpan.FromTicks(BitConverter.ToInt64(serializer[3], 0));
            TimerState state = Enum<TimerState>.Parse(Encoding.UTF8.GetString(serializer[4]));
            TimeSpan elapsedTime = TimeSpan.FromTicks(BitConverter.ToInt64(serializer[5], 0));
            EventHandlerCollection eventHandlerCollection = EventHandlerCollectionSerializer.Instance.Deserialize(serializer[6]);

            return new Timer(id, name, description, interval, state, elapsedTime, eventHandlerCollection);
        }
        public MessageQuestion Deserialize(byte[] serializedData)
        {
            serializedData.ThrowIfNull("serializedData");

            var serializer = new CompactSerializer(serializedData);
            string prompt = Encoding.UTF8.GetString(serializer[0]);
            Color questionForegroundColor = ColorSerializer.Instance.Deserialize(serializer[1]);
            Color unselectedAnswerForegroundColor = ColorSerializer.Instance.Deserialize(serializer[2]);
            Color selectedAnswerForegroundColor = ColorSerializer.Instance.Deserialize(serializer[3]);
            Color selectedAnswerBackgroundColor = ColorSerializer.Instance.Deserialize(serializer[4]);
            var answerSerializer = new CompactSerializer(serializer[5]);
            IEnumerable<MessageAnswer> answers = answerSerializer.FieldIndices.Select(arg => MessageAnswerSerializer.Instance.Deserialize(answerSerializer[arg]));

            return new MessageQuestion(prompt, questionForegroundColor, unselectedAnswerForegroundColor, selectedAnswerForegroundColor, selectedAnswerBackgroundColor, answers);
        }
        public ActorInstance Deserialize(byte[] serializedData)
        {
            serializedData.ThrowIfNull("serializedData");

            var serializer = new CompactSerializer(serializedData);
            var id = new Guid(serializer[0]);
            string name = Encoding.UTF8.GetString(serializer[1]);
            string description = Encoding.UTF8.GetString(serializer[2]);
            var actorId = new Guid(serializer[3]);
            var boardId = new Guid(serializer[4]);
            Coordinate coordinate = CoordinateSerializer.Instance.Deserialize(serializer[5]);
            Character character = CharacterSerializer.Instance.Deserialize(serializer[6]);
            EventHandlerCollection eventHandlers = EventHandlerCollectionSerializer.Instance.Deserialize(serializer[7]);

            return new ActorInstance(id, name, description, actorId, boardId, coordinate, character, eventHandlers);
        }