Spdx 3.0 Parser for SBOM files by pragnya17 · Pull Request #860 · microsoft/sbom-tool (original) (raw)

Expand Up

@@ -21,7 +21,7 @@ namespace Microsoft.Sbom.JsonAsynchronousNodeKit;

/// This class is not Thread-safe since the stream and JsonReaders assume a single forward-only reader.

/// Because of the use of recursion in the GetObject method, this class is also not suitable for parsing very deep json objects.

///

internal class LargeJsonParser

public class LargeJsonParser

Comment thread

sfoslund marked this conversation as resolved.

{

private const int DefaultReadBufferSize = 4096;

private readonly Stream stream;

Expand All

@@ -43,7 +43,6 @@ public LargeJsonParser(

this.stream = stream ?? throw new ArgumentNullException(nameof(stream));

this.handlers = handlers ?? throw new ArgumentNullException(nameof(handlers));

this.jsonSerializerOptions = jsonSerializerOptions ?? new JsonSerializerOptions();

this.buffer = new byte[bufferSize];

// Validate buffer is not of 0 length.

Expand Down Expand Up

@@ -153,6 +152,7 @@ private ParserStateResult HandleExplicitProperty(ref Utf8JsonReader reader, stri

var handler = this.handlers![propertyName];

object? result;

switch (handler.Type)

{

case ParameterType.String:

Expand Down Expand Up

@@ -268,11 +268,23 @@ private IEnumerable GetArray(Type type)

private object GetObject(Type type, ref Utf8JsonReader reader)

{

var jsonObject = ParserUtils.ParseObject(this.stream, ref this.buffer, ref reader);

object? result = jsonObject;

if (type != typeof(JsonNode))

object? result = null;

Comment thread

pragnya17 marked this conversation as resolved.

if (type == typeof(string))

{

result = reader.GetString();

}

else

{

result = jsonObject.Deserialize(type, this.jsonSerializerOptions);

var jsonObject = ParserUtils.ParseObject(this.stream, ref this.buffer, ref reader);

if (type != typeof(JsonNode))

{

result = jsonObject.Deserialize(type, this.jsonSerializerOptions);

}

else

{

result = jsonObject;

}

}

if (result is null)

Expand Down