Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename Write methods to indicate the type #1321

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 58 additions & 58 deletions src/FastSerialization/FastSerialization.cs

Large diffs are not rendered by default.

32 changes: 16 additions & 16 deletions src/FastSerialization/StreamReaderWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public virtual MemoryStreamReader GetReader()
/// <summary>
/// Implementation of IStreamWriter
/// </summary>
public void Write(byte value)
public void WriteByte(byte value)
{
if (endPosition >= bytes.Length)
{
Expand All @@ -274,7 +274,7 @@ public void Write(byte value)
/// <summary>
/// Implementation of IStreamWriter
/// </summary>
public unsafe void Write(short value)
public unsafe void WriteInt16(short value)
{
if (endPosition + sizeof(short) > bytes.Length)
{
Expand All @@ -291,7 +291,7 @@ public unsafe void Write(short value)
/// <summary>
/// Implementation of IStreamWriter
/// </summary>
public unsafe void Write(int value)
public unsafe void WriteInt32(int value)
{
if (endPosition + sizeof(int) > bytes.Length)
{
Expand All @@ -308,7 +308,7 @@ public unsafe void Write(int value)
/// <summary>
/// Implementation of IStreamWriter
/// </summary>
public unsafe void Write(long value)
public unsafe void WriteInt64(long value)
{
if (endPosition + sizeof(long) > bytes.Length)
{
Expand All @@ -325,42 +325,42 @@ public unsafe void Write(long value)
/// <summary>
/// Implementation of IStreamWriter
/// </summary>
public void Write(StreamLabel value)
public void WriteLabel(StreamLabel value)
{
Debug.Assert((long)value <= int.MaxValue);
Write((int)value);
WriteInt32((int)value);
}
/// <summary>
/// Implementation of IStreamWriter
/// </summary>
public void Write(string value)
public void WriteString(string value)
{
if (value == null)
{
Write(-1); // negative charCount means null.
WriteInt32(-1); // negative charCount means null.
}
else
{
Write(value.Length);
WriteInt32(value.Length);
for (int i = 0; i < value.Length; i++)
{
char c = value[i];
if (c <= 0x7F)
{
Write((byte)value[i]); // Only need one byte for UTF8
WriteByte((byte)value[i]); // Only need one byte for UTF8
}
else if (c <= 0x7FF)
{
// TODO confirm that this is correct!
Write((byte)(0xC0 | (c >> 6))); // Encode 2 byte UTF8
Write((byte)(0x80 | (c & 0x3F)));
WriteByte((byte)(0xC0 | (c >> 6))); // Encode 2 byte UTF8
WriteByte((byte)(0x80 | (c & 0x3F)));
}
else
{
// TODO confirm that this is correct!
Write((byte)(0xE0 | ((c >> 12) & 0xF))); // Encode 3 byte UTF8
Write((byte)(0x80 | ((c >> 6) & 0x3F)));
Write((byte)(0x80 | (c & 0x3F)));
WriteByte((byte)(0xE0 | ((c >> 12) & 0xF))); // Encode 3 byte UTF8
WriteByte((byte)(0x80 | ((c >> 6) & 0x3F)));
WriteByte((byte)(0x80 | (c & 0x3F)));
}
}
}
Expand All @@ -379,7 +379,7 @@ public void WriteSuffixLabel(StreamLabel value)
{
// This is guaranteed to be uncompressed, but since we are not compressing anything, we can
// simply write the value.
Write(value);
WriteLabel(value);
}

/// <summary>
Expand Down
92 changes: 46 additions & 46 deletions src/HeapDump/GCHeapDump.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,41 +258,41 @@ private static void GetProcessesWithGCHeapsFromHeapDump(Dictionary<int, ProcessI

void IFastSerializable.ToStream(Serializer serializer)
{
serializer.Write(m_graph);
serializer.Write(m_graph.Is64Bit); // This is redundant but graph did not used to hold this value
serializer.WriteObject(m_graph);
serializer.WriteBoolean(m_graph.Is64Bit); // This is redundant but graph did not used to hold this value
// we write the bit here to preserve compatibility.
serializer.Write(AverageCountMultiplier);
serializer.Write(AverageSizeMultiplier);
serializer.WriteSingle(AverageCountMultiplier);
serializer.WriteSingle(AverageSizeMultiplier);

serializer.Write(JSHeapInfo);
serializer.Write(DotNetHeapInfo);
serializer.WriteObject(JSHeapInfo);
serializer.WriteObject(DotNetHeapInfo);

serializer.Write(CollectionLog);
serializer.Write(TimeCollected.Ticks);
serializer.Write(MachineName);
serializer.Write(ProcessName);
serializer.Write(ProcessID);
serializer.Write(TotalProcessCommit);
serializer.Write(TotalProcessWorkingSet);
serializer.WriteString(CollectionLog);
serializer.WriteInt64(TimeCollected.Ticks);
serializer.WriteString(MachineName);
serializer.WriteString(ProcessName);
serializer.WriteInt32(ProcessID);
serializer.WriteInt64(TotalProcessCommit);
serializer.WriteInt64(TotalProcessWorkingSet);

if (CountMultipliersByType == null)
{
serializer.Write(0);
serializer.WriteInt32(0);
}
else
{
serializer.Write(CountMultipliersByType.Length);
serializer.WriteInt32(CountMultipliersByType.Length);
for (int i = 0; i < CountMultipliersByType.Length; i++)
{
serializer.Write(CountMultipliersByType[i]);
serializer.WriteSingle(CountMultipliersByType[i]);
}
}

// All fields after version 8 should go here and should be in
// the version order (thus always add at the end). Also use the
// WriteTagged variation to write.
serializer.WriteTagged(m_interop);
serializer.WriteTagged(CreationTool);
serializer.WriteTaggedObject(m_interop);
serializer.WriteTaggedString(CreationTool);
}

void IFastSerializable.FromStream(Deserializer deserializer)
Expand Down Expand Up @@ -566,54 +566,54 @@ void IFastSerializable.ToStream(Serializer serializer)
{
int countRCWCCW = m_listRCWInfo.Count + m_listCCWInfo.Count;

serializer.Write(countRCWCCW);
serializer.WriteInt32(countRCWCCW);
if (countRCWCCW == 0)
{
return;
}

serializer.Write(m_listRCWInfo.Count);
serializer.Write(m_listCCWInfo.Count);
serializer.Write(m_listComInterfaceInfo.Count);
serializer.Write(m_listModules.Count);
serializer.WriteInt32(m_listRCWInfo.Count);
serializer.WriteInt32(m_listCCWInfo.Count);
serializer.WriteInt32(m_listComInterfaceInfo.Count);
serializer.WriteInt32(m_listModules.Count);

for (int i = 0; i < m_listRCWInfo.Count; i++)
{
serializer.Write((int)m_listRCWInfo[i].node);
serializer.Write(m_listRCWInfo[i].refCount);
serializer.Write((long)m_listRCWInfo[i].addrIUnknown);
serializer.Write((long)m_listRCWInfo[i].addrJupiter);
serializer.Write((long)m_listRCWInfo[i].addrVTable);
serializer.Write(m_listRCWInfo[i].firstComInf);
serializer.Write(m_listRCWInfo[i].countComInf);
serializer.WriteInt32((int)m_listRCWInfo[i].node);
serializer.WriteInt32(m_listRCWInfo[i].refCount);
serializer.WriteInt64((long)m_listRCWInfo[i].addrIUnknown);
serializer.WriteInt64((long)m_listRCWInfo[i].addrJupiter);
serializer.WriteInt64((long)m_listRCWInfo[i].addrVTable);
serializer.WriteInt32(m_listRCWInfo[i].firstComInf);
serializer.WriteInt32(m_listRCWInfo[i].countComInf);
}

for (int i = 0; i < m_listCCWInfo.Count; i++)
{
serializer.Write((int)m_listCCWInfo[i].node);
serializer.Write(m_listCCWInfo[i].refCount);
serializer.Write((long)m_listCCWInfo[i].addrIUnknown);
serializer.Write((long)m_listCCWInfo[i].addrHandle);
serializer.Write(m_listCCWInfo[i].firstComInf);
serializer.Write(m_listCCWInfo[i].countComInf);
serializer.WriteInt32((int)m_listCCWInfo[i].node);
serializer.WriteInt32(m_listCCWInfo[i].refCount);
serializer.WriteInt64((long)m_listCCWInfo[i].addrIUnknown);
serializer.WriteInt64((long)m_listCCWInfo[i].addrHandle);
serializer.WriteInt32(m_listCCWInfo[i].firstComInf);
serializer.WriteInt32(m_listCCWInfo[i].countComInf);
}

for (int i = 0; i < m_listComInterfaceInfo.Count; i++)
{
serializer.Write(m_listComInterfaceInfo[i].fRCW ? (byte)1 : (byte)0);
serializer.Write(m_listComInterfaceInfo[i].owner);
serializer.Write((int)m_listComInterfaceInfo[i].typeID);
serializer.Write((long)m_listComInterfaceInfo[i].addrInterface);
serializer.Write((long)m_listComInterfaceInfo[i].addrFirstVTable);
serializer.Write((long)m_listComInterfaceInfo[i].addrFirstFunc);
serializer.WriteByte(m_listComInterfaceInfo[i].fRCW ? (byte)1 : (byte)0);
serializer.WriteInt32(m_listComInterfaceInfo[i].owner);
serializer.WriteInt32((int)m_listComInterfaceInfo[i].typeID);
serializer.WriteInt64((long)m_listComInterfaceInfo[i].addrInterface);
serializer.WriteInt64((long)m_listComInterfaceInfo[i].addrFirstVTable);
serializer.WriteInt64((long)m_listComInterfaceInfo[i].addrFirstFunc);
}

for (int i = 0; i < m_listModules.Count; i++)
{
serializer.Write((long)m_listModules[i].baseAddress);
serializer.Write((int)m_listModules[i].fileSize);
serializer.Write((int)m_listModules[i].timeStamp);
serializer.Write(m_listModules[i].fileName);
serializer.WriteInt64((long)m_listModules[i].baseAddress);
serializer.WriteInt32((int)m_listModules[i].fileSize);
serializer.WriteInt32((int)m_listModules[i].timeStamp);
serializer.WriteString(m_listModules[i].fileName);
}
}

Expand Down
20 changes: 10 additions & 10 deletions src/HeapDumpCommon/DotNetHeapInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,18 @@ public int GenerationFor(Address obj)
#region private
void IFastSerializable.ToStream(Serializer serializer)
{
serializer.Write(SizeOfAllSegments);
serializer.WriteInt64(SizeOfAllSegments);
if (Segments != null)
{
serializer.Write(Segments.Count);
serializer.WriteInt32(Segments.Count);
foreach (var segment in Segments)
{
serializer.Write(segment);
serializer.WriteObject(segment);
}
}
else
{
serializer.Write(0);
serializer.WriteInt32(0);
}
}
void IFastSerializable.FromStream(Deserializer deserializer)
Expand Down Expand Up @@ -119,12 +119,12 @@ public class GCHeapDumpSegment : IFastSerializable
#region private
void IFastSerializable.ToStream(Serializer serializer)
{
serializer.Write((long)Start);
serializer.Write((long)End);
serializer.Write((long)Gen0End);
serializer.Write((long)Gen1End);
serializer.Write((long)Gen2End);
serializer.Write((long)Gen3End);
serializer.WriteInt64((long)Start);
serializer.WriteInt64((long)End);
serializer.WriteInt64((long)Gen0End);
serializer.WriteInt64((long)Gen1End);
serializer.WriteInt64((long)Gen2End);
serializer.WriteInt64((long)Gen3End);
}

void IFastSerializable.FromStream(Deserializer deserializer)
Expand Down
6 changes: 3 additions & 3 deletions src/MemoryGraph/MemoryGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,13 @@ void IFastSerializable.ToStream(Serializer serializer)
{
base.ToStream(serializer);
// Write out the Memory addresses of each object
serializer.Write(m_nodeAddresses.Count);
serializer.WriteInt32(m_nodeAddresses.Count);
for (int i = 0; i < m_nodeAddresses.Count; i++)
{
serializer.Write((long)m_nodeAddresses[i]);
serializer.WriteInt64((long)m_nodeAddresses[i]);
}

serializer.WriteTagged(Is64Bit);
serializer.WriteTaggedBoolean(Is64Bit);
}

void IFastSerializable.FromStream(Deserializer deserializer)
Expand Down
42 changes: 21 additions & 21 deletions src/MemoryGraph/graph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -498,32 +498,32 @@ internal struct DeferedTypeInfo

public virtual void ToStream(Serializer serializer)
{
serializer.Write(m_totalSize);
serializer.Write((int)RootIndex);
serializer.WriteInt64(m_totalSize);
serializer.WriteInt32((int)RootIndex);
// Write out the Types
serializer.Write(m_types.Count);
serializer.WriteInt32(m_types.Count);
for (int i = 0; i < m_types.Count; i++)
{
serializer.Write(m_types[i].Name);
serializer.Write(m_types[i].Size);
serializer.Write(m_types[i].ModuleName);
serializer.WriteString(m_types[i].Name);
serializer.WriteInt32(m_types[i].Size);
serializer.WriteString(m_types[i].ModuleName);
}

// Write out the Nodes
serializer.Write(m_nodes.Count);
serializer.WriteInt32(m_nodes.Count);
for (int i = 0; i < m_nodes.Count; i++)
{
serializer.Write((int)m_nodes[i]);
serializer.WriteInt32((int)m_nodes[i]);
}

// Write out the Blob stream.
// TODO this is inefficient. Also think about very large files.
int readerLen = (int)m_reader.Length;
serializer.Write(readerLen);
serializer.WriteInt32(readerLen);
m_reader.Goto((StreamLabel)0);
for (uint i = 0; i < readerLen; i++)
{
serializer.Write(m_reader.ReadByte());
serializer.WriteByte(m_reader.ReadByte());
}

// Are we writing a format for 1 or greater? If so we can use the new (breaking) format, otherwise
Expand All @@ -538,12 +538,12 @@ public virtual void ToStream(Serializer serializer)
expansion.Write(serializer, delegate ()
{
// I don't need to use Tagged types for my 'first' version of this new region
serializer.Write(m_deferedTypes.Count);
serializer.WriteInt32(m_deferedTypes.Count);
for (int i = 0; i < m_deferedTypes.Count; i++)
{
serializer.Write(m_deferedTypes[i].TypeID);
serializer.Write(m_deferedTypes[i].Module);
serializer.Write(m_deferedTypes[i].TypeNameSuffix);
serializer.WriteInt32(m_deferedTypes[i].TypeID);
serializer.WriteObject(m_deferedTypes[i].Module);
serializer.WriteString(m_deferedTypes[i].TypeNameSuffix);
}

// You can place tagged values in here always adding right before the WriteTaggedEnd
Expand Down Expand Up @@ -1077,13 +1077,13 @@ public class Module : IFastSerializable
/// </summary>
public void ToStream(Serializer serializer)
{
serializer.Write(Path);
serializer.Write((long)ImageBase);
serializer.Write(Size);
serializer.Write(BuildTime.Ticks);
serializer.Write(PdbName);
serializer.Write(PdbGuid);
serializer.Write(PdbAge);
serializer.WriteString(Path);
serializer.WriteInt64((long)ImageBase);
serializer.WriteInt32(Size);
serializer.WriteInt64(BuildTime.Ticks);
serializer.WriteString(PdbName);
serializer.WriteGuid(PdbGuid);
serializer.WriteInt32(PdbAge);
}
/// <summary>
/// Implementing IFastSerializable interface.
Expand Down
4 changes: 2 additions & 2 deletions src/PerfView/memory/ClrProfilerMemoryGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -311,10 +311,10 @@ void IFastSerializable.ToStream(Serializer serializer)
{
base.ToStream(serializer);
// Write out the Memory addresses of each object
serializer.Write(m_nodeAddresses.Count);
serializer.WriteInt32(m_nodeAddresses.Count);
for (int i = 0; i < m_nodeAddresses.Count; i++)
{
serializer.Write((long)m_nodeAddresses[i]);
serializer.WriteInt64((long)m_nodeAddresses[i]);
}
}
void IFastSerializable.FromStream(Deserializer deserializer)
Expand Down
Loading