コード例 #1
0
        public static Packet Parse(KaitaiStream input, IParameterManager manager)
        {
            // get command
            var command = (RcpTypes.Command)input.ReadU1();

            if (!Enum.IsDefined(typeof(RcpTypes.Command), command))
            {
                throw new RCPDataErrorException("Packed parsing: Unknown command: " + command.ToString());
            }

            var packet = new Packet(command);

            // read packet options
            while (!input.IsEof)
            {
                var code = input.ReadU1();
                if (code == 0) // terminator
                {
                    break;
                }

                var option = (RcpTypes.PacketOptions)code;
                if (!Enum.IsDefined(typeof(RcpTypes.PacketOptions), option))
                {
                    throw new RCPDataErrorException("Packet parsing: Unknown option: " + option.ToString());
                }

                switch (option)
                {
                case RcpTypes.PacketOptions.Data:
                    switch (command)
                    {
//	                        case RcpTypes.Command.Initialize:
//	                            // init - should not happen
//	                            throw new RCPDataErrorException();

                    case RcpTypes.Command.Remove:
                    case RcpTypes.Command.Update:
                        // expect parameter
                        packet.Data = Parameter.Parse(input, manager);
                        break;

                    case RcpTypes.Command.Version:
                        packet.Data = new RcpTypes.TinyString(input);
                        break;
                    }

                    break;

                case RcpTypes.PacketOptions.Timestamp:
                    packet.Timestamp = input.ReadU8be();
                    break;

                default:
                    throw new RCPUnsupportedFeatureException();
                }
            }

            return(packet);
        }
コード例 #2
0
        public override Color ReadValue(KaitaiStream input)
        {
            var b = input.ReadU1();
            var g = input.ReadU1();
            var r = input.ReadU1();
            var a = input.ReadU1(); // Server send alpha?

            return(new Color(r, g, b, 255));
        }
コード例 #3
0
        public override Color ReadValue(KaitaiStream input)
        {
            var a = input.ReadU1();
            var b = input.ReadU1();
            var g = input.ReadU1();
            var r = input.ReadU1();

            return(new Color(r, g, b, a));
        }
コード例 #4
0
 public override void ParseOptions(KaitaiStream input)
 {
     //read terminator
     input.ReadU1();
     //execute bang
     OnBang?.Invoke();
 }
コード例 #5
0
        public virtual void ParseOptions(KaitaiStream input)
        {
            while (true)
            {
                var code = input.ReadU1();
                if (code == 0) // terminator
                {
                    break;
                }

                // handle option in specific implementation
                if (!HandleOption(input, code))
                {
                    throw new RCPUnsupportedFeatureException();
                }
            }
        }
コード例 #6
0
 public override bool ReadValue(KaitaiStream input)
 {
     return(input.ReadU1() > 0);
 }
コード例 #7
0
 public override byte ReadValue(KaitaiStream input)
 {
     return(input.ReadU1());
 }