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

Add spans support to CodedInputStream #8

Closed
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
2 changes: 1 addition & 1 deletion csharp/src/Google.Protobuf.Test/CodedInputStreamTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ public void TestSlowPathAvoidance()
output.Flush();

ms.Position = 0;
CodedInputStream input = new CodedInputStream(ms, new byte[ms.Length / 2], 0, 0, false);
CodedInputStream input = new CodedInputStream(ms, new byte[ms.Length / 2], null, null, 0, 0, false);

uint tag = input.ReadTag();
Assert.AreEqual(1, WireFormat.GetTagFieldNumber(tag));
Expand Down
2 changes: 1 addition & 1 deletion csharp/src/Google.Protobuf.Test/CodedOutputStreamTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ public void TestCodedInputOutputPosition()
}
// Now test Input stream:
{
CodedInputStream cin = new CodedInputStream(new MemoryStream(bytes), new byte[50], 0, 0, false);
CodedInputStream cin = new CodedInputStream(new MemoryStream(bytes), new byte[50], null, null, 0, 0, false);
Assert.AreEqual(0, cin.Position);
// Field 1:
uint tag = cin.ReadTag();
Expand Down
8 changes: 7 additions & 1 deletion csharp/src/Google.Protobuf/ByteString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Security;
using System.Text;
#if !NET35
using System.Threading;
Expand Down Expand Up @@ -114,7 +115,11 @@ public bool IsEmpty
/// Provides read-only access to the data of this <see cref="ByteString"/>.
/// No data is copied so this is the most efficient way of accessing.
/// </summary>
public ReadOnlySpan<byte> Span => new ReadOnlySpan<byte>(bytes);
public ReadOnlySpan<byte> Span
{
[SecurityCritical]
get => bytes;
}

/// <summary>
/// Converts this <see cref="ByteString"/> into a byte array.
Expand Down Expand Up @@ -221,6 +226,7 @@ public static ByteString CopyFrom(byte[] bytes, int offset, int count)
/// are copied, so further modifications to the span will not
/// be reflected in the returned <see cref="ByteString" />.
/// </summary>
[SecurityCritical]
public static ByteString CopyFrom(ReadOnlySpan<byte> bytes)
{
return new ByteString(bytes.ToArray());
Expand Down
Loading