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
5d7adf66
Commit
5d7adf66
authored
Aug 14, 2008
by
Jon Skeet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
First unit test reading a complete message\!
parent
3f9a6f21
Show whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
416 additions
and
52 deletions
+416
-52
CodedInputStreamTest.cs
csharp/ProtocolBuffers.Test/CodedInputStreamTest.cs
+11
-11
TestUtil.cs
csharp/ProtocolBuffers.Test/TestUtil.cs
+334
-0
AbstractBuilder.cs
csharp/ProtocolBuffers/AbstractBuilder.cs
+9
-5
ByteString.cs
csharp/ProtocolBuffers/ByteString.cs
+29
-1
CodedInputStream.cs
csharp/ProtocolBuffers/CodedInputStream.cs
+2
-2
CodedOutputStream.cs
csharp/ProtocolBuffers/CodedOutputStream.cs
+3
-2
FieldDescriptor.cs
csharp/ProtocolBuffers/Descriptors/FieldDescriptor.cs
+2
-3
MessageDescriptor.cs
csharp/ProtocolBuffers/Descriptors/MessageDescriptor.cs
+4
-4
RepeatedMessageAccessor.cs
...rp/ProtocolBuffers/FieldAccess/RepeatedMessageAccessor.cs
+1
-1
RepeatedPrimitiveAccessor.cs
.../ProtocolBuffers/FieldAccess/RepeatedPrimitiveAccessor.cs
+2
-5
SingleMessageAccessor.cs
csharp/ProtocolBuffers/FieldAccess/SingleMessageAccessor.cs
+1
-1
FieldSet.cs
csharp/ProtocolBuffers/FieldSet.cs
+5
-13
GeneratedBuilder.cs
csharp/ProtocolBuffers/GeneratedBuilder.cs
+9
-0
TextFormat.cs
csharp/ProtocolBuffers/TextFormat.cs
+4
-4
No files found.
csharp/ProtocolBuffers.Test/CodedInputStreamTest.cs
View file @
5d7adf66
...
@@ -15,6 +15,7 @@
...
@@ -15,6 +15,7 @@
// limitations under the License.
// limitations under the License.
using
System
;
using
System
;
using
System.IO
;
using
System.IO
;
using
Google.ProtocolBuffers.TestProtos
;
using
NUnit.Framework
;
using
NUnit.Framework
;
namespace
Google.ProtocolBuffers
{
namespace
Google.ProtocolBuffers
{
...
@@ -183,23 +184,22 @@ namespace Google.ProtocolBuffers {
...
@@ -183,23 +184,22 @@ namespace Google.ProtocolBuffers {
Assert
.
AreEqual
(
unchecked
((
long
)
0x8000000000000000L
),
CodedInputStream
.
DecodeZigZag64
(
0xFFFFFFFFFFFFFFFFL
));
Assert
.
AreEqual
(
unchecked
((
long
)
0x8000000000000000L
),
CodedInputStream
.
DecodeZigZag64
(
0xFFFFFFFFFFFFFFFFL
));
}
}
/* TODO(jonskeet): Reinstate this when protoc is ready
[
Test
]
public void
testReadWholeMessage() throws Exception
{
public
void
ReadWholeMessage
()
{
TestAllTypes message = TestUtil.
g
etAllSet();
TestAllTypes
message
=
TestUtil
.
G
etAllSet
();
byte[] rawBytes = message.
t
oByteArray();
byte
[]
rawBytes
=
message
.
T
oByteArray
();
assertEquals(rawBytes.length, message.getSerializedSize()
);
Assert
.
AreEqual
(
rawBytes
.
Length
,
message
.
SerializedSize
);
TestAllTypes message2 = TestAllTypes.
p
arseFrom(rawBytes);
TestAllTypes
message2
=
TestAllTypes
.
P
arseFrom
(
rawBytes
);
TestUtil.
a
ssertAllFieldsSet(message2);
TestUtil
.
A
ssertAllFieldsSet
(
message2
);
// Try different block sizes.
// Try different block sizes.
for
(
int
blockSize
=
1
;
blockSize
<
256
;
blockSize
*=
2
)
{
for
(
int
blockSize
=
1
;
blockSize
<
256
;
blockSize
*=
2
)
{
message2 = TestAllTypes.
parseFrom(
message2
=
TestAllTypes
.
ParseFrom
(
new
SmallBlockInputStream
(
rawBytes
,
blockSize
));
new SmallBlockInputStream(rawBytes, blockSize)
);
TestUtil
.
AssertAllFieldsSet
(
message2
);
TestUtil.assertAllFieldsSet(message2);
}
}
}
}*/
/* TODO(jonskeet): Reinstate this when protoc is ready
/* TODO(jonskeet): Reinstate this when protoc is ready
public void testSkipWholeMessage() throws Exception {
public void testSkipWholeMessage() throws Exception {
...
...
csharp/ProtocolBuffers.Test/TestUtil.cs
View file @
5d7adf66
...
@@ -2,6 +2,8 @@
...
@@ -2,6 +2,8 @@
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System.Text
;
using
System.Text
;
using
System.IO
;
using
System.IO
;
using
Google.ProtocolBuffers.TestProtos
;
using
NUnit.Framework
;
namespace
Google.ProtocolBuffers
{
namespace
Google.ProtocolBuffers
{
internal
static
class
TestUtil
{
internal
static
class
TestUtil
{
...
@@ -28,5 +30,337 @@ namespace Google.ProtocolBuffers {
...
@@ -28,5 +30,337 @@ namespace Google.ProtocolBuffers {
throw
new
Exception
(
"Unable to find directory containing test files"
);
throw
new
Exception
(
"Unable to find directory containing test files"
);
}
}
}
}
/// <summary>
/// Helper to convert a String to ByteString.
/// </summary>
private
static
ByteString
ToBytes
(
String
str
)
{
return
ByteString
.
CopyFrom
(
Encoding
.
UTF8
.
GetBytes
(
str
));
}
internal
static
TestAllTypes
GetAllSet
()
{
TestAllTypes
.
Builder
builder
=
TestAllTypes
.
CreateBuilder
();
SetAllFields
(
builder
);
return
builder
.
Build
();
}
/// <summary>
/// Sets every field of the specified message to the values expected by
/// AssertAllFieldsSet.
/// </summary>
internal
static
void
SetAllFields
(
TestAllTypes
.
Builder
message
)
{
message
.
SetOptionalInt32
(
101
);
message
.
SetOptionalInt64
(
102
);
message
.
SetOptionalUint32
(
103
);
message
.
SetOptionalUint64
(
104
);
message
.
SetOptionalSint32
(
105
);
message
.
SetOptionalSint64
(
106
);
message
.
SetOptionalFixed32
(
107
);
message
.
SetOptionalFixed64
(
108
);
message
.
SetOptionalSfixed32
(
109
);
message
.
SetOptionalSfixed64
(
110
);
message
.
SetOptionalFloat
(
111
);
message
.
SetOptionalDouble
(
112
);
message
.
SetOptionalBool
(
true
);
message
.
SetOptionalString
(
"115"
);
message
.
SetOptionalBytes
(
ToBytes
(
"116"
));
message
.
SetOptionalGroup
(
TestAllTypes
.
Types
.
OptionalGroup
.
CreateBuilder
().
SetA
(
117
).
Build
());
message
.
SetOptionalNestedMessage
(
TestAllTypes
.
Types
.
NestedMessage
.
CreateBuilder
().
SetBb
(
118
).
Build
());
message
.
SetOptionalForeignMessage
(
ForeignMessage
.
CreateBuilder
().
SetC
(
119
).
Build
());
message
.
SetOptionalImportMessage
(
ImportMessage
.
CreateBuilder
().
SetD
(
120
).
Build
());
message
.
SetOptionalNestedEnum
(
TestAllTypes
.
Types
.
NestedEnum
.
BAZ
);
message
.
SetOptionalForeignEnum
(
ForeignEnum
.
FOREIGN_BAZ
);
message
.
SetOptionalImportEnum
(
ImportEnum
.
IMPORT_BAZ
);
message
.
SetOptionalStringPiece
(
"124"
);
message
.
SetOptionalCord
(
"125"
);
// -----------------------------------------------------------------
message
.
AddRepeatedInt32
(
201
);
message
.
AddRepeatedInt64
(
202
);
message
.
AddRepeatedUint32
(
203
);
message
.
AddRepeatedUint64
(
204
);
message
.
AddRepeatedSint32
(
205
);
message
.
AddRepeatedSint64
(
206
);
message
.
AddRepeatedFixed32
(
207
);
message
.
AddRepeatedFixed64
(
208
);
message
.
AddRepeatedSfixed32
(
209
);
message
.
AddRepeatedSfixed64
(
210
);
message
.
AddRepeatedFloat
(
211
);
message
.
AddRepeatedDouble
(
212
);
message
.
AddRepeatedBool
(
true
);
message
.
AddRepeatedString
(
"215"
);
message
.
AddRepeatedBytes
(
ToBytes
(
"216"
));
message
.
AddRepeatedGroup
(
TestAllTypes
.
Types
.
RepeatedGroup
.
CreateBuilder
().
SetA
(
217
).
Build
());
message
.
AddRepeatedNestedMessage
(
TestAllTypes
.
Types
.
NestedMessage
.
CreateBuilder
().
SetBb
(
218
).
Build
());
message
.
AddRepeatedForeignMessage
(
ForeignMessage
.
CreateBuilder
().
SetC
(
219
).
Build
());
message
.
AddRepeatedImportMessage
(
ImportMessage
.
CreateBuilder
().
SetD
(
220
).
Build
());
message
.
AddRepeatedNestedEnum
(
TestAllTypes
.
Types
.
NestedEnum
.
BAR
);
message
.
AddRepeatedForeignEnum
(
ForeignEnum
.
FOREIGN_BAR
);
message
.
AddRepeatedImportEnum
(
ImportEnum
.
IMPORT_BAR
);
message
.
AddRepeatedStringPiece
(
"224"
);
message
.
AddRepeatedCord
(
"225"
);
// Add a second one of each field.
message
.
AddRepeatedInt32
(
301
);
message
.
AddRepeatedInt64
(
302
);
message
.
AddRepeatedUint32
(
303
);
message
.
AddRepeatedUint64
(
304
);
message
.
AddRepeatedSint32
(
305
);
message
.
AddRepeatedSint64
(
306
);
message
.
AddRepeatedFixed32
(
307
);
message
.
AddRepeatedFixed64
(
308
);
message
.
AddRepeatedSfixed32
(
309
);
message
.
AddRepeatedSfixed64
(
310
);
message
.
AddRepeatedFloat
(
311
);
message
.
AddRepeatedDouble
(
312
);
message
.
AddRepeatedBool
(
false
);
message
.
AddRepeatedString
(
"315"
);
message
.
AddRepeatedBytes
(
ToBytes
(
"316"
));
message
.
AddRepeatedGroup
(
TestAllTypes
.
Types
.
RepeatedGroup
.
CreateBuilder
().
SetA
(
317
).
Build
());
message
.
AddRepeatedNestedMessage
(
TestAllTypes
.
Types
.
NestedMessage
.
CreateBuilder
().
SetBb
(
318
).
Build
());
message
.
AddRepeatedForeignMessage
(
ForeignMessage
.
CreateBuilder
().
SetC
(
319
).
Build
());
message
.
AddRepeatedImportMessage
(
ImportMessage
.
CreateBuilder
().
SetD
(
320
).
Build
());
message
.
AddRepeatedNestedEnum
(
TestAllTypes
.
Types
.
NestedEnum
.
BAZ
);
message
.
AddRepeatedForeignEnum
(
ForeignEnum
.
FOREIGN_BAZ
);
message
.
AddRepeatedImportEnum
(
ImportEnum
.
IMPORT_BAZ
);
message
.
AddRepeatedStringPiece
(
"324"
);
message
.
AddRepeatedCord
(
"325"
);
// -----------------------------------------------------------------
message
.
SetDefaultInt32
(
401
);
message
.
SetDefaultInt64
(
402
);
message
.
SetDefaultUint32
(
403
);
message
.
SetDefaultUint64
(
404
);
message
.
SetDefaultSint32
(
405
);
message
.
SetDefaultSint64
(
406
);
message
.
SetDefaultFixed32
(
407
);
message
.
SetDefaultFixed64
(
408
);
message
.
SetDefaultSfixed32
(
409
);
message
.
SetDefaultSfixed64
(
410
);
message
.
SetDefaultFloat
(
411
);
message
.
SetDefaultDouble
(
412
);
message
.
SetDefaultBool
(
false
);
message
.
SetDefaultString
(
"415"
);
message
.
SetDefaultBytes
(
ToBytes
(
"416"
));
message
.
SetDefaultNestedEnum
(
TestAllTypes
.
Types
.
NestedEnum
.
FOO
);
message
.
SetDefaultForeignEnum
(
ForeignEnum
.
FOREIGN_FOO
);
message
.
SetDefaultImportEnum
(
ImportEnum
.
IMPORT_FOO
);
message
.
SetDefaultStringPiece
(
"424"
);
message
.
SetDefaultCord
(
"425"
);
}
/// <summary>
/// Asserts that all fields of the specified message are set to the values
/// assigned by SetAllFields.
/// </summary>
internal
static
void
AssertAllFieldsSet
(
TestAllTypes
message
)
{
Assert
.
IsTrue
(
message
.
HasOptionalInt32
);
Assert
.
IsTrue
(
message
.
HasOptionalInt64
);
Assert
.
IsTrue
(
message
.
HasOptionalUint32
);
Assert
.
IsTrue
(
message
.
HasOptionalUint64
);
Assert
.
IsTrue
(
message
.
HasOptionalSint32
);
Assert
.
IsTrue
(
message
.
HasOptionalSint64
);
Assert
.
IsTrue
(
message
.
HasOptionalFixed32
);
Assert
.
IsTrue
(
message
.
HasOptionalFixed64
);
Assert
.
IsTrue
(
message
.
HasOptionalSfixed32
);
Assert
.
IsTrue
(
message
.
HasOptionalSfixed64
);
Assert
.
IsTrue
(
message
.
HasOptionalFloat
);
Assert
.
IsTrue
(
message
.
HasOptionalDouble
);
Assert
.
IsTrue
(
message
.
HasOptionalBool
);
Assert
.
IsTrue
(
message
.
HasOptionalString
);
Assert
.
IsTrue
(
message
.
HasOptionalBytes
);
Assert
.
IsTrue
(
message
.
HasOptionalGroup
);
Assert
.
IsTrue
(
message
.
HasOptionalNestedMessage
);
Assert
.
IsTrue
(
message
.
HasOptionalForeignMessage
);
Assert
.
IsTrue
(
message
.
HasOptionalImportMessage
);
Assert
.
IsTrue
(
message
.
OptionalGroup
.
HasA
);
Assert
.
IsTrue
(
message
.
OptionalNestedMessage
.
HasBb
);
Assert
.
IsTrue
(
message
.
OptionalForeignMessage
.
HasC
);
Assert
.
IsTrue
(
message
.
OptionalImportMessage
.
HasD
);
Assert
.
IsTrue
(
message
.
HasOptionalNestedEnum
);
Assert
.
IsTrue
(
message
.
HasOptionalForeignEnum
);
Assert
.
IsTrue
(
message
.
HasOptionalImportEnum
);
Assert
.
IsTrue
(
message
.
HasOptionalStringPiece
);
Assert
.
IsTrue
(
message
.
HasOptionalCord
);
Assert
.
AreEqual
(
101
,
message
.
OptionalInt32
);
Assert
.
AreEqual
(
102
,
message
.
OptionalInt64
);
Assert
.
AreEqual
(
103
,
message
.
OptionalUint32
);
Assert
.
AreEqual
(
104
,
message
.
OptionalUint64
);
Assert
.
AreEqual
(
105
,
message
.
OptionalSint32
);
Assert
.
AreEqual
(
106
,
message
.
OptionalSint64
);
Assert
.
AreEqual
(
107
,
message
.
OptionalFixed32
);
Assert
.
AreEqual
(
108
,
message
.
OptionalFixed64
);
Assert
.
AreEqual
(
109
,
message
.
OptionalSfixed32
);
Assert
.
AreEqual
(
110
,
message
.
OptionalSfixed64
);
Assert
.
AreEqual
(
111
,
message
.
OptionalFloat
);
Assert
.
AreEqual
(
112
,
message
.
OptionalDouble
);
Assert
.
AreEqual
(
true
,
message
.
OptionalBool
);
Assert
.
AreEqual
(
"115"
,
message
.
OptionalString
);
Assert
.
AreEqual
(
ToBytes
(
"116"
),
message
.
OptionalBytes
);
Assert
.
AreEqual
(
117
,
message
.
OptionalGroup
.
A
);
Assert
.
AreEqual
(
118
,
message
.
OptionalNestedMessage
.
Bb
);
Assert
.
AreEqual
(
119
,
message
.
OptionalForeignMessage
.
C
);
Assert
.
AreEqual
(
120
,
message
.
OptionalImportMessage
.
D
);
Assert
.
AreEqual
(
TestAllTypes
.
Types
.
NestedEnum
.
BAZ
,
message
.
OptionalNestedEnum
);
Assert
.
AreEqual
(
ForeignEnum
.
FOREIGN_BAZ
,
message
.
OptionalForeignEnum
);
Assert
.
AreEqual
(
ImportEnum
.
IMPORT_BAZ
,
message
.
OptionalImportEnum
);
Assert
.
AreEqual
(
"124"
,
message
.
OptionalStringPiece
);
Assert
.
AreEqual
(
"125"
,
message
.
OptionalCord
);
// -----------------------------------------------------------------
Assert
.
AreEqual
(
2
,
message
.
RepeatedInt32Count
);
Assert
.
AreEqual
(
2
,
message
.
RepeatedInt64Count
);
Assert
.
AreEqual
(
2
,
message
.
RepeatedUint32Count
);
Assert
.
AreEqual
(
2
,
message
.
RepeatedUint64Count
);
Assert
.
AreEqual
(
2
,
message
.
RepeatedSint32Count
);
Assert
.
AreEqual
(
2
,
message
.
RepeatedSint64Count
);
Assert
.
AreEqual
(
2
,
message
.
RepeatedFixed32Count
);
Assert
.
AreEqual
(
2
,
message
.
RepeatedFixed64Count
);
Assert
.
AreEqual
(
2
,
message
.
RepeatedSfixed32Count
);
Assert
.
AreEqual
(
2
,
message
.
RepeatedSfixed64Count
);
Assert
.
AreEqual
(
2
,
message
.
RepeatedFloatCount
);
Assert
.
AreEqual
(
2
,
message
.
RepeatedDoubleCount
);
Assert
.
AreEqual
(
2
,
message
.
RepeatedBoolCount
);
Assert
.
AreEqual
(
2
,
message
.
RepeatedStringCount
);
Assert
.
AreEqual
(
2
,
message
.
RepeatedBytesCount
);
Assert
.
AreEqual
(
2
,
message
.
RepeatedGroupCount
);
Assert
.
AreEqual
(
2
,
message
.
RepeatedNestedMessageCount
);
Assert
.
AreEqual
(
2
,
message
.
RepeatedForeignMessageCount
);
Assert
.
AreEqual
(
2
,
message
.
RepeatedImportMessageCount
);
Assert
.
AreEqual
(
2
,
message
.
RepeatedNestedEnumCount
);
Assert
.
AreEqual
(
2
,
message
.
RepeatedForeignEnumCount
);
Assert
.
AreEqual
(
2
,
message
.
RepeatedImportEnumCount
);
Assert
.
AreEqual
(
2
,
message
.
RepeatedStringPieceCount
);
Assert
.
AreEqual
(
2
,
message
.
RepeatedCordCount
);
Assert
.
AreEqual
(
201
,
message
.
GetRepeatedInt32
(
0
));
Assert
.
AreEqual
(
202
,
message
.
GetRepeatedInt64
(
0
));
Assert
.
AreEqual
(
203
,
message
.
GetRepeatedUint32
(
0
));
Assert
.
AreEqual
(
204
,
message
.
GetRepeatedUint64
(
0
));
Assert
.
AreEqual
(
205
,
message
.
GetRepeatedSint32
(
0
));
Assert
.
AreEqual
(
206
,
message
.
GetRepeatedSint64
(
0
));
Assert
.
AreEqual
(
207
,
message
.
GetRepeatedFixed32
(
0
));
Assert
.
AreEqual
(
208
,
message
.
GetRepeatedFixed64
(
0
));
Assert
.
AreEqual
(
209
,
message
.
GetRepeatedSfixed32
(
0
));
Assert
.
AreEqual
(
210
,
message
.
GetRepeatedSfixed64
(
0
));
Assert
.
AreEqual
(
211
,
message
.
GetRepeatedFloat
(
0
));
Assert
.
AreEqual
(
212
,
message
.
GetRepeatedDouble
(
0
));
Assert
.
AreEqual
(
true
,
message
.
GetRepeatedBool
(
0
));
Assert
.
AreEqual
(
"215"
,
message
.
GetRepeatedString
(
0
));
Assert
.
AreEqual
(
ToBytes
(
"216"
),
message
.
GetRepeatedBytes
(
0
));
Assert
.
AreEqual
(
217
,
message
.
GetRepeatedGroup
(
0
).
A
);
Assert
.
AreEqual
(
218
,
message
.
GetRepeatedNestedMessage
(
0
).
Bb
);
Assert
.
AreEqual
(
219
,
message
.
GetRepeatedForeignMessage
(
0
).
C
);
Assert
.
AreEqual
(
220
,
message
.
GetRepeatedImportMessage
(
0
).
D
);
Assert
.
AreEqual
(
TestAllTypes
.
Types
.
NestedEnum
.
BAR
,
message
.
GetRepeatedNestedEnum
(
0
));
Assert
.
AreEqual
(
ForeignEnum
.
FOREIGN_BAR
,
message
.
GetRepeatedForeignEnum
(
0
));
Assert
.
AreEqual
(
ImportEnum
.
IMPORT_BAR
,
message
.
GetRepeatedImportEnum
(
0
));
Assert
.
AreEqual
(
"224"
,
message
.
GetRepeatedStringPiece
(
0
));
Assert
.
AreEqual
(
"225"
,
message
.
GetRepeatedCord
(
0
));
Assert
.
AreEqual
(
301
,
message
.
GetRepeatedInt32
(
1
));
Assert
.
AreEqual
(
302
,
message
.
GetRepeatedInt64
(
1
));
Assert
.
AreEqual
(
303
,
message
.
GetRepeatedUint32
(
1
));
Assert
.
AreEqual
(
304
,
message
.
GetRepeatedUint64
(
1
));
Assert
.
AreEqual
(
305
,
message
.
GetRepeatedSint32
(
1
));
Assert
.
AreEqual
(
306
,
message
.
GetRepeatedSint64
(
1
));
Assert
.
AreEqual
(
307
,
message
.
GetRepeatedFixed32
(
1
));
Assert
.
AreEqual
(
308
,
message
.
GetRepeatedFixed64
(
1
));
Assert
.
AreEqual
(
309
,
message
.
GetRepeatedSfixed32
(
1
));
Assert
.
AreEqual
(
310
,
message
.
GetRepeatedSfixed64
(
1
));
Assert
.
AreEqual
(
311
,
message
.
GetRepeatedFloat
(
1
),
0.0
);
Assert
.
AreEqual
(
312
,
message
.
GetRepeatedDouble
(
1
),
0.0
);
Assert
.
AreEqual
(
false
,
message
.
GetRepeatedBool
(
1
));
Assert
.
AreEqual
(
"315"
,
message
.
GetRepeatedString
(
1
));
Assert
.
AreEqual
(
ToBytes
(
"316"
),
message
.
GetRepeatedBytes
(
1
));
Assert
.
AreEqual
(
317
,
message
.
GetRepeatedGroup
(
1
).
A
);
Assert
.
AreEqual
(
318
,
message
.
GetRepeatedNestedMessage
(
1
).
Bb
);
Assert
.
AreEqual
(
319
,
message
.
GetRepeatedForeignMessage
(
1
).
C
);
Assert
.
AreEqual
(
320
,
message
.
GetRepeatedImportMessage
(
1
).
D
);
Assert
.
AreEqual
(
TestAllTypes
.
Types
.
NestedEnum
.
BAZ
,
message
.
GetRepeatedNestedEnum
(
1
));
Assert
.
AreEqual
(
ForeignEnum
.
FOREIGN_BAZ
,
message
.
GetRepeatedForeignEnum
(
1
));
Assert
.
AreEqual
(
ImportEnum
.
IMPORT_BAZ
,
message
.
GetRepeatedImportEnum
(
1
));
Assert
.
AreEqual
(
"324"
,
message
.
GetRepeatedStringPiece
(
1
));
Assert
.
AreEqual
(
"325"
,
message
.
GetRepeatedCord
(
1
));
// -----------------------------------------------------------------
Assert
.
IsTrue
(
message
.
HasDefaultInt32
);
Assert
.
IsTrue
(
message
.
HasDefaultInt64
);
Assert
.
IsTrue
(
message
.
HasDefaultUint32
);
Assert
.
IsTrue
(
message
.
HasDefaultUint64
);
Assert
.
IsTrue
(
message
.
HasDefaultSint32
);
Assert
.
IsTrue
(
message
.
HasDefaultSint64
);
Assert
.
IsTrue
(
message
.
HasDefaultFixed32
);
Assert
.
IsTrue
(
message
.
HasDefaultFixed64
);
Assert
.
IsTrue
(
message
.
HasDefaultSfixed32
);
Assert
.
IsTrue
(
message
.
HasDefaultSfixed64
);
Assert
.
IsTrue
(
message
.
HasDefaultFloat
);
Assert
.
IsTrue
(
message
.
HasDefaultDouble
);
Assert
.
IsTrue
(
message
.
HasDefaultBool
);
Assert
.
IsTrue
(
message
.
HasDefaultString
);
Assert
.
IsTrue
(
message
.
HasDefaultBytes
);
Assert
.
IsTrue
(
message
.
HasDefaultNestedEnum
);
Assert
.
IsTrue
(
message
.
HasDefaultForeignEnum
);
Assert
.
IsTrue
(
message
.
HasDefaultImportEnum
);
Assert
.
IsTrue
(
message
.
HasDefaultStringPiece
);
Assert
.
IsTrue
(
message
.
HasDefaultCord
);
Assert
.
AreEqual
(
401
,
message
.
DefaultInt32
);
Assert
.
AreEqual
(
402
,
message
.
DefaultInt64
);
Assert
.
AreEqual
(
403
,
message
.
DefaultUint32
);
Assert
.
AreEqual
(
404
,
message
.
DefaultUint64
);
Assert
.
AreEqual
(
405
,
message
.
DefaultSint32
);
Assert
.
AreEqual
(
406
,
message
.
DefaultSint64
);
Assert
.
AreEqual
(
407
,
message
.
DefaultFixed32
);
Assert
.
AreEqual
(
408
,
message
.
DefaultFixed64
);
Assert
.
AreEqual
(
409
,
message
.
DefaultSfixed32
);
Assert
.
AreEqual
(
410
,
message
.
DefaultSfixed64
);
Assert
.
AreEqual
(
411
,
message
.
DefaultFloat
);
Assert
.
AreEqual
(
412
,
message
.
DefaultDouble
);
Assert
.
AreEqual
(
false
,
message
.
DefaultBool
);
Assert
.
AreEqual
(
"415"
,
message
.
DefaultString
);
Assert
.
AreEqual
(
ToBytes
(
"416"
),
message
.
DefaultBytes
);
Assert
.
AreEqual
(
TestAllTypes
.
Types
.
NestedEnum
.
FOO
,
message
.
DefaultNestedEnum
);
Assert
.
AreEqual
(
ForeignEnum
.
FOREIGN_FOO
,
message
.
DefaultForeignEnum
);
Assert
.
AreEqual
(
ImportEnum
.
IMPORT_FOO
,
message
.
DefaultImportEnum
);
Assert
.
AreEqual
(
"424"
,
message
.
DefaultStringPiece
);
Assert
.
AreEqual
(
"425"
,
message
.
DefaultCord
);
}
}
}
}
}
csharp/ProtocolBuffers/AbstractBuilder.cs
View file @
5d7adf66
...
@@ -104,16 +104,20 @@ namespace Google.ProtocolBuffers {
...
@@ -104,16 +104,20 @@ namespace Google.ProtocolBuffers {
}
}
IBuilder
IBuilder
.
MergeFrom
(
CodedInputStream
input
)
{
IBuilder
IBuilder
.
MergeFrom
(
CodedInputStream
input
)
{
return
((
IBuilder
)
this
).
MergeFrom
(
input
,
ExtensionRegistry
.
Empty
);
return
MergeFromImpl
(
input
,
ExtensionRegistry
.
Empty
);
}
}
IBuilder
IBuilder
.
MergeFrom
(
CodedInputStream
input
,
ExtensionRegistry
extensionRegistry
)
{
protected
virtual
IBuilder
MergeFromImpl
(
CodedInputStream
input
,
ExtensionRegistry
extensionRegistry
)
{
UnknownFieldSet
.
Builder
unknownFields
=
UnknownFieldSet
.
CreateBuilder
(
UnknownFields
);
UnknownFieldSet
.
Builder
unknownFields
=
UnknownFieldSet
.
CreateBuilder
(
UnknownFields
);
FieldSet
.
MergeFrom
(
input
,
unknownFields
,
extensionRegistry
,
this
);
FieldSet
.
MergeFrom
(
input
,
unknownFields
,
extensionRegistry
,
this
);
UnknownFields
=
unknownFields
.
Build
();
UnknownFields
=
unknownFields
.
Build
();
return
this
;
return
this
;
}
}
IBuilder
IBuilder
.
MergeFrom
(
CodedInputStream
input
,
ExtensionRegistry
extensionRegistry
)
{
return
MergeFromImpl
(
input
,
extensionRegistry
);
}
IBuilder
IBuilder
.
MergeUnknownFields
(
UnknownFieldSet
unknownFields
)
{
IBuilder
IBuilder
.
MergeUnknownFields
(
UnknownFieldSet
unknownFields
)
{
UnknownFields
=
UnknownFieldSet
.
CreateBuilder
(
UnknownFields
)
UnknownFields
=
UnknownFieldSet
.
CreateBuilder
(
UnknownFields
)
.
MergeFrom
(
unknownFields
)
.
MergeFrom
(
unknownFields
)
...
@@ -121,8 +125,6 @@ namespace Google.ProtocolBuffers {
...
@@ -121,8 +125,6 @@ namespace Google.ProtocolBuffers {
return
this
;
return
this
;
}
}
public
UnknownFieldSet
UnknownFields
{
get
;
set
;
}
IBuilder
IBuilder
.
MergeFrom
(
ByteString
data
)
{
IBuilder
IBuilder
.
MergeFrom
(
ByteString
data
)
{
CodedInputStream
input
=
data
.
CreateCodedInput
();
CodedInputStream
input
=
data
.
CreateCodedInput
();
((
IBuilder
)
this
).
MergeFrom
(
input
);
((
IBuilder
)
this
).
MergeFrom
(
input
);
...
@@ -160,9 +162,11 @@ namespace Google.ProtocolBuffers {
...
@@ -160,9 +162,11 @@ namespace Google.ProtocolBuffers {
IBuilder
IBuilder
.
MergeFrom
(
Stream
input
,
ExtensionRegistry
extensionRegistry
)
{
IBuilder
IBuilder
.
MergeFrom
(
Stream
input
,
ExtensionRegistry
extensionRegistry
)
{
CodedInputStream
codedInput
=
CodedInputStream
.
CreateInstance
(
input
);
CodedInputStream
codedInput
=
CodedInputStream
.
CreateInstance
(
input
);
((
IBuilder
)
this
).
MergeFrom
(
codedInput
,
extensionRegistry
);
((
IBuilder
)
this
).
MergeFrom
(
codedInput
,
extensionRegistry
);
codedInput
.
CheckLastTagWas
(
0
);
codedInput
.
CheckLastTagWas
(
0
);
return
this
;
return
this
;
}
}
public
abstract
UnknownFieldSet
UnknownFields
{
get
;
set
;
}
}
}
}
}
csharp/ProtocolBuffers/ByteString.cs
View file @
5d7adf66
...
@@ -23,7 +23,7 @@ namespace Google.ProtocolBuffers {
...
@@ -23,7 +23,7 @@ namespace Google.ProtocolBuffers {
/// Immutable array of bytes.
/// Immutable array of bytes.
/// TODO(jonskeet): Implement the common collection interfaces?
/// TODO(jonskeet): Implement the common collection interfaces?
/// </summary>
/// </summary>
public
sealed
class
ByteString
:
IEnumerable
<
byte
>
{
public
sealed
class
ByteString
:
IEnumerable
<
byte
>
,
IEquatable
<
ByteString
>
{
private
static
readonly
ByteString
empty
=
new
ByteString
(
new
byte
[
0
]);
private
static
readonly
ByteString
empty
=
new
ByteString
(
new
byte
[
0
]);
...
@@ -126,6 +126,34 @@ namespace Google.ProtocolBuffers {
...
@@ -126,6 +126,34 @@ namespace Google.ProtocolBuffers {
// TODO(jonskeet): CopyTo, Equals, GetHashCode if they turn out to be required
// TODO(jonskeet): CopyTo, Equals, GetHashCode if they turn out to be required
public
override
bool
Equals
(
object
obj
)
{
ByteString
other
=
obj
as
ByteString
;
if
(
obj
==
null
)
{
return
false
;
}
return
Equals
(
other
);
}
public
override
int
GetHashCode
()
{
int
ret
=
23
;
foreach
(
byte
b
in
bytes
)
{
ret
=
(
ret
<<
8
)
|
b
;
}
return
ret
;
}
public
bool
Equals
(
ByteString
other
)
{
if
(
other
.
bytes
.
Length
!=
bytes
.
Length
)
{
return
false
;
}
for
(
int
i
=
0
;
i
<
bytes
.
Length
;
i
++)
{
if
(
other
.
bytes
[
i
]
!=
bytes
[
i
])
{
return
false
;
}
}
return
true
;
}
/// <summary>
/// <summary>
/// Builder for ByteStrings which allows them to be created without extra
/// Builder for ByteStrings which allows them to be created without extra
/// copying being involved. This has to be a nested type in order to have access
/// copying being involved. This has to be a nested type in order to have access
...
...
csharp/ProtocolBuffers/CodedInputStream.cs
View file @
5d7adf66
...
@@ -569,8 +569,8 @@ namespace Google.ProtocolBuffers {
...
@@ -569,8 +569,8 @@ namespace Google.ProtocolBuffers {
totalBytesRetired
+=
bufferSize
;
totalBytesRetired
+=
bufferSize
;
bufferPos
=
0
;
bufferPos
=
0
;
bufferSize
=
(
input
==
null
)
?
-
1
:
input
.
Read
(
buffer
,
0
,
buffer
.
Length
);
bufferSize
=
(
input
==
null
)
?
0
:
input
.
Read
(
buffer
,
0
,
buffer
.
Length
);
if
(
bufferSize
==
-
1
)
{
if
(
bufferSize
==
0
)
{
bufferSize
=
0
;
bufferSize
=
0
;
if
(
mustSucceed
)
{
if
(
mustSucceed
)
{
throw
InvalidProtocolBufferException
.
TruncatedMessage
();
throw
InvalidProtocolBufferException
.
TruncatedMessage
();
...
...
csharp/ProtocolBuffers/CodedOutputStream.cs
View file @
5d7adf66
...
@@ -206,6 +206,7 @@ namespace Google.ProtocolBuffers {
...
@@ -206,6 +206,7 @@ namespace Google.ProtocolBuffers {
public
void
WriteBytes
(
int
fieldNumber
,
ByteString
value
)
{
public
void
WriteBytes
(
int
fieldNumber
,
ByteString
value
)
{
// TODO(jonskeet): Optimise this! (No need to copy the bytes twice.)
// TODO(jonskeet): Optimise this! (No need to copy the bytes twice.)
WriteTag
(
fieldNumber
,
WireFormat
.
WireType
.
LengthDelimited
);
byte
[]
bytes
=
value
.
ToByteArray
();
byte
[]
bytes
=
value
.
ToByteArray
();
WriteRawVarint32
((
uint
)
bytes
.
Length
);
WriteRawVarint32
((
uint
)
bytes
.
Length
);
WriteRawBytes
(
bytes
);
WriteRawBytes
(
bytes
);
...
@@ -223,12 +224,12 @@ namespace Google.ProtocolBuffers {
...
@@ -223,12 +224,12 @@ namespace Google.ProtocolBuffers {
public
void
WriteSFixed32
(
int
fieldNumber
,
int
value
)
{
public
void
WriteSFixed32
(
int
fieldNumber
,
int
value
)
{
WriteTag
(
fieldNumber
,
WireFormat
.
WireType
.
Fixed32
);
WriteTag
(
fieldNumber
,
WireFormat
.
WireType
.
Fixed32
);
WriteRaw
Varint
32
((
uint
)
value
);
WriteRaw
LittleEndian
32
((
uint
)
value
);
}
}
public
void
WriteSFixed64
(
int
fieldNumber
,
long
value
)
{
public
void
WriteSFixed64
(
int
fieldNumber
,
long
value
)
{
WriteTag
(
fieldNumber
,
WireFormat
.
WireType
.
Fixed64
);
WriteTag
(
fieldNumber
,
WireFormat
.
WireType
.
Fixed64
);
WriteRaw
Varint
64
((
ulong
)
value
);
WriteRaw
LittleEndian
64
((
ulong
)
value
);
}
}
public
void
WriteSInt32
(
int
fieldNumber
,
int
value
)
{
public
void
WriteSInt32
(
int
fieldNumber
,
int
value
)
{
...
...
csharp/ProtocolBuffers/Descriptors/FieldDescriptor.cs
View file @
5d7adf66
...
@@ -22,7 +22,7 @@ namespace Google.ProtocolBuffers.Descriptors {
...
@@ -22,7 +22,7 @@ namespace Google.ProtocolBuffers.Descriptors {
if
(
proto
.
HasType
)
{
if
(
proto
.
HasType
)
{
fieldType
=
GetFieldTypeFromProtoType
(
proto
.
Type
);
fieldType
=
GetFieldTypeFromProtoType
(
proto
.
Type
);
//type = proto.Type
;
mappedType
=
FieldTypeToMappedTypeMap
[
fieldType
]
;
}
}
if
(
FieldNumber
<=
0
)
{
if
(
FieldNumber
<=
0
)
{
...
@@ -244,8 +244,7 @@ namespace Google.ProtocolBuffers.Descriptors {
...
@@ -244,8 +244,7 @@ namespace Google.ProtocolBuffers.Descriptors {
/// Immutable mapping from field type to mapped type. Built using the attributes on
/// Immutable mapping from field type to mapped type. Built using the attributes on
/// FieldType values.
/// FieldType values.
/// </summary>
/// </summary>
public
static
readonly
IDictionary
<
FieldType
,
MappedType
>
FieldTypeToWireFormatMap
=
MapFieldTypes
();
public
static
readonly
IDictionary
<
FieldType
,
MappedType
>
FieldTypeToMappedTypeMap
=
MapFieldTypes
();
private
static
IDictionary
<
FieldType
,
MappedType
>
MapFieldTypes
()
{
private
static
IDictionary
<
FieldType
,
MappedType
>
MapFieldTypes
()
{
var
map
=
new
Dictionary
<
FieldType
,
MappedType
>();
var
map
=
new
Dictionary
<
FieldType
,
MappedType
>();
...
...
csharp/ProtocolBuffers/Descriptors/MessageDescriptor.cs
View file @
5d7adf66
...
@@ -19,16 +19,16 @@ namespace Google.ProtocolBuffers.Descriptors {
...
@@ -19,16 +19,16 @@ namespace Google.ProtocolBuffers.Descriptors {
containingType
=
parent
;
containingType
=
parent
;
nestedTypes
=
DescriptorUtil
.
ConvertAndMakeReadOnly
(
proto
.
NestedTypeList
,
nestedTypes
=
DescriptorUtil
.
ConvertAndMakeReadOnly
(
proto
.
NestedTypeList
,
(
type
,
index
)
=>
new
MessageDescriptor
(
type
,
file
,
null
,
index
));
(
type
,
index
)
=>
new
MessageDescriptor
(
type
,
file
,
this
,
index
));
enumTypes
=
DescriptorUtil
.
ConvertAndMakeReadOnly
(
proto
.
EnumTypeList
,
enumTypes
=
DescriptorUtil
.
ConvertAndMakeReadOnly
(
proto
.
EnumTypeList
,
(
type
,
index
)
=>
new
EnumDescriptor
(
type
,
file
,
null
,
index
));
(
type
,
index
)
=>
new
EnumDescriptor
(
type
,
file
,
this
,
index
));
fields
=
DescriptorUtil
.
ConvertAndMakeReadOnly
(
proto
.
FieldList
,
fields
=
DescriptorUtil
.
ConvertAndMakeReadOnly
(
proto
.
FieldList
,
(
field
,
index
)
=>
new
FieldDescriptor
(
field
,
file
,
null
,
index
,
false
));
(
field
,
index
)
=>
new
FieldDescriptor
(
field
,
file
,
this
,
index
,
false
));
extensions
=
DescriptorUtil
.
ConvertAndMakeReadOnly
(
proto
.
ExtensionList
,
extensions
=
DescriptorUtil
.
ConvertAndMakeReadOnly
(
proto
.
ExtensionList
,
(
field
,
index
)
=>
new
FieldDescriptor
(
field
,
file
,
null
,
index
,
true
));
(
field
,
index
)
=>
new
FieldDescriptor
(
field
,
file
,
this
,
index
,
true
));
file
.
DescriptorPool
.
AddSymbol
(
this
);
file
.
DescriptorPool
.
AddSymbol
(
this
);
}
}
...
...
csharp/ProtocolBuffers/FieldAccess/RepeatedMessageAccessor.cs
View file @
5d7adf66
...
@@ -21,7 +21,7 @@ namespace Google.ProtocolBuffers.FieldAccess {
...
@@ -21,7 +21,7 @@ namespace Google.ProtocolBuffers.FieldAccess {
internal
RepeatedMessageAccessor
(
string
name
,
Type
messageType
,
Type
builderType
)
internal
RepeatedMessageAccessor
(
string
name
,
Type
messageType
,
Type
builderType
)
:
base
(
name
,
messageType
,
builderType
)
{
:
base
(
name
,
messageType
,
builderType
)
{
createBuilderMethod
=
ClrType
.
GetMethod
(
"CreateBuilder"
,
BindingFlags
.
Public
|
BindingFlags
.
Static
);
createBuilderMethod
=
ClrType
.
GetMethod
(
"CreateBuilder"
,
new
Type
[
0
]
);
if
(
createBuilderMethod
==
null
)
{
if
(
createBuilderMethod
==
null
)
{
throw
new
ArgumentException
(
"No public static CreateBuilder method declared in "
+
ClrType
.
Name
);
throw
new
ArgumentException
(
"No public static CreateBuilder method declared in "
+
ClrType
.
Name
);
}
}
...
...
csharp/ProtocolBuffers/FieldAccess/RepeatedPrimitiveAccessor.cs
View file @
5d7adf66
...
@@ -11,7 +11,6 @@ namespace Google.ProtocolBuffers.FieldAccess {
...
@@ -11,7 +11,6 @@ namespace Google.ProtocolBuffers.FieldAccess {
private
readonly
PropertyInfo
messageProperty
;
private
readonly
PropertyInfo
messageProperty
;
private
readonly
PropertyInfo
builderProperty
;
private
readonly
PropertyInfo
builderProperty
;
private
readonly
PropertyInfo
hasProperty
;
private
readonly
PropertyInfo
countProperty
;
private
readonly
PropertyInfo
countProperty
;
private
readonly
MethodInfo
clearMethod
;
private
readonly
MethodInfo
clearMethod
;
private
readonly
MethodInfo
addMethod
;
private
readonly
MethodInfo
addMethod
;
...
@@ -30,15 +29,13 @@ namespace Google.ProtocolBuffers.FieldAccess {
...
@@ -30,15 +29,13 @@ namespace Google.ProtocolBuffers.FieldAccess {
internal
RepeatedPrimitiveAccessor
(
string
name
,
Type
messageType
,
Type
builderType
)
{
internal
RepeatedPrimitiveAccessor
(
string
name
,
Type
messageType
,
Type
builderType
)
{
messageProperty
=
messageType
.
GetProperty
(
name
+
"List"
);
messageProperty
=
messageType
.
GetProperty
(
name
+
"List"
);
builderProperty
=
builderType
.
GetProperty
(
name
+
"List"
);
builderProperty
=
builderType
.
GetProperty
(
name
+
"List"
);
hasProperty
=
messageType
.
GetProperty
(
"Has"
+
name
);
countProperty
=
messageType
.
GetProperty
(
name
+
"Count"
);
countProperty
=
messageType
.
GetProperty
(
name
+
"Count"
);
clearMethod
=
builderType
.
GetMethod
(
"Clear"
+
name
);
clearMethod
=
builderType
.
GetMethod
(
"Clear"
+
name
);
addMethod
=
builderType
.
GetMethod
(
"Add"
+
name
);
getElementMethod
=
messageType
.
GetMethod
(
"Get"
+
name
,
new
Type
[]
{
typeof
(
int
)
});
getElementMethod
=
messageType
.
GetMethod
(
"Get"
+
name
,
new
Type
[]
{
typeof
(
int
)
});
setElementMethod
=
builderType
.
GetMethod
(
"Set"
+
name
,
new
Type
[]
{
typeof
(
int
)
});
addMethod
=
builderType
.
GetMethod
(
"Add"
+
name
,
new
Type
[]
{
ClrType
});
setElementMethod
=
builderType
.
GetMethod
(
"Set"
+
name
,
new
Type
[]
{
typeof
(
int
),
ClrType
});
if
(
messageProperty
==
null
if
(
messageProperty
==
null
||
builderProperty
==
null
||
builderProperty
==
null
||
hasProperty
==
null
||
countProperty
==
null
||
countProperty
==
null
||
clearMethod
==
null
||
clearMethod
==
null
||
addMethod
==
null
||
addMethod
==
null
...
...
csharp/ProtocolBuffers/FieldAccess/SingleMessageAccessor.cs
View file @
5d7adf66
...
@@ -19,7 +19,7 @@ namespace Google.ProtocolBuffers.FieldAccess {
...
@@ -19,7 +19,7 @@ namespace Google.ProtocolBuffers.FieldAccess {
internal
SingleMessageAccessor
(
string
name
,
Type
messageType
,
Type
builderType
)
internal
SingleMessageAccessor
(
string
name
,
Type
messageType
,
Type
builderType
)
:
base
(
name
,
messageType
,
builderType
)
{
:
base
(
name
,
messageType
,
builderType
)
{
createBuilderMethod
=
ClrType
.
GetMethod
(
"CreateBuilder"
,
BindingFlags
.
Public
|
BindingFlags
.
Static
);
createBuilderMethod
=
ClrType
.
GetMethod
(
"CreateBuilder"
,
new
Type
[
0
]);
//BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly
);
if
(
createBuilderMethod
==
null
)
{
if
(
createBuilderMethod
==
null
)
{
throw
new
ArgumentException
(
"No public static CreateBuilder method declared in "
+
ClrType
.
Name
);
throw
new
ArgumentException
(
"No public static CreateBuilder method declared in "
+
ClrType
.
Name
);
}
}
...
...
csharp/ProtocolBuffers/FieldSet.cs
View file @
5d7adf66
...
@@ -91,11 +91,8 @@ namespace Google.ProtocolBuffers {
...
@@ -91,11 +91,8 @@ namespace Google.ProtocolBuffers {
}
}
// TODO(jonskeet): Should this be in UnknownFieldSet.Builder really? Or CodedInputStream?
// TODO(jonskeet): Should this be in UnknownFieldSet.Builder really? Or CodedInputStream?
internal
static
void
MergeFrom
(
CodedInputStream
input
,
internal
static
void
MergeFrom
(
CodedInputStream
input
,
UnknownFieldSet
.
Builder
unknownFields
,
UnknownFieldSet
.
Builder
unknownFields
,
ExtensionRegistry
extensionRegistry
,
IBuilder
builder
)
{
ExtensionRegistry
extensionRegistry
,
IBuilder
builder
)
{
while
(
true
)
{
while
(
true
)
{
uint
tag
=
input
.
ReadTag
();
uint
tag
=
input
.
ReadTag
();
if
(
tag
==
0
)
{
if
(
tag
==
0
)
{
...
@@ -120,15 +117,10 @@ namespace Google.ProtocolBuffers {
...
@@ -120,15 +117,10 @@ namespace Google.ProtocolBuffers {
/// <param name="builder">Builder to merge field into, if it's a known field</param>
/// <param name="builder">Builder to merge field into, if it's a known field</param>
/// <param name="tag">The tag, which should already have been read from the input</param>
/// <param name="tag">The tag, which should already have been read from the input</param>
/// <returns>true unless the tag is an end-group tag</returns>
/// <returns>true unless the tag is an end-group tag</returns>
internal
static
bool
MergeFieldFrom
(
CodedInputStream
input
,
internal
static
bool
MergeFieldFrom
(
CodedInputStream
input
,
UnknownFieldSet
.
Builder
unknownFields
,
UnknownFieldSet
.
Builder
unknownFields
,
ExtensionRegistry
extensionRegistry
,
IBuilder
builder
,
uint
tag
)
{
ExtensionRegistry
extensionRegistry
,
IBuilder
builder
,
uint
tag
)
{
MessageDescriptor
type
=
builder
.
DescriptorForType
;
MessageDescriptor
type
=
builder
.
DescriptorForType
;
if
(
type
.
Options
.
MessageSetWireFormat
&&
tag
==
WireFormat
.
MessageSetTag
.
ItemStart
)
{
if
(
type
.
Options
.
MessageSetWireFormat
&&
tag
==
WireFormat
.
MessageSetTag
.
ItemStart
)
{
MergeMessageSetExtensionFromCodedStream
(
input
,
unknownFields
,
extensionRegistry
,
builder
);
MergeMessageSetExtensionFromCodedStream
(
input
,
unknownFields
,
extensionRegistry
,
builder
);
return
true
;
return
true
;
}
}
...
...
csharp/ProtocolBuffers/GeneratedBuilder.cs
View file @
5d7adf66
...
@@ -200,6 +200,10 @@ namespace Google.ProtocolBuffers {
...
@@ -200,6 +200,10 @@ namespace Google.ProtocolBuffers {
return
this
;
return
this
;
}
}
protected
override
IBuilder
MergeFromImpl
(
CodedInputStream
data
,
ExtensionRegistry
extensionRegistry
)
{
return
MergeFrom
(
data
,
extensionRegistry
);
}
/// <summary>
/// <summary>
/// Like Build(), but will wrap UninitializedMessageException in
/// Like Build(), but will wrap UninitializedMessageException in
/// InvalidProtocolBufferException.
/// InvalidProtocolBufferException.
...
@@ -223,6 +227,11 @@ namespace Google.ProtocolBuffers {
...
@@ -223,6 +227,11 @@ namespace Google.ProtocolBuffers {
return
BuildPartial
();
return
BuildPartial
();
}
}
public
override
UnknownFieldSet
UnknownFields
{
get
{
return
MessageBeingBuilt
.
UnknownFields
;
}
set
{
MessageBeingBuilt
.
SetUnknownFields
(
value
);
}
}
public
abstract
TMessage
BuildPartial
();
public
abstract
TMessage
BuildPartial
();
public
abstract
IBuilder
<
TMessage
>
Clone
();
public
abstract
IBuilder
<
TMessage
>
Clone
();
public
abstract
new
IBuilder
<
TMessage
>
Clear
();
public
abstract
new
IBuilder
<
TMessage
>
Clear
();
...
...
csharp/ProtocolBuffers/TextFormat.cs
View file @
5d7adf66
...
@@ -187,15 +187,15 @@ namespace Google.ProtocolBuffers {
...
@@ -187,15 +187,15 @@ namespace Google.ProtocolBuffers {
}
}
internal
static
ulong
ParseUInt64
(
string
text
)
{
internal
static
ulong
ParseUInt64
(
string
text
)
{
return
(
ulong
)
ParseInteger
(
text
,
true
,
fals
e
);
return
(
ulong
)
ParseInteger
(
text
,
false
,
tru
e
);
}
}
internal
static
long
ParseInt64
(
string
text
)
{
internal
static
long
ParseInt64
(
string
text
)
{
return
ParseInteger
(
text
,
true
,
fals
e
);
return
ParseInteger
(
text
,
true
,
tru
e
);
}
}
internal
static
uint
ParseUInt32
(
string
text
)
{
internal
static
uint
ParseUInt32
(
string
text
)
{
return
(
uint
)
ParseInteger
(
text
,
tru
e
,
false
);
return
(
uint
)
ParseInteger
(
text
,
fals
e
,
false
);
}
}
internal
static
int
ParseInt32
(
string
text
)
{
internal
static
int
ParseInt32
(
string
text
)
{
...
@@ -229,7 +229,7 @@ namespace Google.ProtocolBuffers {
...
@@ -229,7 +229,7 @@ namespace Google.ProtocolBuffers {
ulong
result
=
Convert
.
ToUInt64
(
text
,
radix
);
ulong
result
=
Convert
.
ToUInt64
(
text
,
radix
);
if
(
negative
)
{
if
(
negative
)
{
ulong
max
=
isLong
?
0x8000000
U
L
:
0x8
000L
;
ulong
max
=
isLong
?
0x8000000
000000000U
L
:
0x80000
000L
;
if
(
result
>
max
)
{
if
(
result
>
max
)
{
throw
new
FormatException
(
"Number of out range: "
+
original
);
throw
new
FormatException
(
"Number of out range: "
+
original
);
}
}
...
...
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