|
|
|
@ -41,38 +41,38 @@ namespace Google.Protobuf |
|
|
|
|
{ |
|
|
|
|
public static void AssertReadingMessage<T>(MessageParser<T> parser, byte[] bytes, Action<T> assert) where T : IMessage<T> |
|
|
|
|
{ |
|
|
|
|
var parsedBuffer = parser.ParseFrom(bytes); |
|
|
|
|
assert(parsedBuffer); |
|
|
|
|
var parsedMsg = parser.ParseFrom(bytes); |
|
|
|
|
assert(parsedMsg); |
|
|
|
|
|
|
|
|
|
// Load content as single segment |
|
|
|
|
parsedBuffer = parser.ParseFrom(new ReadOnlySequence<byte>(bytes)); |
|
|
|
|
assert(parsedBuffer); |
|
|
|
|
parsedMsg = parser.ParseFrom(new ReadOnlySequence<byte>(bytes)); |
|
|
|
|
assert(parsedMsg); |
|
|
|
|
|
|
|
|
|
// Load content as multiple segments |
|
|
|
|
parsedBuffer = parser.ParseFrom(ReadOnlySequenceFactory.CreateWithContent(bytes)); |
|
|
|
|
assert(parsedBuffer); |
|
|
|
|
parsedMsg = parser.ParseFrom(ReadOnlySequenceFactory.CreateWithContent(bytes)); |
|
|
|
|
assert(parsedMsg); |
|
|
|
|
|
|
|
|
|
// Load content as ReadOnlySpan |
|
|
|
|
parsedBuffer = parser.ParseFrom(new ReadOnlySpan<byte>(bytes)); |
|
|
|
|
assert(parsedBuffer); |
|
|
|
|
parsedMsg = parser.ParseFrom(new ReadOnlySpan<byte>(bytes)); |
|
|
|
|
assert(parsedMsg); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static void AssertReadingMessage(MessageParser parser, byte[] bytes, Action<IMessage> assert) |
|
|
|
|
{ |
|
|
|
|
var parsedBuffer = parser.ParseFrom(bytes); |
|
|
|
|
assert(parsedBuffer); |
|
|
|
|
var parsedMsg = parser.ParseFrom(bytes); |
|
|
|
|
assert(parsedMsg); |
|
|
|
|
|
|
|
|
|
// Load content as single segment |
|
|
|
|
parsedBuffer = parser.ParseFrom(new ReadOnlySequence<byte>(bytes)); |
|
|
|
|
assert(parsedBuffer); |
|
|
|
|
parsedMsg = parser.ParseFrom(new ReadOnlySequence<byte>(bytes)); |
|
|
|
|
assert(parsedMsg); |
|
|
|
|
|
|
|
|
|
// Load content as multiple segments |
|
|
|
|
parsedBuffer = parser.ParseFrom(ReadOnlySequenceFactory.CreateWithContent(bytes)); |
|
|
|
|
assert(parsedBuffer); |
|
|
|
|
parsedMsg = parser.ParseFrom(ReadOnlySequenceFactory.CreateWithContent(bytes)); |
|
|
|
|
assert(parsedMsg); |
|
|
|
|
|
|
|
|
|
// Load content as ReadOnlySpan |
|
|
|
|
parsedBuffer = parser.ParseFrom(new ReadOnlySpan<byte>(bytes)); |
|
|
|
|
assert(parsedBuffer); |
|
|
|
|
parsedMsg = parser.ParseFrom(new ReadOnlySpan<byte>(bytes)); |
|
|
|
|
assert(parsedMsg); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static void AssertReadingMessageThrows<TMessage, TException>(MessageParser<TMessage> parser, byte[] bytes) |
|
|
|
@ -95,24 +95,24 @@ namespace Google.Protobuf |
|
|
|
|
message.WriteTo(bufferWriter); |
|
|
|
|
Assert.AreEqual(bytes, bufferWriter.WrittenSpan.ToArray(), "Both serialization approaches need to result in the same data."); |
|
|
|
|
|
|
|
|
|
var parsedBuffer = parser.ParseFrom(bytes); |
|
|
|
|
Assert.AreEqual(message, parsedBuffer); |
|
|
|
|
additionalAssert?.Invoke(parsedBuffer); |
|
|
|
|
var parsedMsg = parser.ParseFrom(bytes); |
|
|
|
|
Assert.AreEqual(message, parsedMsg); |
|
|
|
|
additionalAssert?.Invoke(parsedMsg); |
|
|
|
|
|
|
|
|
|
// Load content as single segment |
|
|
|
|
parsedBuffer = parser.ParseFrom(new ReadOnlySequence<byte>(bytes)); |
|
|
|
|
Assert.AreEqual(message, parsedBuffer); |
|
|
|
|
additionalAssert?.Invoke(parsedBuffer); |
|
|
|
|
parsedMsg = parser.ParseFrom(new ReadOnlySequence<byte>(bytes)); |
|
|
|
|
Assert.AreEqual(message, parsedMsg); |
|
|
|
|
additionalAssert?.Invoke(parsedMsg); |
|
|
|
|
|
|
|
|
|
// Load content as multiple segments |
|
|
|
|
parsedBuffer = parser.ParseFrom(ReadOnlySequenceFactory.CreateWithContent(bytes)); |
|
|
|
|
Assert.AreEqual(message, parsedBuffer); |
|
|
|
|
additionalAssert?.Invoke(parsedBuffer); |
|
|
|
|
parsedMsg = parser.ParseFrom(ReadOnlySequenceFactory.CreateWithContent(bytes)); |
|
|
|
|
Assert.AreEqual(message, parsedMsg); |
|
|
|
|
additionalAssert?.Invoke(parsedMsg); |
|
|
|
|
|
|
|
|
|
// Load content as ReadOnlySpan |
|
|
|
|
parsedBuffer = parser.ParseFrom(new ReadOnlySpan<byte>(bytes)); |
|
|
|
|
Assert.AreEqual(message, parsedBuffer); |
|
|
|
|
additionalAssert?.Invoke(parsedBuffer); |
|
|
|
|
parsedMsg = parser.ParseFrom(new ReadOnlySpan<byte>(bytes)); |
|
|
|
|
Assert.AreEqual(message, parsedMsg); |
|
|
|
|
additionalAssert?.Invoke(parsedMsg); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static void AssertWritingMessage(IMessage message) |
|
|
|
|