Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        public static bool UnwrapPacket(StreamData source, ProtocolBuffer dest)
        {
            BigEndianBinaryReader reader = source.Reader;
            long num      = source.Length - source.Position;
            long position = source.Position;

            if (num < 10)
            {
                return(false);
            }
            if (reader.ReadByte() != 0xff)
            {
                throw new CorruptBufferException();
            }
            if (reader.ReadByte() != 0)
            {
                throw new CorruptBufferException();
            }
            int size        = reader.ReadInt32();
            int num6        = reader.ReadInt32();
            int sizeInBytes = GetSizeInBytes(size);

            if (num < ((sizeInBytes + num6) + 10))
            {
                source.Position = position;
                return(false);
            }
            UpdatePackeHelperBuffer(sizeInBytes);
            source.Read(packetHelperBuffer, 0, sizeInBytes);
            packetHelperOptionalMap.Fill(packetHelperBuffer, size);
            dest.OptionalMap.Concat(packetHelperOptionalMap);
            UpdatePackeHelperBuffer(num6);
            source.Read(packetHelperBuffer, 0, num6);
            dest.Data.Write(packetHelperBuffer, 0, num6);
            dest.Flip();
            return(true);
        }
Exemplo n.º 3
0
 public void WrapPacket(ProtocolBuffer source, StreamData dest)
 {
     PacketHelper.WrapPacket(source, dest);
 }
Exemplo n.º 4
0
 public bool UnwrapPacket(StreamData source, ProtocolBuffer dest) =>
 PacketHelper.UnwrapPacket(source, dest);