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
45a93fad
Commit
45a93fad
authored
Jun 02, 2011
by
csharptest
Committed by
rogerk
Jun 02, 2011
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimized access to ByteString from coded io.
parent
efed509b
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
11 deletions
+37
-11
ByteString.cs
src/ProtocolBuffers/ByteString.cs
+30
-0
CodedInputStream.cs
src/ProtocolBuffers/CodedInputStream.cs
+2
-2
CodedOutputStream.cs
src/ProtocolBuffers/CodedOutputStream.cs
+5
-9
No files found.
src/ProtocolBuffers/ByteString.cs
View file @
45a93fad
...
...
@@ -51,6 +51,14 @@ namespace Google.ProtocolBuffers
private
readonly
byte
[]
bytes
;
/// <summary>
/// Internal use only. Ensure that the provided array is not mutated and belongs to this instance.
/// </summary>
internal
static
ByteString
AttachBytes
(
byte
[]
bytes
)
{
return
new
ByteString
(
bytes
);
}
/// <summary>
/// Constructs a new ByteString from the given byte array. The array is
/// *not* copied, and must not be modified after this constructor is called.
...
...
@@ -237,5 +245,26 @@ namespace Google.ProtocolBuffers
get
{
return
output
;
}
}
}
internal
void
WriteTo
(
CodedOutputStream
outputStream
)
{
outputStream
.
WriteRawBytes
(
bytes
,
0
,
bytes
.
Length
);
}
/// <summary>
/// Copies the entire byte array to the destination array provided at the offset specified.
/// </summary>
public
void
CopyTo
(
Array
array
,
int
position
)
{
Array
.
Copy
(
bytes
,
0
,
array
,
position
,
bytes
.
Length
);
}
/// <summary>
/// Writes the entire byte array to the provided stream
/// </summary>
public
void
WriteTo
(
System
.
IO
.
Stream
outputStream
)
{
outputStream
.
Write
(
bytes
,
0
,
bytes
.
Length
);
}
}
}
\ No newline at end of file
src/ProtocolBuffers/CodedInputStream.cs
View file @
45a93fad
...
...
@@ -58,7 +58,7 @@ namespace Google.ProtocolBuffers
/// TODO(jonskeet): Consider whether recursion and size limits shouldn't be readonly,
/// set at construction time.
/// </remarks>
public
sealed
class
CodedInputStream
public
sealed
partial
class
CodedInputStream
{
private
readonly
byte
[]
buffer
;
private
int
bufferSize
;
...
...
@@ -353,7 +353,7 @@ namespace Google.ProtocolBuffers
else
{
// Slow path: Build a byte array first then copy it.
return
ByteString
.
CopyFrom
(
ReadRawBytes
(
size
));
return
ByteString
.
AttachBytes
(
ReadRawBytes
(
size
));
}
}
...
...
src/ProtocolBuffers/CodedOutputStream.cs
View file @
45a93fad
...
...
@@ -54,7 +54,7 @@ namespace Google.ProtocolBuffers
/// methods are taken from the protocol buffer type names, not .NET types.
/// (Hence WriteFloat instead of WriteSingle, and WriteBool instead of WriteBoolean.)
/// </remarks>
public
sealed
class
CodedOutputStream
public
sealed
partial
class
CodedOutputStream
{
/// <summary>
/// The buffer size used by CreateInstance(Stream).
...
...
@@ -257,11 +257,9 @@ namespace Google.ProtocolBuffers
public
void
WriteBytes
(
int
fieldNumber
,
ByteString
value
)
{
// TODO(jonskeet): Optimise this! (No need to copy the bytes twice.)
WriteTag
(
fieldNumber
,
WireFormat
.
WireType
.
LengthDelimited
);
byte
[]
bytes
=
value
.
ToByteArray
();
WriteRawVarint32
((
uint
)
bytes
.
Length
);
WriteRawBytes
(
bytes
);
WriteRawVarint32
((
uint
)
value
.
Length
);
value
.
WriteTo
(
this
);
}
[
CLSCompliant
(
false
)]
...
...
@@ -564,10 +562,8 @@ namespace Google.ProtocolBuffers
public
void
WriteBytesNoTag
(
ByteString
value
)
{
// TODO(jonskeet): Optimise this! (No need to copy the bytes twice.)
byte
[]
bytes
=
value
.
ToByteArray
();
WriteRawVarint32
((
uint
)
bytes
.
Length
);
WriteRawBytes
(
bytes
);
WriteRawVarint32
((
uint
)
value
.
Length
);
value
.
WriteTo
(
this
);
}
[
CLSCompliant
(
false
)]
...
...
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