Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
ec3d9481
Commit
ec3d9481
authored
Mar 18, 2019
by
Jan Tattermusch
Committed by
Jie Luo
Mar 18, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add System.Memory dependency (#5835)
also add useful Span-based methods for ByteString
parent
68cd8e8b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
13 deletions
+28
-13
ByteString.cs
csharp/src/Google.Protobuf/ByteString.cs
+22
-11
Google.Protobuf.csproj
csharp/src/Google.Protobuf/Google.Protobuf.csproj
+6
-2
No files found.
csharp/src/Google.Protobuf/ByteString.cs
View file @
ec3d9481
...
...
@@ -67,15 +67,6 @@ namespace Google.Protobuf
{
return
new
ByteString
(
bytes
);
}
/// <summary>
/// Provides direct, unrestricted access to the bytes contained in this instance.
/// You must not modify or resize the byte array returned by this method.
/// </summary>
internal
static
byte
[]
GetBuffer
(
ByteString
bytes
)
{
return
bytes
.
bytes
;
}
}
/// <summary>
...
...
@@ -119,6 +110,14 @@ namespace Google.Protobuf
get
{
return
Length
==
0
;
}
}
#if NETSTANDARD2_0
/// <summary>
/// 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
);
#endif
/// <summary>
/// Converts this <see cref="ByteString"/> into a byte array.
/// </summary>
...
...
@@ -161,7 +160,7 @@ namespace Google.Protobuf
int
capacity
=
stream
.
CanSeek
?
checked
((
int
)
(
stream
.
Length
-
stream
.
Position
))
:
0
;
var
memoryStream
=
new
MemoryStream
(
capacity
);
stream
.
CopyTo
(
memoryStream
);
#if NETSTANDARD1_0
#if NETSTANDARD1_0
|| NETSTANDARD2_0
byte
[]
bytes
=
memoryStream
.
ToArray
();
#else
// Avoid an extra copy if we can.
...
...
@@ -187,7 +186,7 @@ namespace Google.Protobuf
// We have to specify the buffer size here, as there's no overload accepting the cancellation token
// alone. But it's documented to use 81920 by default if not specified.
await
stream
.
CopyToAsync
(
memoryStream
,
81920
,
cancellationToken
);
#if NETSTANDARD1_0
#if NETSTANDARD1_0
|| NETSTANDARD2_0
byte
[]
bytes
=
memoryStream
.
ToArray
();
#else
// Avoid an extra copy if we can.
...
...
@@ -219,6 +218,18 @@ namespace Google.Protobuf
return
new
ByteString
(
portion
);
}
#if NETSTANDARD2_0
/// <summary>
/// Constructs a <see cref="ByteString" /> from a read only span. The contents
/// are copied, so further modifications to the span will not
/// be reflected in the returned <see cref="ByteString" />.
/// </summary>
public
static
ByteString
CopyFrom
(
ReadOnlySpan
<
byte
>
bytes
)
{
return
new
ByteString
(
bytes
.
ToArray
());
}
#endif
/// <summary>
/// Creates a new <see cref="ByteString" /> by encoding the specified text with
/// the given encoding.
...
...
csharp/src/Google.Protobuf/Google.Protobuf.csproj
View file @
ec3d9481
...
...
@@ -7,7 +7,7 @@
<VersionPrefix>3.7.0</VersionPrefix>
<LangVersion>6</LangVersion>
<Authors>Google Inc.</Authors>
<TargetFrameworks>netstandard1.0;net45</TargetFrameworks>
<TargetFrameworks>netstandard1.0;net
standard2.0;net
45</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<AssemblyOriginatorKeyFile>../../keys/Google.Protobuf.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
...
...
@@ -28,9 +28,13 @@
- Visual Studio.
-->
<PropertyGroup Condition="'$(OS)' != 'Windows_NT'">
<TargetFrameworks>netstandard1.0</TargetFrameworks>
<TargetFrameworks>netstandard1.0
;netstandard2.0
</TargetFrameworks>
</PropertyGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<PackageReference Include="System.Memory" Version="4.5.2" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0-beta2-18618-05" PrivateAssets="All" />
</ItemGroup>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment