protected override void EncodeInternal(BinaryWriter output) { output.WriteOpcode(MarshalOpcode.SubStream); var tempMs = new MemoryStream(); var temp = new BinaryWriter(tempMs); temp.Write((byte)0x7E); temp.Write((uint)0); Data.Encode(temp); output.WriteSizeEx((uint)tempMs.Length); output.Write(tempMs.ToArray()); }
protected override void EncodeInternal(BinaryWriter output) { output.WriteOpcode(MarshalOpcode.SubStream); var memoryStream = new MemoryStream(); var binaryWriter = new BinaryWriter(memoryStream); binaryWriter.Write(Marshal.Process(Data)); output.WriteSizeEx((uint)memoryStream.Length); output.Write(memoryStream.ToArray()); }
protected override void EncodeInternal(BinaryWriter output) { output.WriteOpcode(MarshalOpcode.IntegerVar); output.WriteSizeEx(Raw.Length); output.Write(Raw); }
protected override void EncodeInternal(BinaryWriter output) { output.WriteOpcode(MarshalOpcode.Buffer); output.WriteSizeEx(Data.Length); output.Write(Data); }
public static void ZeroCompress(BinaryReader reader, MemoryStream stream, BinaryWriter output) { MemoryStream newStream = new MemoryStream(); BinaryWriter newWriter = new BinaryWriter(newStream); byte b = reader.ReadByte(); while(stream.Position < stream.Length) { ZeroCompressOpcode opcode = new ZeroCompressOpcode(0); int opcodeStartShift = 1; // Reserve space for opcode newWriter.Write(opcode.Value); if (b == 0x00) { opcode.FirstIsZero = true; int firstLen = -1; while ((b == 0x00) && (firstLen < 7) && (stream.Position < stream.Length)) { firstLen++; b = reader.ReadByte(); } opcode.FirstLength = (byte)(firstLen); } else { opcode.FirstIsZero = false; opcode.FirstLength = 8; while ((b != 0x00) && (opcode.FirstLength > 0)) { opcode.FirstLength--; opcodeStartShift++; newWriter.Write(b); if (stream.Position < stream.Length) { b = reader.ReadByte(); } else { break; } } } if (stream.Position == stream.Length) { opcode.SecondIsZero = true; opcode.SecondLength = 0; } else if (b == 0x00) { opcode.SecondIsZero = true; int secondLength = -1; while ((b == 0x00) && (opcode.SecondLength < 7) && (stream.Position < stream.Length)) { secondLength++; b = reader.ReadByte(); } opcode.SecondLength = (byte)(secondLength); } else { opcode.SecondIsZero = false; opcode.SecondLength = 8; while ((b != 0x00) && (opcode.SecondLength > 0)) { opcode.SecondLength--; opcodeStartShift++; newWriter.Write(b); if (stream.Position < stream.Length) { b = reader.ReadByte(); } else { break; } } } newWriter.Seek(-opcodeStartShift, SeekOrigin.Current); newWriter.Write(opcode.Value); newWriter.Seek(opcodeStartShift - 1, SeekOrigin.Current); } output.WriteSizeEx((int)(newStream.Length)); if(newStream.Length > 0) { output.Write(newStream.ToArray()); } }
protected override void EncodeInternal(BinaryWriter output) { if (ForceUTF8) { output.WriteOpcode(MarshalOpcode.WStringUTF8); output.WriteSizeEx(Raw.Length); output.Write(Raw); return; } int idx; if (Raw.Length == 0) output.WriteOpcode(MarshalOpcode.StringEmpty); else if (Raw.Length == 1) { output.WriteOpcode(MarshalOpcode.StringChar); output.Write(Raw[0]); } else if ((idx = StringTable.Entries.IndexOf(Value)) >= 0) { output.WriteOpcode(MarshalOpcode.StringTable); output.Write((byte)(idx+1)); } else { /*if (Raw.Length < 0xFF) { output.WriteOpcode(MarshalOpcode.StringShort); output.Write((byte)Raw.Length); output.Write(Raw); } else*/ { output.WriteOpcode(MarshalOpcode.StringLong); output.WriteSizeEx(Raw.Length); output.Write(Raw); } } }
protected override void EncodeInternal(BinaryWriter output) { output.WriteOpcode(MarshalOpcode.Dict); output.WriteSizeEx(Dictionary.Count); foreach (var pair in Dictionary) { pair.Value.Encode(output); pair.Key.Encode(output); } }