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
a80a37cc
Commit
a80a37cc
authored
Aug 14, 2008
by
Jon Skeet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tidying up, and a couple of extra tests.
parent
f26f8dce
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
28 additions
and
34 deletions
+28
-34
CodedInputStreamTest.cs
csharp/ProtocolBuffers.Test/CodedInputStreamTest.cs
+25
-27
ReflectionTester.cs
csharp/ProtocolBuffers.Test/ReflectionTester.cs
+0
-1
CodedInputStream.cs
csharp/ProtocolBuffers/CodedInputStream.cs
+1
-1
DynamicMessage.cs
csharp/ProtocolBuffers/DynamicMessage.cs
+0
-1
ExtendableBuilder.cs
csharp/ProtocolBuffers/ExtendableBuilder.cs
+2
-4
No files found.
csharp/ProtocolBuffers.Test/CodedInputStreamTest.cs
View file @
a80a37cc
...
...
@@ -201,56 +201,54 @@ namespace Google.ProtocolBuffers {
}
}
/* TODO(jonskeet): Reinstate this when protoc is ready
public void
testSkipWholeMessage() throws Exception
{
TestAllTypes message = TestUtil.
g
etAllSet();
byte[] rawBytes = message.
t
oByteArray();
[
Test
]
public
void
SkipWholeMessage
()
{
TestAllTypes
message
=
TestUtil
.
G
etAllSet
();
byte
[]
rawBytes
=
message
.
T
oByteArray
();
// Create two parallel inputs. Parse one as unknown fields while using
// skipField() to skip each field on the other. Expect the same tags.
CodedInputStream input1 = CodedInputStream.
new
Instance(rawBytes);
CodedInputStream input2 = CodedInputStream.
new
Instance(rawBytes);
UnknownFieldSet.Builder unknownFields = UnknownFieldSet.
new
Builder();
CodedInputStream
input1
=
CodedInputStream
.
Create
Instance
(
rawBytes
);
CodedInputStream
input2
=
CodedInputStream
.
Create
Instance
(
rawBytes
);
UnknownFieldSet
.
Builder
unknownFields
=
UnknownFieldSet
.
Create
Builder
();
while
(
true
)
{
int tag = input1.r
eadTag();
assertEquals(tag, input2.r
eadTag());
uint
tag
=
input1
.
R
eadTag
();
Assert
.
AreEqual
(
tag
,
input2
.
R
eadTag
());
if
(
tag
==
0
)
{
break
;
}
unknownFields.
m
ergeFieldFrom(tag, input1);
input2.
s
kipField(tag);
unknownFields
.
M
ergeFieldFrom
(
tag
,
input1
);
input2
.
S
kipField
(
tag
);
}
}
*/
}
/* TODO(jonskeet): Reinstate this when protoc is ready
public void testReadHugeBlob() throws Exception {
public
void
ReadHugeBlob
()
{
// Allocate and initialize a 1MB blob.
byte
[]
blob
=
new
byte
[
1
<<
20
];
for (int i = 0; i < blob.
l
ength; i++) {
for
(
int
i
=
0
;
i
<
blob
.
L
ength
;
i
++)
{
blob
[
i
]
=
(
byte
)
i
;
}
// Make a message containing it.
TestAllTypes.Builder builder = TestAllTypes.
new
Builder();
TestUtil.
s
etAllFields(builder);
builder.
setOptionalBytes(ByteString.c
opyFrom(blob));
TestAllTypes message = builder.
b
uild();
TestAllTypes
.
Builder
builder
=
TestAllTypes
.
Create
Builder
();
TestUtil
.
S
etAllFields
(
builder
);
builder
.
SetOptionalBytes
(
ByteString
.
C
opyFrom
(
blob
));
TestAllTypes
message
=
builder
.
B
uild
();
// Serialize and parse it. Make sure to parse from an InputStream, not
// directly from a ByteString, so that CodedInputStream uses buffered
// reading.
TestAllTypes message2 =
TestAllTypes.parseFrom(message.toByteString().newInput());
TestAllTypes
message2
=
TestAllTypes
.
ParseFrom
(
message
.
ToByteString
().
CreateCodedInput
());
assertEquals(message.getOptionalBytes(), message2.getOptionalBytes()
);
Assert
.
AreEqual
(
message
.
OptionalBytes
,
message2
.
OptionalBytes
);
// Make sure all the other fields were parsed correctly.
TestAllTypes message3 = TestAllTypes.
new
Builder(message2)
.
setOptionalBytes(TestUtil.getAllSet().getOptionalBytes()
)
.
b
uild();
TestUtil.
a
ssertAllFieldsSet(message3);
}
*/
TestAllTypes
message3
=
TestAllTypes
.
Create
Builder
(
message2
)
.
SetOptionalBytes
(
TestUtil
.
GetAllSet
().
OptionalBytes
)
.
B
uild
();
TestUtil
.
A
ssertAllFieldsSet
(
message3
);
}
[
Test
]
public
void
ReadMaliciouslyLargeBlob
()
{
...
...
csharp/ProtocolBuffers.Test/ReflectionTester.cs
View file @
a80a37cc
...
...
@@ -51,7 +51,6 @@ namespace Google.ProtocolBuffers {
/// then baseDescriptor should be for TestAllExtensions instead, and instead of
/// reading and writing normal fields, the tester will read and write extensions.
/// All of the TestAllExtensions extensions must be registered in the registry.
/// TODO(jonskeet): Enforce all of these with two factory methods.
/// </summary>
private
ReflectionTester
(
MessageDescriptor
baseDescriptor
,
ExtensionRegistry
extensionRegistry
)
{
...
...
csharp/ProtocolBuffers/CodedInputStream.cs
View file @
a80a37cc
...
...
@@ -102,7 +102,7 @@ namespace Google.ProtocolBuffers {
}
#
endregion
#
region
Uncategorised
(
TODO
:
Fix
this
!)
#
region
Validation
/// <summary>
/// Verifies that the last call to ReadTag() returned the given tag value.
/// This is used to verify that a nested group ended with the correct
...
...
csharp/ProtocolBuffers/DynamicMessage.cs
View file @
a80a37cc
...
...
@@ -8,7 +8,6 @@ namespace Google.ProtocolBuffers {
/// <summary>
/// An implementation of IMessage that can represent arbitrary types, given a MessageaDescriptor.
/// TODO: Implement appropriate generics.
/// </summary>
public
class
DynamicMessage
:
AbstractMessage
<
DynamicMessage
,
DynamicMessage
.
Builder
>
{
...
...
csharp/ProtocolBuffers/ExtendableBuilder.cs
View file @
a80a37cc
...
...
@@ -95,8 +95,7 @@ namespace Google.ProtocolBuffers {
set
{
if
(
field
.
IsExtension
)
{
ExtendableMessage
<
TMessage
,
TBuilder
>
message
=
MessageBeingBuilt
;
// TODO(jonskeet): Figure out how to call this!
// message.VerifyExtensionContainingType(field);
message
.
VerifyContainingType
(
field
);
message
.
Extensions
[
field
,
index
]
=
value
;
}
else
{
base
[
field
,
index
]
=
value
;
...
...
@@ -109,8 +108,7 @@ namespace Google.ProtocolBuffers {
set
{
if
(
field
.
IsExtension
)
{
ExtendableMessage
<
TMessage
,
TBuilder
>
message
=
MessageBeingBuilt
;
// TODO(jonskeet): Figure out how to call this!
// message.VerifyExtensionContainingType(field);
message
.
VerifyContainingType
(
field
);
message
.
Extensions
[
field
]
=
value
;
}
else
{
base
[
field
]
=
value
;
...
...
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