Skip to content

Commit

Permalink
Refactoring deserialization into methods (#4061)
Browse files Browse the repository at this point in the history
  • Loading branch information
nohwnd authored Nov 13, 2024
1 parent eaf26c3 commit 7eade67
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ internal static class FailedTestResultMessageFieldsId
public const ushort Duration = 4;
public const ushort Reason = 5;
public const ushort ExceptionMessageList = 6;
public const ushort StandardOutput = 8;
public const ushort ErrorOutput = 9;
public const ushort SessionUid = 10;
public const ushort StandardOutput = 7;
public const ushort ErrorOutput = 8;
public const ushort SessionUid = 9;
}

internal static class ExceptionMessageFieldsId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ private static List<FailedTestResultMessage> ReadFailedTestMessagesPayload(Strea
for (int i = 0; i < length; i++)
{
string? uid = null, displayName = null, reason = null, sessionUid = null, standardOutput = null, errorOutput = null;
List<ExceptionMessage> exceptionMessages = [];
ExceptionMessage[] exceptionMessages = [];
byte? state = null;
long? duration = null;

Expand Down Expand Up @@ -249,42 +249,8 @@ private static List<FailedTestResultMessage> ReadFailedTestMessagesPayload(Strea
break;

case FailedTestResultMessageFieldsId.ExceptionMessageList:
{
int length2 = ReadInt(stream);
for (int k = 0; k < length2; k++)
{
int fieldCount2 = ReadShort(stream);

string? errorMessage = null;
string? errorType = null;
string? stackTrace = null;

for (int l = 0; l < fieldCount2; l++)
{
int fieldId2 = ReadShort(stream);
int fieldSize2 = ReadInt(stream);

switch (fieldId2)
{
case ExceptionMessageFieldsId.ErrorMessage:
errorMessage = ReadStringValue(stream, fieldSize2);
break;

case ExceptionMessageFieldsId.ErrorType:
errorType = ReadStringValue(stream, fieldSize2);
break;

case ExceptionMessageFieldsId.StackTrace:
stackTrace = ReadStringValue(stream, fieldSize2);
break;
}
}

exceptionMessages.Add(new ExceptionMessage(errorMessage, errorType, stackTrace));
}

break;
}
exceptionMessages = ReadExceptionMessagesPayload(stream);
break;

case FailedTestResultMessageFieldsId.StandardOutput:
standardOutput = ReadStringValue(stream, fieldSize);
Expand All @@ -304,12 +270,52 @@ private static List<FailedTestResultMessage> ReadFailedTestMessagesPayload(Strea
}
}

failedTestResultMessages.Add(new FailedTestResultMessage(uid, displayName, state, duration, reason, exceptionMessages.ToArray(), standardOutput, errorOutput, sessionUid));
failedTestResultMessages.Add(new FailedTestResultMessage(uid, displayName, state, duration, reason, exceptionMessages, standardOutput, errorOutput, sessionUid));
}

return failedTestResultMessages;
}

private static ExceptionMessage[] ReadExceptionMessagesPayload(Stream stream)
{
var exceptionMessages = new List<ExceptionMessage>();

int length = ReadInt(stream);
for (int i = 0; i < length; i++)
{
int fieldCount = ReadShort(stream);

string? errorMessage = null;
string? errorType = null;
string? stackTrace = null;

for (int j = 0; j < fieldCount; j++)
{
int fieldId = ReadShort(stream);
int fieldSize = ReadInt(stream);

switch (fieldId)
{
case ExceptionMessageFieldsId.ErrorMessage:
errorMessage = ReadStringValue(stream, fieldSize);
break;

case ExceptionMessageFieldsId.ErrorType:
errorType = ReadStringValue(stream, fieldSize);
break;

case ExceptionMessageFieldsId.StackTrace:
stackTrace = ReadStringValue(stream, fieldSize);
break;
}
}

exceptionMessages.Add(new ExceptionMessage(errorMessage, errorType, stackTrace));
}

return exceptionMessages.ToArray();
}

public void Serialize(object objectToSerialize, Stream stream)
{
RoslynDebug.Assert(stream.CanSeek, "We expect a seekable stream.");
Expand Down

0 comments on commit 7eade67

Please sign in to comment.