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

Refactoring deserialization into methods #4061

Merged
merged 2 commits into from
Nov 13, 2024
Merged
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
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
Loading