コード例 #1
0
        public static RollMessage Decode(byte[] bytes)
        {
            RollMessage message = null;

            if (bytes != null)
            {
                message = new RollMessage();

                MemoryStream memoryStream = new MemoryStream(bytes);

                message.msgId  = ReadMessageId(memoryStream);
                message.convId = ReadMessageId(memoryStream);
                ReadShort(memoryStream);
                message.GameId = ReadShort(memoryStream);
                message.Roll   = ReadShort(memoryStream);
            }

            return(message);
        }
コード例 #2
0
        public static Message DecodeMessage(byte[] messageByteStream)
        {
            MemoryStream memoryStream = new MemoryStream(messageByteStream);
            Message      message      = null;

            ReadMessageId(memoryStream);
            ReadMessageId(memoryStream);

            short messageType = ReadShort(memoryStream);

            try
            {
                switch (messageType)
                {
                case REQUEST_GAME:
                    message = RequestGameMessage.Decode(messageByteStream);
                    break;

                case GAME_INFO:
                    message = GameInfoMessage.Decode(messageByteStream);
                    break;

                case START_GAME:
                    message = StartGameMessage.Decode(messageByteStream);
                    break;

                case GAME_STATE_UPDATE:
                    message = GameStateUpdateMessage.Decode(messageByteStream);
                    break;

                case ROLL:
                    message = RollMessage.Decode(messageByteStream);
                    break;

                case TRADE_REQUEST:
                    message = TradeRequestMessage.Decode(messageByteStream);
                    break;

                case TRADE_REPLY:
                    message = TradeReplyMessage.Decode(messageByteStream);
                    break;

                case BUY:
                    message = BuyMessage.Decode(messageByteStream);
                    break;

                case END_TURN:
                    message = EndTurnMessage.Decode(messageByteStream);
                    break;

                case END_GAME:
                    message = EndGameMessage.Decode(messageByteStream);
                    break;

                case ACK:
                    message = AckMessage.Decode(messageByteStream);
                    break;

                case ERROR:
                    message = ErrorMessage.Decode(messageByteStream);
                    break;

                default:

                    break;
                }

                return(message);
            }
            catch
            {
                return(null);
            }
        }