Exemplo n.º 1
0
        public FstDataPacket Decode(FstPacket packet)
        {
            var reader = new BinaryReader(new MemoryStream(packet.Data));

            reader.ReadByte();

            var versionLength = reader.ReadByte();
            var version       = Encoders.Ascii.GetString(reader.ReadBytes(versionLength - 1));

            reader.ReadByte();

            reader.ReadBytes(3);

            var pluginIdLength = reader.ReadByte();
            var pluginId       = Encoders.Utf16.GetString(reader.ReadBytes(pluginIdLength - 2));

            reader.ReadBytes(2);

            var dataOffset = (int)reader.BaseStream.Position;
            var data       = reader.ReadBytes(packet.Data.Length - (int)reader.BaseStream.Position);

            return(new FstDataPacket
            {
                Version = version,
                PluginId = pluginId,
                PluginData = data,
                PluginDataOffset = dataOffset
            });
        }
Exemplo n.º 2
0
        public int Write(Stream stream, FstPacket packet)
        {
            var writer = new BinaryWriter(stream);
            var id     = Encoders.Ascii.GetBytes(packet.Id);

            writer.Write(id);
            writer.Write(packet.Data.Length);
            writer.Write(packet.Data);
            return(id.Length + packet.Data.Length + 4);
        }