public void Save(Stream stream) { stream.WriteUInt16((UInt16)Name.Length); stream.WriteAsciiString(Name); stream.WriteUInt8(ContainerType); stream.WriteUInt16((UInt16)Flags); stream.WriteUInt16((UInt16)Primitives.Count); stream.WriteUInt32(PackfileBaseOffset); stream.WriteUInt8(CompressionType); if (StubContainerParentName != null && StubContainerParentName != "") { stream.WriteUInt16((UInt16)StubContainerParentName.Length); stream.WriteAsciiString(StubContainerParentName); } else { stream.WriteUInt16(0); } stream.WriteInt32(AuxData.Length); stream.Write(AuxData, 0, AuxData.Length); stream.WriteInt32(TotalCompressedPackfileReadSize); foreach (WriteTimeSizes sizes in PrimitiveSizes) { stream.WriteStruct(sizes); } foreach (Primitive primitive in Primitives) { primitive.Save(stream); } }
public override void WriteToStream(Stream outputStream) { outputStream.WriteInt32(CancelRequestMessageSize); outputStream.WriteInt32(CancelRequestCode); outputStream.WriteInt32(BackendKeydata.ProcessID); outputStream.WriteInt32(BackendKeydata.SecretKey); }
public override void WriteValue(Stream stream, object value, SerializerSession session) { var data = decimal.GetBits((decimal) value); stream.WriteInt32(data[0]); stream.WriteInt32(data[1]); stream.WriteInt32(data[2]); stream.WriteInt32(data[3]); }
public void PackFull(Stream stream) { long start = stream.Position; stream.WriteInt32(1); stream.WriteInt8((byte) ID); Pack(stream); long end = stream.Position; stream.Position = start; stream.WriteInt32((int) (end - start) - 4); stream.Position = end; }
public override void WriteToStream(Stream outputStream) { NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "WriteToStream"); switch (protocolVersion) { case ProtocolVersion.Version2: // Write the size of the packet. // 4 + (passwordlength + 1) -> Int32 + NULL terminated string. // output_stream.Write(BitConverter.GetBytes(IPAddress.HostToNetworkOrder(4 + (password.Length + 1))), 0, 4); outputStream .WriteInt32(4 + password.Length + 1) .WriteBytesNullTerminated(password); break; case ProtocolVersion.Version3: outputStream .WriteBytes((Byte)ASCIIBytes.p) .WriteInt32(4 + password.Length + 1) .WriteBytesNullTerminated(password); break; } }
public override void WriteValue(Stream stream, object value, SerializerSession session) { //null = 0 // [0] //length < 255 gives length + 1 as a single byte + payload // [B length+1] [Payload] //others gives 254 + int32 length + payload // [B 254] [I Length] [Payload] if (value == null) { stream.WriteByte(0); } else { var bytes = Encoding.UTF8.GetBytes((string) value); if (bytes.Length < 255) { stream.WriteByte((byte)(bytes.Length+1)); stream.Write(bytes, 0, bytes.Length); } else { stream.WriteByte(254); stream.WriteInt32(bytes.Length); stream.Write(bytes,0,bytes.Length); } } }
public override void WriteValue(Stream stream, object value, SerializerSession session) { if (value == null) { stream.WriteInt32(-1); } else { var type = (Type) value; int existingId; if (session.Serializer.Options.PreserveObjectReferences && session.TryGetObjectId(type, out existingId)) { ObjectReferenceSerializer.Instance.WriteManifest(stream, null, session); ObjectReferenceSerializer.Instance.WriteValue(stream, existingId, session); } else { //type was not written before, add it to the tacked object list var name = type.GetShortAssemblyQualifiedName(); if (session.Serializer.Options.PreserveObjectReferences) { session.TrackSerializedObject(type); } // ReSharper disable once PossibleNullReferenceException // ReSharper disable once AssignNullToNotNullAttribute var bytes = Encoding.UTF8.GetBytes(name); stream.WriteLengthEncodedByteArray(bytes); } } }
public BlockHandle Finish(Stream output) { if (_slices.Count > 0) { GenerateFilter(); } var startPos = output.Position; var offsetInBlock = _stream.Position; _stream.Position = 0; _stream.CopyTo(output); foreach (var filterOffset in _filterOffsets) { output.WriteInt32(filterOffset); } output.WriteInt32((int)offsetInBlock); output.WriteByte(FilterBaseLg); return new BlockHandle { Position = startPos, Count = output.Position - startPos }; }
public override void WriteToStream(Stream outputStream) { outputStream.WriteByte((byte)FrontEndMessageCode.Parse); // message length = // Int32 self // name of prepared statement + 1 null string terminator + // query string + 1 null string terminator // + Int16 // + Int32 * number of parameters. Int32 messageLength = 4 + _bPrepareName.Length + 1 + _bQueryString.Length + 1 + 2 + (_parameterIDs.Length * 4); outputStream .WriteInt32(messageLength) .WriteBytesNullTerminated(_bPrepareName) .WriteBytesNullTerminated(_bQueryString) .WriteInt16((Int16)_parameterIDs.Length); for (Int32 i = 0; i < _parameterIDs.Length; i++) { outputStream.WriteInt32(_parameterIDs[i]); } outputStream.Flush(); }
public override void WriteValue(Stream stream, object value, SerializerSession session) { if (value == null) { stream.WriteInt32(-1); } else { var bytes = Encoding.UTF8.GetBytes((string) value); stream.WriteLengthEncodedByteArray(bytes); } }
public override void WriteValue(Stream stream, object arr, SerializerSession session) { var array = arr as Array; var elementSerializer = session.Serializer.GetSerializerByType(_elementType); stream.WriteInt32(array.Length); var preserveObjectReferences = session.Serializer.Options.PreserveObjectReferences; for (var i = 0; i < array.Length; i++) //write the elements { var value = array.GetValue(i); stream.WriteObject(value, _elementType, elementSerializer, preserveObjectReferences, session); } }
public override void WriteValue(Stream stream, object value, SerializerSession session) { var array = value as Array; var elementType = value.GetType().GetElementType(); var elementSerializer = session.Serializer.GetSerializerByType(elementType); elementSerializer.WriteManifest(stream, elementType, session); //write array element type stream.WriteInt32(array.Length); for (var i = 0; i < array.Length; i++) //write the elements { var elementValue = array.GetValue(i); elementSerializer.WriteValue(stream, elementValue, session); } }
public override void WriteValue(Stream stream, object value, SerializerSession session) { if (value == null) { stream.WriteInt32(-1); } else { var type = (Type) value; var name = type.AssemblyQualifiedName; var bytes = Encoding.UTF8.GetBytes(name); stream.WriteLengthEncodedByteArray(bytes); } }
private void HandleRequestHandlers(Stream stream) { string filename = stream.ReadString(); Debug.WriteLine("Exception handlers requested for: " + filename); var statements = GetHandledExceptionRanges(filename); lock (_streamLock) { stream.Write(SetExceptionHandlerInfoCommandBytes); stream.WriteString(filename); stream.WriteInt32(statements.Count); foreach (var t in statements) { stream.WriteInt32(t.Item1); stream.WriteInt32(t.Item2); foreach (var expr in t.Item3) { stream.WriteString(expr); } stream.WriteString("-"); } } }
private void SezializeSaveFile(Stream stream, SaveFile save) { var saveDataStream = new MemoryStream(); var nameTableStream = new MemoryStream(); var newSave = new SaveFile { Header = { UnkInt1 = save.Header.UnkInt1 }, SaveDataHeader = { HeaderSize = save.SaveDataHeader.HeaderSize, UnkInt2 = save.SaveDataHeader.UnkInt2 } }; newSave.SaveData = FillSaveData(); saveDataStream.SerializeObject(newSave.SaveData, newSave.NameTable.Names); nameTableStream.WriteInt32(newSave.NameTable.Names.Count); for (var i = 0; i < newSave.NameTable.Names.Count; i++) { nameTableStream.WriteString(newSave.NameTable.Names[i]); } newSave.SaveDataHeader.SaveDataSize = (int) saveDataStream.Length + 12; // 12 = SaveDataHeader size newSave.Header.FileSize = (int) saveDataStream.Length + 12 + (int) nameTableStream.Length; stream.Seek(0, SeekOrigin.Begin); // File header stream.WriteInt32(newSave.Header.UnkInt1); stream.WriteInt32(newSave.Header.FileSize); // Save data header stream.WriteInt32(newSave.SaveDataHeader.HeaderSize); stream.WriteInt32(newSave.SaveDataHeader.SaveDataSize); stream.WriteInt32(newSave.SaveDataHeader.UnkInt2); // Save data saveDataStream.WriteTo(stream); //stream.WriteInt32(255); // Name table nameTableStream.WriteTo(stream); }
public void Serialize(Stream output) { var endian = ByteOrder; const uint headerSize = 32; output.WriteUInt32(0x42424947, endian); output.WriteUInt32(Version, endian); var keys = new List<string> { "" }; var maxValueLength = 0; var blob = new StringBuilder(); foreach (var file in Files) { keys.Add(file.Name); foreach (var section in file.Sections) { keys.Add(section.Key); foreach (var value in section.Value) { keys.Add(value.Key); foreach (var item in value.Value) { if (item.Value != null) { blob.Append(item.Value + '\0'); maxValueLength = Math.Max(maxValueLength, item.Value.Length); } } } } } var huffmanEncoder = new Encoder(); huffmanEncoder.Build(blob.ToString()); keys = keys.Distinct().OrderBy(k => k.HashCrc32()).ToList(); var maxKeyLength = keys.Max(k => k.Length); uint stringTableSize; using (var data = new MemoryStream()) { data.Position = 4; data.WriteInt32(keys.Count, endian); data.Position = 4 + 4 + (8 * keys.Count); var offsets = new List<KeyValuePair<uint, uint>>(); foreach (var key in keys) { var offset = (uint) data.Position; data.WriteUInt16((ushort) key.Length, endian); data.WriteString(key, Encoding.UTF8); offsets.Add(new KeyValuePair<uint, uint>(key.HashCrc32(), offset)); } data.Position = 8; foreach (var kv in offsets) { data.WriteUInt32(kv.Key, endian); data.WriteUInt32(kv.Value - 8, endian); } data.Position = 0; data.WriteUInt32((uint) data.Length, endian); data.Position = 0; stringTableSize = (uint) data.Length; output.Seek(headerSize, SeekOrigin.Begin); output.WriteFromStream(data, data.Length); } uint huffmanSize; using (var data = new MemoryStream()) { var pairs = huffmanEncoder.GetPairs(); data.WriteUInt16((ushort) pairs.Length, endian); foreach (var pair in pairs) { data.WriteInt32(pair.Left, endian); data.WriteInt32(pair.Right, endian); } data.Position = 0; huffmanSize = (uint) data.Length; output.Seek(headerSize + stringTableSize, SeekOrigin.Begin); output.WriteFromStream(data, data.Length); } var bits = new BitArray(huffmanEncoder.TotalBits); var bitOffset = 0; uint indexSize; using (var index = new MemoryStream()) { var fileDataOffset = 2 + (Files.Count * 6); var files = new List<KeyValuePair<ushort, int>>(); foreach (var file in Files.OrderBy(f => keys.IndexOf(f.Name))) { files.Add(new KeyValuePair<ushort, int>((ushort) keys.IndexOf(file.Name), fileDataOffset)); var sectionDataOffset = 2 + (file.Sections.Count * 6); var sections = new List<KeyValuePair<ushort, int>>(); foreach (var section in file.Sections.OrderBy(s => keys.IndexOf(s.Key))) { sections.Add(new KeyValuePair<ushort, int>((ushort) keys.IndexOf(section.Key), sectionDataOffset)); var valueDataOffset = 2 + (section.Value.Count * 6); var values = new List<KeyValuePair<ushort, int>>(); foreach (var value in section.Value.OrderBy(v => keys.IndexOf(v.Key))) { index.Position = fileDataOffset + sectionDataOffset + valueDataOffset; values.Add(new KeyValuePair<ushort, int>((ushort) keys.IndexOf(value.Key), valueDataOffset)); index.WriteUInt16((ushort) value.Value.Count, endian); valueDataOffset += 2; foreach (var item in value.Value) { switch (item.Type) { case -1: { continue; } case 1: { index.WriteInt32((1 << 29) | bitOffset, endian); break; } case 0: case 2: case 3: case 4: { var type = item.Type; if (OverrideCompileValueTypes >= 0) { type = OverrideCompileValueTypes; } index.WriteInt32((type << 29) | bitOffset, endian); bitOffset += huffmanEncoder.Encode((item.Value ?? "") + '\0', bits, bitOffset); break; } } valueDataOffset += 4; } } index.Position = fileDataOffset + sectionDataOffset; index.WriteUInt16((ushort) values.Count, endian); sectionDataOffset += 2; foreach (var value in values) { index.WriteUInt16(value.Key, endian); index.WriteInt32(value.Value, endian); sectionDataOffset += 6; } sectionDataOffset += valueDataOffset; } index.Position = fileDataOffset; index.WriteUInt16((ushort) sections.Count, endian); fileDataOffset += 2; foreach (var section in sections) { index.WriteUInt16(section.Key, endian); index.WriteInt32(section.Value, endian); fileDataOffset += 6; } fileDataOffset += sectionDataOffset; } index.Position = 0; index.WriteUInt16((ushort) files.Count, endian); foreach (var file in files) { index.WriteUInt16(file.Key, endian); index.WriteInt32(file.Value, endian); } index.Position = 0; indexSize = (uint) index.Length; output.Seek(headerSize + stringTableSize + huffmanSize, SeekOrigin.Begin); output.WriteFromStream(index, index.Length); } output.Seek(headerSize + stringTableSize + huffmanSize + indexSize, SeekOrigin.Begin); output.WriteInt32(bits.Length, endian); var bytes = new byte[(bits.Length - 1) / 8 + 1]; bits.CopyTo(bytes, 0); output.WriteBytes(bytes); output.Seek(8, SeekOrigin.Begin); output.WriteInt32(maxKeyLength, endian); output.WriteInt32(maxValueLength, endian); output.WriteUInt32(stringTableSize, endian); output.WriteUInt32(huffmanSize, endian); output.WriteUInt32(indexSize, endian); output.WriteInt32(bytes.Length, endian); output.Seek(0, SeekOrigin.Begin); output.WriteUInt32(0x666D726D, endian); }
public override void WriteToStream(Stream outputStream) { NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "WriteToStream"); int packet_size = 4 + 4 + 1; for (int i = 0; i < parameterNames.Count; i++) { packet_size += (parameterNames[i].Length + parameterValues[i].Length + 2); } outputStream.WriteInt32(packet_size); outputStream.WriteInt32(PGUtil.ConvertProtocolVersion(this.protocol_version)); for (int i = 0; i < parameterNames.Count; i++) { outputStream.WriteBytesNullTerminated(parameterNames[i]); outputStream.WriteBytesNullTerminated(parameterValues[i]); } outputStream.WriteByte(0); outputStream.Flush(); }
public override void WriteToStream(Stream outputStream) { NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "WriteToStream"); // Packet length = 296 outputStream .WriteInt32(296) .WriteInt32(PGUtil.ConvertProtocolVersion(this.protocol_version)) .WriteLimBytes(database_name, 64) .WriteLimBytes(user_name, 32) .WriteLimBytes(arguments, 64) .WriteLimBytes(unused, 64) .WriteLimBytes(optional_tty, 64) .Flush(); }
public static void Write(object obj, Stream stream) { stream.WriteInt32((Int32)obj); }
public override void WriteToStream(Stream outputStream) { if (_messageLength == 0) { _messageLength = 4 + // Message length (32 bits) _bPortalName.Length + 1 + // Portal name + null terminator _bPreparedStatementName.Length + 1 + // Statement name + null terminator 2 + // Parameter format code array length (16 bits) _parameterFormatCodes.Length * 2 + // Parameter format code array (16 bits per code) 2; // Parameter va;ue array length (16 bits) if (_parameterValues != null) { for (int i = 0; i < _parameterValues.Length; i++) { _messageLength += 4; // Parameter value length (32 bits) if (_parameterValues[i] != null) { _messageLength += _parameterValues[i].Length; // Parameter value } } } _messageLength += 2 + // Result format code array length (16 bits) _resultFormatCodes.Length * 2; // Result format code array (16 bits per code) } outputStream .WriteBytes((byte)FrontEndMessageCode.Bind) .WriteInt32(_messageLength) .WriteBytesNullTerminated(_bPortalName) .WriteBytesNullTerminated(_bPreparedStatementName) .WriteInt16((Int16)_parameterFormatCodes.Length); foreach (short code in _parameterFormatCodes) { outputStream.WriteInt16(code); } if (_parameterValues != null) { outputStream.WriteInt16((Int16)_parameterValues.Length); for (int i = 0 ; i < _parameterValues.Length ; i++) { Byte[] parameterValue = _parameterValues[i]; if (parameterValue == null) { outputStream.WriteInt32(-1); } else { outputStream .WriteInt32(parameterValue.Length) .WriteBytes(parameterValue); } } } else { outputStream.WriteInt16(0); } outputStream.WriteInt16((Int16)_resultFormatCodes.Length); foreach (short code in _resultFormatCodes) { outputStream.WriteInt16(code); } }
public override void Pack(Stream stream) { stream.WriteInt32(Time); stream.WriteBoolean(DayTime); stream.WriteInt8(MoonPhase); stream.WriteBoolean(BloodMoon); stream.WriteInt32(MaxTilesX); stream.WriteInt32(MaxTilesY); stream.WriteInt32(SpawnX); stream.WriteInt32(SpawnY); stream.WriteInt32(WorldSurface); stream.WriteInt32(RockLayer); stream.WriteInt32(WorldID); stream.WriteInt8((byte) WorldFlags); stream.WriteBytes(Encoding.UTF8.GetBytes(WorldName)); }
public override void WriteToStream(Stream output_stream) { int packet_size = 4 + 4 + 1; for (int i = 0; i < parameterNames.Count; i++) { packet_size += (parameterNames[i].Length + parameterValues[i].Length + 2); } output_stream .WriteInt32(packet_size) .WriteInt32(PGUtil.ConvertProtocolVersion(ProtocolVersion.Version3)); for (int i = 0; i < parameterNames.Count; i++) { output_stream .WriteBytesNullTerminated(parameterNames[i]) .WriteBytesNullTerminated(parameterValues[i]); } output_stream.WriteByte(0); }
public override void WriteValue(Stream stream, object value, SerializerSession session) { stream.WriteInt32((int) value); }
private PythonProcess(Stream stream, int pid, PythonLanguageVersion version, PythonDebugOptions debugOptions) { _pid = pid; _process = Process.GetProcessById(pid); _process.EnableRaisingEvents = true; _process.Exited += new EventHandler(_process_Exited); _delayUnregister = true; ListenForConnection(); stream.WriteInt32(DebugConnectionListener.ListenerPort); stream.WriteString(_processGuid.ToString()); stream.WriteString(debugOptions.ToString()); }
/// <summary> /// This sends this argument down the network stream. /// The stream sent consists of the length.int4 then the contents. /// Note: This is called from Fastpath, and cannot be called from /// client code. /// </summary> /// <param name="s"></param> internal void Send(Stream s) { if (type) { // argument is an integer s.WriteInt32(4); s.WriteInt32(value); // integer value of argument } else { // argument is a byte array s.WriteInt32(bytes.Length); s.Write(bytes, 0, bytes.Length); } }
public void Pack(Stream stream) { stream.WriteInt8(Field6); stream.WriteInt16(Field7); stream.WriteInt32(Field8); stream.WriteBytes(Field9); stream.WriteString(Field10); }
public override void Pack(Stream stream) { stream.WriteInt32(Time); stream.WriteBoolean(DayTime); stream.WriteInt8(MoonPhase); stream.WriteBoolean(BloodMoon); stream.WriteBoolean(Eclipse); stream.WriteInt32(MaxTilesX); stream.WriteInt32(MaxTilesY); stream.WriteInt32(SpawnX); stream.WriteInt32(SpawnY); stream.WriteInt32(WorldSurface); stream.WriteInt32(RockLayer); stream.WriteInt32(WorldID); stream.WriteByte(MoonType); stream.WriteInt32(TreeX0); stream.WriteInt32(TreeX1); stream.WriteInt32(TreeX2); stream.WriteByte(TreeStyle0); stream.WriteByte(TreeStyle1); stream.WriteByte(TreeStyle2); stream.WriteByte(TreeStyle3); stream.WriteInt32(CaveBackX0); stream.WriteInt32(CaveBackX1); stream.WriteInt32(CaveBackX2); stream.WriteByte(CaveBackStyle0); stream.WriteByte(CaveBackStyle1); stream.WriteByte(CaveBackStyle2); stream.WriteByte(CaveBackStyle3); stream.WriteByte(SetBG0); stream.WriteByte(SetBG1); stream.WriteByte(SetBG2); stream.WriteByte(SetBG3); stream.WriteByte(SetBG4); stream.WriteByte(SetBG5); stream.WriteByte(SetBG6); stream.WriteByte(SetBG7); stream.WriteByte(IceBackStyle); stream.WriteByte(JungleBackStyle); stream.WriteByte(HellBackStyle); stream.WriteSingle(WindSpeed); stream.WriteByte(NumberOfClouds); stream.WriteInt8((byte)BossFlags); stream.WriteInt8((byte)BossFlags2); stream.WriteSingle(Rain); stream.WriteBytes(Encoding.UTF8.GetBytes(WorldName)); }