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
0c874a6a
Commit
0c874a6a
authored
Nov 09, 2017
by
Jan Tattermusch
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
allow message parsing from an array slice
parent
c258fb30
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
0 deletions
+31
-0
MessageExtensions.cs
csharp/src/Google.Protobuf/MessageExtensions.cs
+16
-0
MessageParser.cs
csharp/src/Google.Protobuf/MessageParser.cs
+15
-0
No files found.
csharp/src/Google.Protobuf/MessageExtensions.cs
View file @
0c874a6a
...
...
@@ -53,6 +53,22 @@ namespace Google.Protobuf
input
.
CheckReadEndOfStreamTag
();
}
/// <summary>
/// Merges data from the given byte array slice into an existing message.
/// </summary>
/// <param name="message">The message to merge the data into.</param>
/// <param name="data">The data containing the slice to merge, which must be protobuf-encoded binary data.</param>
/// <param name="offset">The offset of the slice to merge.</param>
/// <param name="length">The length of the slice to merge.</param>
public
static
void
MergeFrom
(
this
IMessage
message
,
byte
[]
data
,
int
offset
,
int
length
)
{
ProtoPreconditions
.
CheckNotNull
(
message
,
"message"
);
ProtoPreconditions
.
CheckNotNull
(
data
,
"data"
);
CodedInputStream
input
=
new
CodedInputStream
(
data
,
offset
,
length
);
message
.
MergeFrom
(
input
);
input
.
CheckReadEndOfStreamTag
();
}
/// <summary>
/// Merges data from the given byte string into an existing message.
/// </summary>
...
...
csharp/src/Google.Protobuf/MessageParser.cs
View file @
0c874a6a
...
...
@@ -70,6 +70,21 @@ namespace Google.Protobuf
return
message
;
}
/// <summary>
/// Parses a message from a byte array slice.
/// </summary>
/// <param name="data">The byte array containing the message. Must not be null.</param>
/// <param name="offset">The offset of the slice to parse.</param>
/// <param name="length">The length of the slice to parse.</param>
/// <returns>The newly parsed message.</returns>
public
IMessage
ParseFrom
(
byte
[]
data
,
int
offset
,
int
length
)
{
ProtoPreconditions
.
CheckNotNull
(
data
,
"data"
);
IMessage
message
=
factory
();
message
.
MergeFrom
(
data
,
offset
,
length
);
return
message
;
}
/// <summary>
/// Parses a message from the given byte string.
/// </summary>
...
...
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