Esempio n. 1
0
        public IOptionalMap Duplicate()
        {
            OptionalMap map = new OptionalMap {
                capacity     = this.capacity,
                readPosition = this.readPosition,
                size         = this.size
            };

            Array.Copy(this.map, 0, map.map, 0, this.map.Length);
            return(map);
        }
Esempio n. 2
0
        public static void WrapPacket(ProtocolBuffer source, StreamData dest)
        {
            BigEndianBinaryWriter writer = dest.Writer;

            writer.Write((byte)0xff);
            writer.Write((byte)0);
            OptionalMap optionalMap = (OptionalMap)source.OptionalMap;

            writer.Write(optionalMap.GetSize());
            writer.Write((int)source.Data.Length);
            byte[] map         = optionalMap.GetMap();
            int    sizeInBytes = GetSizeInBytes(optionalMap.GetSize());

            for (int i = 0; i < sizeInBytes; i++)
            {
                writer.Write(map[i]);
            }
            source.Data.CastedStream.WriteTo(dest.Stream);
        }
Esempio n. 3
0
        public static void UnwrapOptionalMap(Stream packet, ProtocolBuffer dest)
        {
            BinaryReader reader      = new BinaryReader(packet);
            byte         num         = reader.ReadByte();
            OptionalMap  optionalMap = (OptionalMap)dest.OptionalMap;

            byte[] map = optionalMap.GetMap();
            if ((num & 0x80) != 0)
            {
                int  num3;
                byte num2 = (byte)(num & 0x3f);
                if ((num & 0x40) == 0)
                {
                    num3 = num2;
                }
                else
                {
                    byte num4 = reader.ReadByte();
                    byte num5 = reader.ReadByte();
                    num3 = ((num2 << 0x10) + ((num4 & 0xff) << 8)) + (num5 & 0xff);
                }
                reader.Read(map, 0, num3);
                optionalMap.SetSize(num3 << 3);
            }
            else
            {
                byte num9;
                byte num10;
                byte num7 = (byte)(num << 3);
                switch (((num & 0x60) >> 5))
                {
                case 0:
                    map[0] = num7;
                    optionalMap.SetSize(5);
                    break;

                case 1:
                    num9   = reader.ReadByte();
                    map[0] = (byte)(num7 + (num9 >> 5));
                    map[1] = (byte)(num9 << 3);
                    optionalMap.SetSize(13);
                    break;

                case 2:
                    num9   = reader.ReadByte();
                    num10  = reader.ReadByte();
                    map[0] = (byte)(num7 + (num9 >> 5));
                    map[1] = (byte)((num9 << 3) + (num10 >> 5));
                    map[2] = (byte)(num10 << 3);
                    optionalMap.SetSize(0x15);
                    break;

                case 3:
                {
                    num9  = reader.ReadByte();
                    num10 = reader.ReadByte();
                    byte num11 = reader.ReadByte();
                    map[0] = (byte)(num7 + (num9 >> 5));
                    map[1] = (byte)((num9 << 3) + (num10 >> 5));
                    map[2] = (byte)((num10 << 3) + (num11 >> 5));
                    map[3] = (byte)(num11 << 3);
                    optionalMap.SetSize(0x1d);
                    break;
                }

                default:
                    break;
                }
            }
        }