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
d9c59e66
Commit
d9c59e66
authored
Nov 05, 2010
by
csharptest
Committed by
unknown
Nov 05, 2010
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
First pass at interface breakup
parent
c07571a7
Hide whitespace changes
Inline
Side-by-side
Showing
21 changed files
with
412 additions
and
422 deletions
+412
-422
UmbrellaClassGenerator.cs
src/ProtoGen/UmbrellaClassGenerator.cs
+0
-4
ProtocolBuffers.sln
src/ProtocolBuffers.sln
+8
-0
AbstractBuilder.cs
src/ProtocolBuffers/AbstractBuilder.cs
+72
-8
AbstractMessage.cs
src/ProtocolBuffers/AbstractMessage.cs
+11
-0
CodedInputStream.cs
src/ProtocolBuffers/CodedInputStream.cs
+11
-7
CodedOutputStream.cs
src/ProtocolBuffers/CodedOutputStream.cs
+22
-14
DynamicMessage.cs
src/ProtocolBuffers/DynamicMessage.cs
+1
-1
ExtensionInfo.cs
src/ProtocolBuffers/ExtensionInfo.cs
+18
-1
ExtensionRegistry.cs
src/ProtocolBuffers/ExtensionRegistry.cs
+13
-45
ExtensionRegistryLite.cs
src/ProtocolBuffers/ExtensionRegistryLite.cs
+32
-98
GeneratedExtensionBase.cs
src/ProtocolBuffers/GeneratedExtensionBase.cs
+5
-0
GeneratedExtensionLite.cs
src/ProtocolBuffers/GeneratedExtensionLite.cs
+25
-0
IBuilder.cs
src/ProtocolBuffers/IBuilder.cs
+31
-31
IBuilderLite.cs
src/ProtocolBuffers/IBuilderLite.cs
+21
-113
IMessage.cs
src/ProtocolBuffers/IMessage.cs
+19
-19
IMessageLite.cs
src/ProtocolBuffers/IMessageLite.cs
+8
-70
ProtocolBuffers.csproj
src/ProtocolBuffers/ProtocolBuffers.csproj
+9
-1
UninitializedMessageException.cs
src/ProtocolBuffers/UninitializedMessageException.cs
+9
-5
UnknownField.cs
src/ProtocolBuffers/UnknownField.cs
+4
-0
UnknownFieldSet.cs
src/ProtocolBuffers/UnknownFieldSet.cs
+89
-5
WireFormat.cs
src/ProtocolBuffers/WireFormat.cs
+4
-0
No files found.
src/ProtoGen/UmbrellaClassGenerator.cs
View file @
d9c59e66
...
@@ -74,10 +74,6 @@ namespace Google.ProtocolBuffers.ProtoGen {
...
@@ -74,10 +74,6 @@ namespace Google.ProtocolBuffers.ProtoGen {
return
false
;
return
false
;
}
}
public
string
UmbrellaClassName
{
get
{
throw
new
NotImplementedException
();
}
}
public
void
Generate
(
TextGenerator
writer
)
{
public
void
Generate
(
TextGenerator
writer
)
{
WriteIntroduction
(
writer
);
WriteIntroduction
(
writer
);
WriteExtensionRegistration
(
writer
);
WriteExtensionRegistration
(
writer
);
...
...
src/ProtocolBuffers.sln
View file @
d9c59e66
...
@@ -25,6 +25,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "proto", "proto", "{1F896D5C
...
@@ -25,6 +25,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "proto", "proto", "{1F896D5C
..\todo.txt = ..\todo.txt
..\todo.txt = ..\todo.txt
EndProjectSection
EndProjectSection
EndProject
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProtocolBuffersLite", "ProtocolBuffers\ProtocolBuffersLite.csproj", "{6969BDCE-D925-43F3-94AC-A531E6DF2591}"
EndProject
Global
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|Any CPU = Debug|Any CPU
...
@@ -80,6 +82,12 @@ Global
...
@@ -80,6 +82,12 @@ Global
{D7282E99-2DC3-405B-946F-177DB2FD2AE2}.Release|Any CPU.Build.0 = Release|Any CPU
{D7282E99-2DC3-405B-946F-177DB2FD2AE2}.Release|Any CPU.Build.0 = Release|Any CPU
{D7282E99-2DC3-405B-946F-177DB2FD2AE2}.Silverlight2|Any CPU.ActiveCfg = Silverlight2|Any CPU
{D7282E99-2DC3-405B-946F-177DB2FD2AE2}.Silverlight2|Any CPU.ActiveCfg = Silverlight2|Any CPU
{D7282E99-2DC3-405B-946F-177DB2FD2AE2}.Silverlight2|Any CPU.Build.0 = Silverlight2|Any CPU
{D7282E99-2DC3-405B-946F-177DB2FD2AE2}.Silverlight2|Any CPU.Build.0 = Silverlight2|Any CPU
{6969BDCE-D925-43F3-94AC-A531E6DF2591}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6969BDCE-D925-43F3-94AC-A531E6DF2591}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6969BDCE-D925-43F3-94AC-A531E6DF2591}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6969BDCE-D925-43F3-94AC-A531E6DF2591}.Release|Any CPU.Build.0 = Release|Any CPU
{6969BDCE-D925-43F3-94AC-A531E6DF2591}.Silverlight2|Any CPU.ActiveCfg = Silverlight2|Any CPU
{6969BDCE-D925-43F3-94AC-A531E6DF2591}.Silverlight2|Any CPU.Build.0 = Silverlight2|Any CPU
EndGlobalSection
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
HideSolutionNode = FALSE
...
...
src/ProtocolBuffers/AbstractBuilder.cs
View file @
d9c59e66
...
@@ -88,7 +88,7 @@ namespace Google.ProtocolBuffers {
...
@@ -88,7 +88,7 @@ namespace Google.ProtocolBuffers {
return
MergeFrom
(
input
);
return
MergeFrom
(
input
);
}
}
public
IBuilder
WeakMergeFrom
(
CodedInputStream
input
,
ExtensionRegistry
registry
)
{
public
IBuilder
WeakMergeFrom
(
CodedInputStream
input
,
ExtensionRegistry
Lite
registry
)
{
return
MergeFrom
(
input
,
registry
);
return
MergeFrom
(
input
,
registry
);
}
}
...
@@ -96,7 +96,7 @@ namespace Google.ProtocolBuffers {
...
@@ -96,7 +96,7 @@ namespace Google.ProtocolBuffers {
return
MergeFrom
(
data
);
return
MergeFrom
(
data
);
}
}
public
IBuilder
WeakMergeFrom
(
ByteString
data
,
ExtensionRegistry
registry
)
{
public
IBuilder
WeakMergeFrom
(
ByteString
data
,
ExtensionRegistry
Lite
registry
)
{
return
MergeFrom
(
data
,
registry
);
return
MergeFrom
(
data
,
registry
);
}
}
...
@@ -173,6 +173,10 @@ namespace Google.ProtocolBuffers {
...
@@ -173,6 +173,10 @@ namespace Google.ProtocolBuffers {
}
}
public
virtual
TBuilder
MergeFrom
(
CodedInputStream
input
,
ExtensionRegistry
extensionRegistry
)
{
public
virtual
TBuilder
MergeFrom
(
CodedInputStream
input
,
ExtensionRegistry
extensionRegistry
)
{
return
MergeFrom
(
input
,
(
ExtensionRegistryLite
)
extensionRegistry
);
}
public
virtual
TBuilder
MergeFrom
(
CodedInputStream
input
,
ExtensionRegistryLite
extensionRegistry
)
{
UnknownFieldSet
.
Builder
unknownFields
=
UnknownFieldSet
.
CreateBuilder
(
UnknownFields
);
UnknownFieldSet
.
Builder
unknownFields
=
UnknownFieldSet
.
CreateBuilder
(
UnknownFields
);
unknownFields
.
MergeFrom
(
input
,
extensionRegistry
,
this
);
unknownFields
.
MergeFrom
(
input
,
extensionRegistry
,
this
);
UnknownFields
=
unknownFields
.
Build
();
UnknownFields
=
unknownFields
.
Build
();
...
@@ -194,6 +198,10 @@ namespace Google.ProtocolBuffers {
...
@@ -194,6 +198,10 @@ namespace Google.ProtocolBuffers {
}
}
public
virtual
TBuilder
MergeFrom
(
ByteString
data
,
ExtensionRegistry
extensionRegistry
)
{
public
virtual
TBuilder
MergeFrom
(
ByteString
data
,
ExtensionRegistry
extensionRegistry
)
{
return
MergeFrom
(
data
,
(
ExtensionRegistryLite
)
extensionRegistry
);
}
public
virtual
TBuilder
MergeFrom
(
ByteString
data
,
ExtensionRegistryLite
extensionRegistry
)
{
CodedInputStream
input
=
data
.
CreateCodedInput
();
CodedInputStream
input
=
data
.
CreateCodedInput
();
MergeFrom
(
input
,
extensionRegistry
);
MergeFrom
(
input
,
extensionRegistry
);
input
.
CheckLastTagWas
(
0
);
input
.
CheckLastTagWas
(
0
);
...
@@ -208,6 +216,10 @@ namespace Google.ProtocolBuffers {
...
@@ -208,6 +216,10 @@ namespace Google.ProtocolBuffers {
}
}
public
virtual
TBuilder
MergeFrom
(
byte
[]
data
,
ExtensionRegistry
extensionRegistry
)
{
public
virtual
TBuilder
MergeFrom
(
byte
[]
data
,
ExtensionRegistry
extensionRegistry
)
{
return
MergeFrom
(
data
,
(
ExtensionRegistryLite
)
extensionRegistry
);
}
public
virtual
TBuilder
MergeFrom
(
byte
[]
data
,
ExtensionRegistryLite
extensionRegistry
)
{
CodedInputStream
input
=
CodedInputStream
.
CreateInstance
(
data
);
CodedInputStream
input
=
CodedInputStream
.
CreateInstance
(
data
);
MergeFrom
(
input
,
extensionRegistry
);
MergeFrom
(
input
,
extensionRegistry
);
input
.
CheckLastTagWas
(
0
);
input
.
CheckLastTagWas
(
0
);
...
@@ -222,6 +234,10 @@ namespace Google.ProtocolBuffers {
...
@@ -222,6 +234,10 @@ namespace Google.ProtocolBuffers {
}
}
public
virtual
TBuilder
MergeFrom
(
Stream
input
,
ExtensionRegistry
extensionRegistry
)
{
public
virtual
TBuilder
MergeFrom
(
Stream
input
,
ExtensionRegistry
extensionRegistry
)
{
return
MergeFrom
(
input
,
(
ExtensionRegistryLite
)
extensionRegistry
);
}
public
virtual
TBuilder
MergeFrom
(
Stream
input
,
ExtensionRegistryLite
extensionRegistry
)
{
CodedInputStream
codedInput
=
CodedInputStream
.
CreateInstance
(
input
);
CodedInputStream
codedInput
=
CodedInputStream
.
CreateInstance
(
input
);
MergeFrom
(
codedInput
,
extensionRegistry
);
MergeFrom
(
codedInput
,
extensionRegistry
);
codedInput
.
CheckLastTagWas
(
0
);
codedInput
.
CheckLastTagWas
(
0
);
...
@@ -229,6 +245,10 @@ namespace Google.ProtocolBuffers {
...
@@ -229,6 +245,10 @@ namespace Google.ProtocolBuffers {
}
}
public
TBuilder
MergeDelimitedFrom
(
Stream
input
,
ExtensionRegistry
extensionRegistry
)
{
public
TBuilder
MergeDelimitedFrom
(
Stream
input
,
ExtensionRegistry
extensionRegistry
)
{
return
MergeDelimitedFrom
(
input
,
(
ExtensionRegistryLite
)
extensionRegistry
);
}
public
TBuilder
MergeDelimitedFrom
(
Stream
input
,
ExtensionRegistryLite
extensionRegistry
)
{
int
size
=
(
int
)
CodedInputStream
.
ReadRawVarint32
(
input
);
int
size
=
(
int
)
CodedInputStream
.
ReadRawVarint32
(
input
);
Stream
limitedStream
=
new
LimitedInputStream
(
input
,
size
);
Stream
limitedStream
=
new
LimitedInputStream
(
input
,
size
);
return
MergeFrom
(
limitedStream
,
extensionRegistry
);
return
MergeFrom
(
limitedStream
,
extensionRegistry
);
...
@@ -279,15 +299,15 @@ namespace Google.ProtocolBuffers {
...
@@ -279,15 +299,15 @@ namespace Google.ProtocolBuffers {
}
}
public
override
long
Length
{
public
override
long
Length
{
get
{
throw
new
Not
Implemen
tedException
();
}
get
{
throw
new
Not
Suppor
tedException
();
}
}
}
public
override
long
Position
{
public
override
long
Position
{
get
{
get
{
throw
new
Not
Implemen
tedException
();
throw
new
Not
Suppor
tedException
();
}
}
set
{
set
{
throw
new
Not
Implemen
tedException
();
throw
new
Not
Suppor
tedException
();
}
}
}
}
...
@@ -301,16 +321,60 @@ namespace Google.ProtocolBuffers {
...
@@ -301,16 +321,60 @@ namespace Google.ProtocolBuffers {
}
}
public
override
long
Seek
(
long
offset
,
SeekOrigin
origin
)
{
public
override
long
Seek
(
long
offset
,
SeekOrigin
origin
)
{
throw
new
Not
Implemen
tedException
();
throw
new
Not
Suppor
tedException
();
}
}
public
override
void
SetLength
(
long
value
)
{
public
override
void
SetLength
(
long
value
)
{
throw
new
Not
Implemen
tedException
();
throw
new
Not
Suppor
tedException
();
}
}
public
override
void
Write
(
byte
[]
buffer
,
int
offset
,
int
count
)
{
public
override
void
Write
(
byte
[]
buffer
,
int
offset
,
int
count
)
{
throw
new
Not
Implemen
tedException
();
throw
new
Not
Suppor
tedException
();
}
}
}
}
IBuilderLite
IBuilderLite
.
WeakClear
()
{
return
WeakClear
();
}
public
IBuilderLite
WeakMergeFrom
(
IMessageLite
message
)
{
return
MergeFrom
(
message
);
}
IBuilderLite
IBuilderLite
.
WeakMergeFrom
(
ByteString
data
)
{
return
WeakMergeFrom
(
data
);
}
IBuilderLite
IBuilderLite
.
WeakMergeFrom
(
ByteString
data
,
ExtensionRegistryLite
registry
)
{
throw
new
NotImplementedException
();
}
IBuilderLite
IBuilderLite
.
WeakMergeFrom
(
CodedInputStream
input
)
{
return
WeakMergeFrom
(
input
);
}
IBuilderLite
IBuilderLite
.
WeakMergeFrom
(
CodedInputStream
input
,
ExtensionRegistryLite
registry
)
{
throw
new
NotImplementedException
();
}
IMessageLite
IBuilderLite
.
WeakBuild
()
{
return
WeakBuild
();
}
IMessageLite
IBuilderLite
.
WeakBuildPartial
()
{
return
WeakBuildPartial
();
}
IBuilderLite
IBuilderLite
.
WeakClone
()
{
return
WeakClone
();
}
IMessageLite
IBuilderLite
.
WeakDefaultInstanceForType
{
get
{
return
WeakDefaultInstanceForType
;
}
}
public
TBuilder
MergeFrom
(
IMessageLite
other
)
{
throw
new
NotImplementedException
();
}
}
}
}
}
src/ProtocolBuffers/AbstractMessage.cs
View file @
d9c59e66
...
@@ -72,6 +72,10 @@ namespace Google.ProtocolBuffers {
...
@@ -72,6 +72,10 @@ namespace Google.ProtocolBuffers {
return
ToBuilder
();
return
ToBuilder
();
}
}
IMessageLite
IMessageLite
.
WeakDefaultInstanceForType
{
get
{
return
DefaultInstanceForType
;
}
}
public
IMessage
WeakDefaultInstanceForType
{
public
IMessage
WeakDefaultInstanceForType
{
get
{
return
DefaultInstanceForType
;
}
get
{
return
DefaultInstanceForType
;
}
}
}
...
@@ -233,5 +237,12 @@ namespace Google.ProtocolBuffers {
...
@@ -233,5 +237,12 @@ namespace Google.ProtocolBuffers {
hash
=
(
29
*
hash
)
+
UnknownFields
.
GetHashCode
();
hash
=
(
29
*
hash
)
+
UnknownFields
.
GetHashCode
();
return
hash
;
return
hash
;
}
}
IBuilderLite
IMessageLite
.
WeakCreateBuilderForType
()
{
return
WeakCreateBuilderForType
();
}
IBuilderLite
IMessageLite
.
WeakToBuilder
()
{
return
WeakToBuilder
();
}
}
}
}
}
src/ProtocolBuffers/CodedInputStream.cs
View file @
d9c59e66
...
@@ -36,7 +36,9 @@ using System;
...
@@ -36,7 +36,9 @@ using System;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System.IO
;
using
System.IO
;
using
System.Text
;
using
System.Text
;
#if !LITE
using
Google.ProtocolBuffers.Descriptors
;
using
Google.ProtocolBuffers.Descriptors
;
#endif
namespace
Google.ProtocolBuffers
{
namespace
Google.ProtocolBuffers
{
...
@@ -258,8 +260,8 @@ namespace Google.ProtocolBuffers {
...
@@ -258,8 +260,8 @@ namespace Google.ProtocolBuffers {
/// <summary>
/// <summary>
/// Reads a group field value from the stream.
/// Reads a group field value from the stream.
/// </summary>
/// </summary>
public
void
ReadGroup
(
int
fieldNumber
,
IBuilder
builder
,
public
void
ReadGroup
(
int
fieldNumber
,
IBuilder
Lite
builder
,
ExtensionRegistry
extensionRegistry
)
{
ExtensionRegistry
Lite
extensionRegistry
)
{
if
(
recursionDepth
>=
recursionLimit
)
{
if
(
recursionDepth
>=
recursionLimit
)
{
throw
InvalidProtocolBufferException
.
RecursionLimitExceeded
();
throw
InvalidProtocolBufferException
.
RecursionLimitExceeded
();
}
}
...
@@ -273,12 +275,14 @@ namespace Google.ProtocolBuffers {
...
@@ -273,12 +275,14 @@ namespace Google.ProtocolBuffers {
/// Reads a group field value from the stream and merges it into the given
/// Reads a group field value from the stream and merges it into the given
/// UnknownFieldSet.
/// UnknownFieldSet.
/// </summary>
/// </summary>
public
void
ReadUnknownGroup
(
int
fieldNumber
,
UnknownFieldSet
.
Builder
builder
)
{
[
Obsolete
]
public
void
ReadUnknownGroup
(
int
fieldNumber
,
IBuilderLite
builder
)
{
if
(
recursionDepth
>=
recursionLimit
)
{
if
(
recursionDepth
>=
recursionLimit
)
{
throw
InvalidProtocolBufferException
.
RecursionLimitExceeded
();
throw
InvalidProtocolBufferException
.
RecursionLimitExceeded
();
}
}
++
recursionDepth
;
++
recursionDepth
;
builder
.
MergeFrom
(
this
);
builder
.
Weak
MergeFrom
(
this
);
CheckLastTagWas
(
WireFormat
.
MakeTag
(
fieldNumber
,
WireFormat
.
WireType
.
EndGroup
));
CheckLastTagWas
(
WireFormat
.
MakeTag
(
fieldNumber
,
WireFormat
.
WireType
.
EndGroup
));
--
recursionDepth
;
--
recursionDepth
;
}
}
...
@@ -286,7 +290,7 @@ namespace Google.ProtocolBuffers {
...
@@ -286,7 +290,7 @@ namespace Google.ProtocolBuffers {
/// <summary>
/// <summary>
/// Reads an embedded message field value from the stream.
/// Reads an embedded message field value from the stream.
/// </summary>
/// </summary>
public
void
ReadMessage
(
IBuilder
builder
,
ExtensionRegistry
extensionRegistry
)
{
public
void
ReadMessage
(
IBuilder
Lite
builder
,
ExtensionRegistryLite
extensionRegistry
)
{
int
length
=
(
int
)
ReadRawVarint32
();
int
length
=
(
int
)
ReadRawVarint32
();
if
(
recursionDepth
>=
recursionLimit
)
{
if
(
recursionDepth
>=
recursionLimit
)
{
throw
InvalidProtocolBufferException
.
RecursionLimitExceeded
();
throw
InvalidProtocolBufferException
.
RecursionLimitExceeded
();
...
@@ -359,7 +363,7 @@ namespace Google.ProtocolBuffers {
...
@@ -359,7 +363,7 @@ namespace Google.ProtocolBuffers {
public
long
ReadSInt64
()
{
public
long
ReadSInt64
()
{
return
DecodeZigZag64
(
ReadRawVarint64
());
return
DecodeZigZag64
(
ReadRawVarint64
());
}
}
#if !LITE
/// <summary>
/// <summary>
/// Reads a field of any primitive type. Enums, groups and embedded
/// Reads a field of any primitive type. Enums, groups and embedded
/// messages are not handled by this method.
/// messages are not handled by this method.
...
@@ -393,7 +397,7 @@ namespace Google.ProtocolBuffers {
...
@@ -393,7 +397,7 @@ namespace Google.ProtocolBuffers {
throw
new
ArgumentOutOfRangeException
(
"Invalid field type "
+
fieldType
);
throw
new
ArgumentOutOfRangeException
(
"Invalid field type "
+
fieldType
);
}
}
}
}
#endif
#
endregion
#
endregion
#
region
Underlying
reading
primitives
#
region
Underlying
reading
primitives
...
...
src/ProtocolBuffers/CodedOutputStream.cs
View file @
d9c59e66
...
@@ -35,8 +35,9 @@
...
@@ -35,8 +35,9 @@
using
System
;
using
System
;
using
System.IO
;
using
System.IO
;
using
System.Text
;
using
System.Text
;
#if !LITE
using
Google.ProtocolBuffers.Descriptors
;
using
Google.ProtocolBuffers.Descriptors
;
#endif
namespace
Google.ProtocolBuffers
{
namespace
Google.ProtocolBuffers
{
/// <summary>
/// <summary>
...
@@ -206,19 +207,20 @@ namespace Google.ProtocolBuffers {
...
@@ -206,19 +207,20 @@ namespace Google.ProtocolBuffers {
/// <summary>
/// <summary>
/// Writes a group field value, including tag, to the stream.
/// Writes a group field value, including tag, to the stream.
/// </summary>
/// </summary>
public
void
WriteGroup
(
int
fieldNumber
,
IMessage
value
)
{
public
void
WriteGroup
(
int
fieldNumber
,
IMessage
Lite
value
)
{
WriteTag
(
fieldNumber
,
WireFormat
.
WireType
.
StartGroup
);
WriteTag
(
fieldNumber
,
WireFormat
.
WireType
.
StartGroup
);
value
.
WriteTo
(
this
);
value
.
WriteTo
(
this
);
WriteTag
(
fieldNumber
,
WireFormat
.
WireType
.
EndGroup
);
WriteTag
(
fieldNumber
,
WireFormat
.
WireType
.
EndGroup
);
}
}
public
void
WriteUnknownGroup
(
int
fieldNumber
,
UnknownFieldSet
value
)
{
[
Obsolete
]
public
void
WriteUnknownGroup
(
int
fieldNumber
,
IMessageLite
value
)
{
WriteTag
(
fieldNumber
,
WireFormat
.
WireType
.
StartGroup
);
WriteTag
(
fieldNumber
,
WireFormat
.
WireType
.
StartGroup
);
value
.
WriteTo
(
this
);
value
.
WriteTo
(
this
);
WriteTag
(
fieldNumber
,
WireFormat
.
WireType
.
EndGroup
);
WriteTag
(
fieldNumber
,
WireFormat
.
WireType
.
EndGroup
);
}
}
public
void
WriteMessage
(
int
fieldNumber
,
IMessage
value
)
{
public
void
WriteMessage
(
int
fieldNumber
,
IMessage
Lite
value
)
{
WriteTag
(
fieldNumber
,
WireFormat
.
WireType
.
LengthDelimited
);
WriteTag
(
fieldNumber
,
WireFormat
.
WireType
.
LengthDelimited
);
WriteRawVarint32
((
uint
)
value
.
SerializedSize
);
WriteRawVarint32
((
uint
)
value
.
SerializedSize
);
value
.
WriteTo
(
this
);
value
.
WriteTo
(
this
);
...
@@ -263,7 +265,7 @@ namespace Google.ProtocolBuffers {
...
@@ -263,7 +265,7 @@ namespace Google.ProtocolBuffers {
WriteRawVarint64
(
EncodeZigZag64
(
value
));
WriteRawVarint64
(
EncodeZigZag64
(
value
));
}
}
public
void
WriteMessageSetExtension
(
int
fieldNumber
,
IMessage
value
)
{
public
void
WriteMessageSetExtension
(
int
fieldNumber
,
IMessage
Lite
value
)
{
WriteTag
(
WireFormat
.
MessageSetField
.
Item
,
WireFormat
.
WireType
.
StartGroup
);
WriteTag
(
WireFormat
.
MessageSetField
.
Item
,
WireFormat
.
WireType
.
StartGroup
);
WriteUInt32
(
WireFormat
.
MessageSetField
.
TypeID
,
(
uint
)
fieldNumber
);
WriteUInt32
(
WireFormat
.
MessageSetField
.
TypeID
,
(
uint
)
fieldNumber
);
WriteMessage
(
WireFormat
.
MessageSetField
.
Message
,
value
);
WriteMessage
(
WireFormat
.
MessageSetField
.
Message
,
value
);
...
@@ -277,6 +279,7 @@ namespace Google.ProtocolBuffers {
...
@@ -277,6 +279,7 @@ namespace Google.ProtocolBuffers {
WriteTag
(
WireFormat
.
MessageSetField
.
Item
,
WireFormat
.
WireType
.
EndGroup
);
WriteTag
(
WireFormat
.
MessageSetField
.
Item
,
WireFormat
.
WireType
.
EndGroup
);
}
}
#if !LITE
public
void
WriteField
(
FieldType
fieldType
,
int
fieldNumber
,
object
value
)
{
public
void
WriteField
(
FieldType
fieldType
,
int
fieldNumber
,
object
value
)
{
switch
(
fieldType
)
{
switch
(
fieldType
)
{
case
FieldType
.
Double
:
WriteDouble
(
fieldNumber
,
(
double
)
value
);
break
;
case
FieldType
.
Double
:
WriteDouble
(
fieldNumber
,
(
double
)
value
);
break
;
...
@@ -324,6 +327,7 @@ namespace Google.ProtocolBuffers {
...
@@ -324,6 +327,7 @@ namespace Google.ProtocolBuffers {
break
;
break
;
}
}
}
}
#endif
#
endregion
#
endregion
#
region
Writing
of
values
without
tags
#
region
Writing
of
values
without
tags
...
@@ -420,11 +424,11 @@ namespace Google.ProtocolBuffers {
...
@@ -420,11 +424,11 @@ namespace Google.ProtocolBuffers {
/// <summary>
/// <summary>
/// Writes a group field value, without a tag, to the stream.
/// Writes a group field value, without a tag, to the stream.
/// </summary>
/// </summary>
public
void
WriteGroupNoTag
(
IMessage
value
)
{
public
void
WriteGroupNoTag
(
IMessage
Lite
value
)
{
value
.
WriteTo
(
this
);
value
.
WriteTo
(
this
);
}
}
public
void
WriteMessageNoTag
(
IMessage
value
)
{
public
void
WriteMessageNoTag
(
IMessage
Lite
value
)
{
WriteRawVarint32
((
uint
)
value
.
SerializedSize
);
WriteRawVarint32
((
uint
)
value
.
SerializedSize
);
value
.
WriteTo
(
this
);
value
.
WriteTo
(
this
);
}
}
...
@@ -685,7 +689,7 @@ namespace Google.ProtocolBuffers {
...
@@ -685,7 +689,7 @@ namespace Google.ProtocolBuffers {
/// Compute the number of bytes that would be needed to encode a
/// Compute the number of bytes that would be needed to encode a
/// group field, including the tag.
/// group field, including the tag.
/// </summary>
/// </summary>
public
static
int
ComputeGroupSize
(
int
fieldNumber
,
IMessage
value
)
{
public
static
int
ComputeGroupSize
(
int
fieldNumber
,
IMessage
Lite
value
)
{
return
ComputeTagSize
(
fieldNumber
)
*
2
+
value
.
SerializedSize
;
return
ComputeTagSize
(
fieldNumber
)
*
2
+
value
.
SerializedSize
;
}
}
...
@@ -693,8 +697,9 @@ namespace Google.ProtocolBuffers {
...
@@ -693,8 +697,9 @@ namespace Google.ProtocolBuffers {
/// Compute the number of bytes that would be needed to encode a
/// Compute the number of bytes that would be needed to encode a
/// group field represented by an UnknownFieldSet, including the tag.
/// group field represented by an UnknownFieldSet, including the tag.
/// </summary>
/// </summary>
[
Obsolete
]
public
static
int
ComputeUnknownGroupSize
(
int
fieldNumber
,
public
static
int
ComputeUnknownGroupSize
(
int
fieldNumber
,
UnknownFieldSet
value
)
{
IMessageLite
value
)
{
return
ComputeTagSize
(
fieldNumber
)
*
2
+
value
.
SerializedSize
;
return
ComputeTagSize
(
fieldNumber
)
*
2
+
value
.
SerializedSize
;
}
}
...
@@ -702,7 +707,7 @@ namespace Google.ProtocolBuffers {
...
@@ -702,7 +707,7 @@ namespace Google.ProtocolBuffers {
/// Compute the number of bytes that would be needed to encode an
/// Compute the number of bytes that would be needed to encode an
/// embedded message field, including the tag.
/// embedded message field, including the tag.
/// </summary>
/// </summary>
public
static
int
ComputeMessageSize
(
int
fieldNumber
,
IMessage
value
)
{
public
static
int
ComputeMessageSize
(
int
fieldNumber
,
IMessage
Lite
value
)
{
int
size
=
value
.
SerializedSize
;
int
size
=
value
.
SerializedSize
;
return
ComputeTagSize
(
fieldNumber
)
+
ComputeRawVarint32Size
((
uint
)
size
)
+
size
;
return
ComputeTagSize
(
fieldNumber
)
+
ComputeRawVarint32Size
((
uint
)
size
)
+
size
;
}
}
...
@@ -853,7 +858,7 @@ namespace Google.ProtocolBuffers {
...
@@ -853,7 +858,7 @@ namespace Google.ProtocolBuffers {
/// Compute the number of bytes that would be needed to encode a
/// Compute the number of bytes that would be needed to encode a
/// group field, including the tag.
/// group field, including the tag.
/// </summary>
/// </summary>
public
static
int
ComputeGroupSizeNoTag
(
IMessage
value
)
{
public
static
int
ComputeGroupSizeNoTag
(
IMessage
Lite
value
)
{
return
value
.
SerializedSize
;
return
value
.
SerializedSize
;
}
}
...
@@ -861,7 +866,8 @@ namespace Google.ProtocolBuffers {
...
@@ -861,7 +866,8 @@ namespace Google.ProtocolBuffers {
/// Compute the number of bytes that would be needed to encode a
/// Compute the number of bytes that would be needed to encode a
/// group field represented by an UnknownFieldSet, including the tag.
/// group field represented by an UnknownFieldSet, including the tag.
/// </summary>
/// </summary>
public
static
int
ComputeUnknownGroupSizeNoTag
(
UnknownFieldSet
value
)
{
[
Obsolete
]
public
static
int
ComputeUnknownGroupSizeNoTag
(
IMessageLite
value
)
{
return
value
.
SerializedSize
;
return
value
.
SerializedSize
;
}
}
...
@@ -869,7 +875,7 @@ namespace Google.ProtocolBuffers {
...
@@ -869,7 +875,7 @@ namespace Google.ProtocolBuffers {
/// Compute the number of bytes that would be needed to encode an
/// Compute the number of bytes that would be needed to encode an
/// embedded message field, including the tag.
/// embedded message field, including the tag.
/// </summary>
/// </summary>
public
static
int
ComputeMessageSizeNoTag
(
IMessage
value
)
{
public
static
int
ComputeMessageSizeNoTag
(
IMessage
Lite
value
)
{
int
size
=
value
.
SerializedSize
;
int
size
=
value
.
SerializedSize
;
return
ComputeRawVarint32Size
((
uint
)
size
)
+
size
;
return
ComputeRawVarint32Size
((
uint
)
size
)
+
size
;
}
}
...
@@ -943,7 +949,7 @@ namespace Google.ProtocolBuffers {
...
@@ -943,7 +949,7 @@ namespace Google.ProtocolBuffers {
/// MessageSet extension to the stream. For historical reasons,
/// MessageSet extension to the stream. For historical reasons,
/// the wire format differs from normal fields.
/// the wire format differs from normal fields.
/// </summary>
/// </summary>
public
static
int
ComputeMessageSetExtensionSize
(
int
fieldNumber
,
IMessage
value
)
{
public
static
int
ComputeMessageSetExtensionSize
(
int
fieldNumber
,
IMessage
Lite
value
)
{
return
ComputeTagSize
(
WireFormat
.
MessageSetField
.
Item
)
*
2
+
return
ComputeTagSize
(
WireFormat
.
MessageSetField
.
Item
)
*
2
+
ComputeUInt32Size
(
WireFormat
.
MessageSetField
.
TypeID
,
(
uint
)
fieldNumber
)
+
ComputeUInt32Size
(
WireFormat
.
MessageSetField
.
TypeID
,
(
uint
)
fieldNumber
)
+
ComputeMessageSize
(
WireFormat
.
MessageSetField
.
Message
,
value
);
ComputeMessageSize
(
WireFormat
.
MessageSetField
.
Message
,
value
);
...
@@ -989,6 +995,7 @@ namespace Google.ProtocolBuffers {
...
@@ -989,6 +995,7 @@ namespace Google.ProtocolBuffers {
return
10
;
return
10
;
}
}
#if !LITE
/// <summary>
/// <summary>
/// Compute the number of bytes that would be needed to encode a
/// Compute the number of bytes that would be needed to encode a
/// field of arbitrary type, including the tag, to the stream.
/// field of arbitrary type, including the tag, to the stream.
...
@@ -1046,6 +1053,7 @@ namespace Google.ProtocolBuffers {
...
@@ -1046,6 +1053,7 @@ namespace Google.ProtocolBuffers {
throw
new
ArgumentOutOfRangeException
(
"Invalid field type "
+
fieldType
);
throw
new
ArgumentOutOfRangeException
(
"Invalid field type "
+
fieldType
);
}
}
}
}
#endif
/// <summary>
/// <summary>
/// Compute the number of bytes that would be needed to encode a tag.
/// Compute the number of bytes that would be needed to encode a tag.
...
...
src/ProtocolBuffers/DynamicMessage.cs
View file @
d9c59e66
...
@@ -338,7 +338,7 @@ namespace Google.ProtocolBuffers {
...
@@ -338,7 +338,7 @@ namespace Google.ProtocolBuffers {
get
{
return
fields
.
IsInitializedWithRespectTo
(
type
);
}
get
{
return
fields
.
IsInitializedWithRespectTo
(
type
);
}
}
}
public
override
Builder
MergeFrom
(
CodedInputStream
input
,
ExtensionRegistry
extensionRegistry
)
{
public
override
Builder
MergeFrom
(
CodedInputStream
input
,
ExtensionRegistry
Lite
extensionRegistry
)
{
UnknownFieldSet
.
Builder
unknownFieldsBuilder
=
UnknownFieldSet
.
CreateBuilder
(
unknownFields
);
UnknownFieldSet
.
Builder
unknownFieldsBuilder
=
UnknownFieldSet
.
CreateBuilder
(
unknownFields
);
unknownFieldsBuilder
.
MergeFrom
(
input
,
extensionRegistry
,
this
);
unknownFieldsBuilder
.
MergeFrom
(
input
,
extensionRegistry
,
this
);
unknownFields
=
unknownFieldsBuilder
.
Build
();
unknownFields
=
unknownFieldsBuilder
.
Build
();
...
...
src/ProtocolBuffers/ExtensionInfo.cs
View file @
d9c59e66
...
@@ -36,7 +36,7 @@ using Google.ProtocolBuffers.Descriptors;
...
@@ -36,7 +36,7 @@ using Google.ProtocolBuffers.Descriptors;
namespace
Google.ProtocolBuffers
namespace
Google.ProtocolBuffers
{
{
public
sealed
class
ExtensionInfo
{
public
sealed
class
ExtensionInfo
:
IGeneratedExtensionLite
{
/// <summary>
/// <summary>
/// The extension's descriptor
/// The extension's descriptor
/// </summary>
/// </summary>
...
@@ -55,5 +55,21 @@ namespace Google.ProtocolBuffers
...
@@ -55,5 +55,21 @@ namespace Google.ProtocolBuffers
Descriptor
=
descriptor
;
Descriptor
=
descriptor
;
DefaultInstance
=
defaultInstance
;
DefaultInstance
=
defaultInstance
;
}
}
#
region
IGeneratedExtensionLite
Members
int
IGeneratedExtensionLite
.
Number
{
get
{
return
Descriptor
.
FieldNumber
;
}
}
object
IGeneratedExtensionLite
.
ContainingType
{
get
{
return
Descriptor
;
}
}
IMessageLite
IGeneratedExtensionLite
.
MessageDefaultInstance
{
get
{
return
DefaultInstance
;
}
}
#
endregion
}
}
}
}
\ No newline at end of file
src/ProtocolBuffers/ExtensionRegistry.cs
View file @
d9c59e66
...
@@ -88,41 +88,38 @@ namespace Google.ProtocolBuffers {
...
@@ -88,41 +88,38 @@ namespace Google.ProtocolBuffers {
/// could take advantage of this to inject a mutable object into a message
/// could take advantage of this to inject a mutable object into a message
/// belonging to privileged code and create mischief.</para>
/// belonging to privileged code and create mischief.</para>
/// </remarks>
/// </remarks>
public
sealed
class
ExtensionRegistry
{
public
sealed
class
ExtensionRegistry
:
ExtensionRegistryLite
{
private
static
readonly
ExtensionRegistry
empty
=
new
ExtensionRegistry
(
private
static
readonly
ExtensionRegistry
empty
=
new
ExtensionRegistry
(
new
Dictionary
<
string
,
ExtensionInfo
>(),
new
Dictionary
<
string
,
ExtensionInfo
>(),
new
Dictionary
<
DescriptorIntPair
,
ExtensionInfo
>(),
new
Dictionary
<
ExtensionIntPair
,
IGeneratedExtensionLite
>(),
true
);
true
);
private
readonly
IDictionary
<
string
,
ExtensionInfo
>
extensionsByName
;
private
readonly
IDictionary
<
string
,
ExtensionInfo
>
extensionsByName
;
private
readonly
IDictionary
<
DescriptorIntPair
,
ExtensionInfo
>
extensionsByNumber
;
private
readonly
bool
readOnly
;
private
ExtensionRegistry
(
IDictionary
<
String
,
ExtensionInfo
>
extensionsByName
,
private
ExtensionRegistry
(
IDictionary
<
String
,
ExtensionInfo
>
extensionsByName
,
IDictionary
<
DescriptorIntPair
,
ExtensionInfo
>
extensionsByNumber
,
IDictionary
<
ExtensionIntPair
,
IGeneratedExtensionLite
>
extensionsByNumber
,
bool
readOnly
)
{
bool
readOnly
)
:
base
(
extensionsByNumber
,
readOnly
)
{
this
.
extensionsByName
=
extensionsByName
;
this
.
extensionsByName
=
extensionsByName
;
this
.
extensionsByNumber
=
extensionsByNumber
;
this
.
readOnly
=
readOnly
;
}
}
/// <summary>
/// <summary>
/// Construct a new, empty instance.
/// Construct a new, empty instance.
/// </summary>
/// </summary>
public
static
ExtensionRegistry
CreateInstance
()
{
public
static
new
ExtensionRegistry
CreateInstance
()
{
return
new
ExtensionRegistry
(
new
Dictionary
<
string
,
ExtensionInfo
>(),
return
new
ExtensionRegistry
(
new
Dictionary
<
string
,
ExtensionInfo
>(),
new
Dictionary
<
DescriptorIntPair
,
ExtensionInfo
>(),
false
);
new
Dictionary
<
ExtensionIntPair
,
IGeneratedExtensionLite
>(),
false
);
}
}
/// <summary>
/// <summary>
/// Get the unmodifiable singleton empty instance.
/// Get the unmodifiable singleton empty instance.
/// </summary>
/// </summary>
public
static
ExtensionRegistry
Empty
{
public
new
static
ExtensionRegistry
Empty
{
get
{
return
empty
;
}
get
{
return
empty
;
}
}
}
public
ExtensionRegistry
AsReadOnly
()
{
public
override
ExtensionRegistryLite
AsReadOnly
()
{
return
new
ExtensionRegistry
(
extensionsByName
,
extensionsByNumber
,
true
);
return
new
ExtensionRegistry
(
extensionsByName
,
extensionsByNumber
,
true
);
}
}
...
@@ -146,9 +143,9 @@ namespace Google.ProtocolBuffers {
...
@@ -146,9 +143,9 @@ namespace Google.ProtocolBuffers {
/// </summary>
/// </summary>
public
ExtensionInfo
this
[
MessageDescriptor
containingType
,
int
fieldNumber
]
{
public
ExtensionInfo
this
[
MessageDescriptor
containingType
,
int
fieldNumber
]
{
get
{
get
{
ExtensionInfo
ret
;
IGeneratedExtensionLite
ret
;
extensionsByNumber
.
TryGetValue
(
new
Descriptor
IntPair
(
containingType
,
fieldNumber
),
out
ret
);
extensionsByNumber
.
TryGetValue
(
new
Extension
IntPair
(
containingType
,
fieldNumber
),
out
ret
);
return
ret
;
return
ret
as
ExtensionInfo
;
}
}
}
}
...
@@ -198,7 +195,7 @@ namespace Google.ProtocolBuffers {
...
@@ -198,7 +195,7 @@ namespace Google.ProtocolBuffers {
}
}
extensionsByName
[
extension
.
Descriptor
.
FullName
]
=
extension
;
extensionsByName
[
extension
.
Descriptor
.
FullName
]
=
extension
;
extensionsByNumber
[
new
Descriptor
IntPair
(
extension
.
Descriptor
.
ContainingType
,
extensionsByNumber
[
new
Extension
IntPair
(
extension
.
Descriptor
.
ContainingType
,
extension
.
Descriptor
.
FieldNumber
)]
=
extension
;
extension
.
Descriptor
.
FieldNumber
)]
=
extension
;
FieldDescriptor
field
=
extension
.
Descriptor
;
FieldDescriptor
field
=
extension
.
Descriptor
;
...
@@ -212,34 +209,5 @@ namespace Google.ProtocolBuffers {
...
@@ -212,34 +209,5 @@ namespace Google.ProtocolBuffers {
extensionsByName
[
field
.
MessageType
.
FullName
]
=
extension
;
extensionsByName
[
field
.
MessageType
.
FullName
]
=
extension
;
}
}
}
}
/// <summary>
/// Nested type just used to represent a pair of MessageDescriptor and int, as
/// the key into the "by number" map.
/// </summary>
private
struct
DescriptorIntPair
:
IEquatable
<
DescriptorIntPair
>
{
readonly
MessageDescriptor
descriptor
;
readonly
int
number
;
internal
DescriptorIntPair
(
MessageDescriptor
descriptor
,
int
number
)
{
this
.
descriptor
=
descriptor
;
this
.
number
=
number
;
}
public
override
int
GetHashCode
()
{
return
descriptor
.
GetHashCode
()
*
((
1
<<
16
)
-
1
)
+
number
;
}
public
override
bool
Equals
(
object
obj
)
{
if
(!(
obj
is
DescriptorIntPair
))
{
return
false
;
}
return
Equals
((
DescriptorIntPair
)
obj
);
}
public
bool
Equals
(
DescriptorIntPair
other
)
{
return
descriptor
==
other
.
descriptor
&&
number
==
other
.
number
;
}
}
}
}
}
}
src/ProtocolBuffers/ExtensionRegistryLite.cs
View file @
d9c59e66
...
@@ -33,14 +33,15 @@
...
@@ -33,14 +33,15 @@
#endregion
#endregion
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
Google.ProtocolBuffers.Descriptors
;
using
System
;
using
System
;
namespace
Google.ProtocolBuffers
{
namespace
Google.ProtocolBuffers
{
/// <summary>
/// <summary>
/// A table of known extensions, searchable by name or field number. When
/// A table of known extensions, searchable by name or field number. When
/// parsing a protocol message that might have extensions, you must provide
/// parsing a protocol message that might have extensions, you must provide
/// an <see cref="ExtensionRegistry"/> in which you have registered any extensions
/// an <see cref="ExtensionRegistry
Lite
"/> in which you have registered any extensions
/// that you want to be able to parse. Otherwise, those extensions will just
/// that you want to be able to parse. Otherwise, those extensions will just
/// be treated like unknown fields.
/// be treated like unknown fields.
/// </summary>
/// </summary>
...
@@ -61,7 +62,7 @@ namespace Google.ProtocolBuffers {
...
@@ -61,7 +62,7 @@ namespace Google.ProtocolBuffers {
/// Then you might write code like:
/// Then you might write code like:
///
///
/// <code>
/// <code>
/// ExtensionRegistry
registry = ExtensionRegistry
.CreateInstance();
/// ExtensionRegistry
Lite registry = ExtensionRegistryLite
.CreateInstance();
/// registry.Add(MyProto.Bar);
/// registry.Add(MyProto.Bar);
/// MyProto.Foo message = MyProto.Foo.ParseFrom(input, registry);
/// MyProto.Foo message = MyProto.Foo.ParseFrom(input, registry);
/// </code>
/// </code>
...
@@ -88,21 +89,17 @@ namespace Google.ProtocolBuffers {
...
@@ -88,21 +89,17 @@ namespace Google.ProtocolBuffers {
/// could take advantage of this to inject a mutable object into a message
/// could take advantage of this to inject a mutable object into a message
/// belonging to privileged code and create mischief.</para>
/// belonging to privileged code and create mischief.</para>
/// </remarks>
/// </remarks>
public
sealed
class
ExtensionRegistry
{
public
class
ExtensionRegistryLite
{
private
static
readonly
ExtensionRegistry
empty
=
new
ExtensionRegistry
(
private
static
readonly
ExtensionRegistryLite
empty
=
new
ExtensionRegistryLite
(
new
Dictionary
<
string
,
ExtensionInfo
>(),
new
Dictionary
<
ExtensionIntPair
,
IGeneratedExtensionLite
>(),
new
Dictionary
<
DescriptorIntPair
,
ExtensionInfo
>(),
true
);
true
);
private
readonly
IDictionary
<
string
,
ExtensionInfo
>
extensionsByName
;
protected
readonly
IDictionary
<
ExtensionIntPair
,
IGeneratedExtensionLite
>
extensionsByNumber
;
private
readonly
IDictionary
<
DescriptorIntPair
,
ExtensionInfo
>
extensionsByNumber
;
protected
readonly
bool
readOnly
;
private
readonly
bool
readOnly
;
private
ExtensionRegistry
(
IDictionary
<
String
,
ExtensionInfo
>
extensionsByName
,
protected
ExtensionRegistryLite
(
IDictionary
<
ExtensionIntPair
,
IGeneratedExtensionLite
>
extensionsByNumber
,
IDictionary
<
DescriptorIntPair
,
ExtensionInfo
>
extensionsByNumber
,
bool
readOnly
)
{
bool
readOnly
)
{
this
.
extensionsByName
=
extensionsByName
;
this
.
extensionsByNumber
=
extensionsByNumber
;
this
.
extensionsByNumber
=
extensionsByNumber
;
this
.
readOnly
=
readOnly
;
this
.
readOnly
=
readOnly
;
}
}
...
@@ -110,44 +107,30 @@ namespace Google.ProtocolBuffers {
...
@@ -110,44 +107,30 @@ namespace Google.ProtocolBuffers {
/// <summary>
/// <summary>
/// Construct a new, empty instance.
/// Construct a new, empty instance.
/// </summary>
/// </summary>
public
static
ExtensionRegistry
CreateInstance
()
{
public
static
ExtensionRegistry
Lite
CreateInstance
()
{
return
new
ExtensionRegistry
(
new
Dictionary
<
string
,
ExtensionInfo
>(),
return
new
ExtensionRegistry
Lite
(
new
Dictionary
<
DescriptorIntPair
,
ExtensionInfo
>(),
false
);
new
Dictionary
<
ExtensionIntPair
,
IGeneratedExtensionLite
>(),
false
);
}
}
/// <summary>
/// <summary>
/// Get the unmodifiable singleton empty instance.
/// Get the unmodifiable singleton empty instance.
/// </summary>
/// </summary>
public
static
ExtensionRegistry
Empty
{
public
static
ExtensionRegistry
Lite
Empty
{
get
{
return
empty
;
}
get
{
return
empty
;
}
}
}
public
ExtensionRegistry
AsReadOnly
()
{
public
virtual
ExtensionRegistryLite
AsReadOnly
()
{
return
new
ExtensionRegistry
(
extensionsByName
,
extensionsByNumber
,
true
);
return
new
ExtensionRegistryLite
(
extensionsByNumber
,
true
);
}
/// <summary>
/// Finds an extension by fully-qualified field name, in the
/// proto namespace, i.e. result.Descriptor.FullName will match
/// <paramref name="fullName"/> if a match is found. A null
/// reference is returned if the extension can't be found.
/// </summary>
public
ExtensionInfo
this
[
string
fullName
]
{
get
{
ExtensionInfo
ret
;
extensionsByName
.
TryGetValue
(
fullName
,
out
ret
);
return
ret
;
}
}
}
/// <summary>
/// <summary>
/// Finds an extension by containing type and field number.
/// Finds an extension by containing type and field number.
/// A null reference is returned if the extension can't be found.
/// A null reference is returned if the extension can't be found.
/// </summary>
/// </summary>
public
ExtensionInfo
this
[
MessageDescriptor
containingType
,
int
fieldNumber
]
{
public
IGeneratedExtensionLite
this
[
IMessageLite
containingType
,
int
fieldNumber
]
{
get
{
get
{
ExtensionInfo
ret
;
IGeneratedExtensionLite
ret
;
extensionsByNumber
.
TryGetValue
(
new
Descriptor
IntPair
(
containingType
,
fieldNumber
),
out
ret
);
extensionsByNumber
.
TryGetValue
(
new
Extension
IntPair
(
containingType
,
fieldNumber
),
out
ret
);
return
ret
;
return
ret
;
}
}
}
}
...
@@ -155,90 +138,41 @@ namespace Google.ProtocolBuffers {
...
@@ -155,90 +138,41 @@ namespace Google.ProtocolBuffers {
/// <summary>
/// <summary>
/// Add an extension from a generated file to the registry.
/// Add an extension from a generated file to the registry.
/// </summary>
/// </summary>
public
void
Add
<
TExtension
>
(
GeneratedExtensionBase
<
TExtension
>
extension
)
{
public
virtual
void
Add
(
IGeneratedExtensionLite
extension
)
{
if
(
extension
.
Descriptor
.
MappedType
==
MappedType
.
Message
)
{
Add
(
new
ExtensionInfo
(
extension
.
Descriptor
,
extension
.
MessageDefaultInstance
));
}
else
{
Add
(
new
ExtensionInfo
(
extension
.
Descriptor
,
null
));
}
}
/// <summary>
/// Adds a non-message-type extension to the registry by descriptor.
/// </summary>
/// <param name="type"></param>
public
void
Add
(
FieldDescriptor
type
)
{
if
(
type
.
MappedType
==
MappedType
.
Message
)
{
throw
new
ArgumentException
(
"ExtensionRegistry.Add() must be provided a default instance "
+
"when adding an embedded message extension."
);
}
Add
(
new
ExtensionInfo
(
type
,
null
));
}
/// <summary>
/// Adds a message-type-extension to the registry by descriptor.
/// </summary>
/// <param name="type"></param>
/// <param name="defaultInstance"></param>
public
void
Add
(
FieldDescriptor
type
,
IMessage
defaultInstance
)
{
if
(
type
.
MappedType
!=
MappedType
.
Message
)
{
throw
new
ArgumentException
(
"ExtensionRegistry.Add() provided a default instance for a "
+
"non-message extension."
);
}
Add
(
new
ExtensionInfo
(
type
,
defaultInstance
));
}
private
void
Add
(
ExtensionInfo
extension
)
{
if
(
readOnly
)
{
if
(
readOnly
)
{
throw
new
InvalidOperationException
(
"Cannot add entries to a read-only extension registry"
);
throw
new
InvalidOperationException
(
"Cannot add entries to a read-only extension registry"
);
}
}
if
(!
extension
.
Descriptor
.
IsExtension
)
{
extensionsByNumber
.
Add
(
throw
new
ArgumentException
(
"ExtensionRegistry.add() was given a FieldDescriptor for a "
new
ExtensionIntPair
(
extension
.
ContainingType
,
extension
.
Number
),
+
"regular (non-extension) field."
);
extension
);
}
extensionsByName
[
extension
.
Descriptor
.
FullName
]
=
extension
;
extensionsByNumber
[
new
DescriptorIntPair
(
extension
.
Descriptor
.
ContainingType
,
extension
.
Descriptor
.
FieldNumber
)]
=
extension
;
FieldDescriptor
field
=
extension
.
Descriptor
;
if
(
field
.
ContainingType
.
Options
.
MessageSetWireFormat
&&
field
.
FieldType
==
FieldType
.
Message
&&
field
.
IsOptional
&&
field
.
ExtensionScope
==
field
.
MessageType
)
{
// This is an extension of a MessageSet type defined within the extension
// type's own scope. For backwards-compatibility, allow it to be looked
// up by type name.
extensionsByName
[
field
.
MessageType
.
FullName
]
=
extension
;
}
}
}
/// <summary>
/// <summary>
/// Nested type just used to represent a pair of MessageDescriptor and int, as
/// Nested type just used to represent a pair of MessageDescriptor and int, as
/// the key into the "by number" map.
/// the key into the "by number" map.
/// </summary>
/// </summary>
pr
ivate
struct
DescriptorIntPair
:
IEquatable
<
Descriptor
IntPair
>
{
pr
otected
struct
ExtensionIntPair
:
IEquatable
<
Extension
IntPair
>
{
readonly
MessageDescriptor
descriptor
;
readonly
object
msgType
;
readonly
int
number
;
readonly
int
number
;
internal
DescriptorIntPair
(
MessageDescriptor
descriptor
,
int
number
)
{
internal
ExtensionIntPair
(
object
msgType
,
int
number
)
{
this
.
descriptor
=
descriptor
;
this
.
msgType
=
msgType
;
this
.
number
=
number
;
this
.
number
=
number
;
}
}
public
override
int
GetHashCode
()
{
public
override
int
GetHashCode
()
{
return
descriptor
.
GetHashCode
()
*
((
1
<<
16
)
-
1
)
+
number
;
return
msgType
.
GetHashCode
()
*
((
1
<<
16
)
-
1
)
+
number
;
}
}
public
override
bool
Equals
(
object
obj
)
{
public
override
bool
Equals
(
object
obj
)
{
if
(!(
obj
is
Descriptor
IntPair
))
{
if
(!(
obj
is
Extension
IntPair
))
{
return
false
;
return
false
;
}
}
return
Equals
((
Descriptor
IntPair
)
obj
);
return
Equals
((
Extension
IntPair
)
obj
);
}
}
public
bool
Equals
(
Descriptor
IntPair
other
)
{
public
bool
Equals
(
Extension
IntPair
other
)
{
return
descriptor
==
other
.
descriptor
&&
number
==
other
.
number
;
return
msgType
.
Equals
(
other
.
msgType
)
&&
number
==
other
.
number
;
}
}
}
}
}
}
...
...
src/ProtocolBuffers/GeneratedExtensionBase.cs
View file @
d9c59e66
...
@@ -39,6 +39,7 @@ using System.Reflection;
...
@@ -39,6 +39,7 @@ using System.Reflection;
using
Google.ProtocolBuffers.Descriptors
;
using
Google.ProtocolBuffers.Descriptors
;
namespace
Google.ProtocolBuffers
{
namespace
Google.ProtocolBuffers
{
/// <summary>
/// <summary>
/// Base type for all generated extensions.
/// Base type for all generated extensions.
/// </summary>
/// </summary>
...
@@ -87,6 +88,10 @@ namespace Google.ProtocolBuffers {
...
@@ -87,6 +88,10 @@ namespace Google.ProtocolBuffers {
get
{
return
descriptor
;
}
get
{
return
descriptor
;
}
}
}
public
int
Number
{
get
{
return
Descriptor
.
FieldNumber
;
}
}
/// <summary>
/// <summary>
/// Returns the default message instance for extensions which are message types.
/// Returns the default message instance for extensions which are message types.
/// </summary>
/// </summary>
...
...
src/ProtocolBuffers/GeneratedExtensionLite.cs
0 → 100644
View file @
d9c59e66
using
System
;
namespace
Google.ProtocolBuffers
{
public
interface
IGeneratedExtensionLite
{
int
Number
{
get
;
}
object
ContainingType
{
get
;
}
IMessageLite
MessageDefaultInstance
{
get
;
}
}
public
class
GeneratedExtensionLite
:
IGeneratedExtensionLite
{
public
int
Number
{
get
{
throw
new
NotImplementedException
();
}
}
public
object
ContainingType
{
get
{
throw
new
NotImplementedException
();
}
}
public
IMessageLite
MessageDefaultInstance
{
get
{
throw
new
NotImplementedException
();
}
}
}
}
\ No newline at end of file
src/ProtocolBuffers/IBuilder.cs
View file @
d9c59e66
...
@@ -47,12 +47,12 @@ namespace Google.ProtocolBuffers {
...
@@ -47,12 +47,12 @@ namespace Google.ProtocolBuffers {
/// use explicit interface implemenation for the non-generic form. This mirrors
/// use explicit interface implemenation for the non-generic form. This mirrors
/// how IEnumerable and IEnumerable<T> work.
/// how IEnumerable and IEnumerable<T> work.
/// </summary>
/// </summary>
public
interface
IBuilder
{
public
interface
IBuilder
:
IBuilderLite
{
/// <summary>
/// <summary>
/// Returns true iff all required fields in the message and all
/// Returns true iff all required fields in the message and all
/// embedded messages are set.
/// embedded messages are set.
/// </summary>
/// </summary>
bool
IsInitialized
{
get
;
}
new
bool
IsInitialized
{
get
;
}
/// <summary>
/// <summary>
/// Only present in the nongeneric interface - useful for tests, but
/// Only present in the nongeneric interface - useful for tests, but
...
@@ -119,17 +119,17 @@ namespace Google.ProtocolBuffers {
...
@@ -119,17 +119,17 @@ namespace Google.ProtocolBuffers {
#
region
Methods
which
are
like
those
of
the
generic
form
,
but
without
any
knowledge
of
the
type
parameters
#
region
Methods
which
are
like
those
of
the
generic
form
,
but
without
any
knowledge
of
the
type
parameters
IBuilder
WeakAddRepeatedField
(
FieldDescriptor
field
,
object
value
);
IBuilder
WeakAddRepeatedField
(
FieldDescriptor
field
,
object
value
);
IBuilder
WeakClear
();
new
IBuilder
WeakClear
();
IBuilder
WeakClearField
(
FieldDescriptor
field
);
IBuilder
WeakClearField
(
FieldDescriptor
field
);
IBuilder
WeakMergeFrom
(
IMessage
message
);
IBuilder
WeakMergeFrom
(
IMessage
message
);
IBuilder
WeakMergeFrom
(
ByteString
data
);
new
IBuilder
WeakMergeFrom
(
ByteString
data
);
IBuilder
WeakMergeFrom
(
ByteString
data
,
ExtensionRegistry
registry
);
new
IBuilder
WeakMergeFrom
(
ByteString
data
,
ExtensionRegistryLite
registry
);
IBuilder
WeakMergeFrom
(
CodedInputStream
input
);
new
IBuilder
WeakMergeFrom
(
CodedInputStream
input
);
IBuilder
WeakMergeFrom
(
CodedInputStream
input
,
ExtensionRegistry
registry
);
new
IBuilder
WeakMergeFrom
(
CodedInputStream
input
,
ExtensionRegistryLite
registry
);
IMessage
WeakBuild
();
new
IMessage
WeakBuild
();
IMessage
WeakBuildPartial
();
new
IMessage
WeakBuildPartial
();
IBuilder
WeakClone
();
new
IBuilder
WeakClone
();
IMessage
WeakDefaultInstanceForType
{
get
;
}
new
IMessage
WeakDefaultInstanceForType
{
get
;
}
#
endregion
#
endregion
}
}
...
@@ -139,7 +139,7 @@ namespace Google.ProtocolBuffers {
...
@@ -139,7 +139,7 @@ namespace Google.ProtocolBuffers {
/// </summary>
/// </summary>
/// <typeparam name="TMessage">Type of message</typeparam>
/// <typeparam name="TMessage">Type of message</typeparam>
/// <typeparam name="TBuilder">Type of builder</typeparam>
/// <typeparam name="TBuilder">Type of builder</typeparam>
public
interface
IBuilder
<
TMessage
,
TBuilder
>
:
IBuilder
public
interface
IBuilder
<
TMessage
,
TBuilder
>
:
IBuilder
,
IBuilderLite
<
TMessage
,
TBuilder
>
where
TMessage
:
IMessage
<
TMessage
,
TBuilder
>
where
TMessage
:
IMessage
<
TMessage
,
TBuilder
>
where
TBuilder
:
IBuilder
<
TMessage
,
TBuilder
>
{
where
TBuilder
:
IBuilder
<
TMessage
,
TBuilder
>
{
...
@@ -148,7 +148,7 @@ namespace Google.ProtocolBuffers {
...
@@ -148,7 +148,7 @@ namespace Google.ProtocolBuffers {
/// <summary>
/// <summary>
/// Resets all fields to their default values.
/// Resets all fields to their default values.
/// </summary>
/// </summary>
TBuilder
Clear
();
new
TBuilder
Clear
();
/// <summary>
/// <summary>
/// Merge the specified other message into the message being
/// Merge the specified other message into the message being
...
@@ -163,7 +163,7 @@ namespace Google.ProtocolBuffers {
...
@@ -163,7 +163,7 @@ namespace Google.ProtocolBuffers {
/// </summary>
/// </summary>
/// <param name="other"></param>
/// <param name="other"></param>
/// <returns></returns>
/// <returns></returns>
TBuilder
MergeFrom
(
TMessage
other
);
new
TBuilder
MergeFrom
(
TMessage
other
);
/// <summary>
/// <summary>
/// Merge the specified other message which may be a different implementation of
/// Merge the specified other message which may be a different implementation of
...
@@ -180,19 +180,19 @@ namespace Google.ProtocolBuffers {
...
@@ -180,19 +180,19 @@ namespace Google.ProtocolBuffers {
/// <exception cref="UninitializedMessageException">the message
/// <exception cref="UninitializedMessageException">the message
/// is missing one or more required fields; use BuildPartial to bypass
/// is missing one or more required fields; use BuildPartial to bypass
/// this check</exception>
/// this check</exception>
TMessage
Build
();
new
TMessage
Build
();
/// <summary>
/// <summary>
/// Like Build(), but does not throw an exception if the message is missing
/// Like Build(), but does not throw an exception if the message is missing
/// required fields. Instead, a partial message is returned.
/// required fields. Instead, a partial message is returned.
/// </summary>
/// </summary>
TMessage
BuildPartial
();
new
TMessage
BuildPartial
();
/// <summary>
/// <summary>
/// Clones this builder.
/// Clones this builder.
/// TODO(jonskeet): Explain depth of clone.
/// TODO(jonskeet): Explain depth of clone.
/// </summary>
/// </summary>
TBuilder
Clone
();
new
TBuilder
Clone
();
/// <summary>
/// <summary>
/// Parses a message of this type from the input and merges it with this
/// Parses a message of this type from the input and merges it with this
...
@@ -213,7 +213,7 @@ namespace Google.ProtocolBuffers {
...
@@ -213,7 +213,7 @@ namespace Google.ProtocolBuffers {
/// Use BuildPartial to build, which ignores missing required fields.
/// Use BuildPartial to build, which ignores missing required fields.
/// </list>
/// </list>
/// </remarks>
/// </remarks>
TBuilder
MergeFrom
(
CodedInputStream
input
);
new
TBuilder
MergeFrom
(
CodedInputStream
input
);
/// <summary>
/// <summary>
/// Like MergeFrom(CodedInputStream), but also parses extensions.
/// Like MergeFrom(CodedInputStream), but also parses extensions.
...
@@ -221,13 +221,13 @@ namespace Google.ProtocolBuffers {
...
@@ -221,13 +221,13 @@ namespace Google.ProtocolBuffers {
/// in <paramref name="extensionRegistry"/>. Extensions not in the registry
/// in <paramref name="extensionRegistry"/>. Extensions not in the registry
/// will be treated as unknown fields.
/// will be treated as unknown fields.
/// </summary>
/// </summary>
TBuilder
MergeFrom
(
CodedInputStream
input
,
ExtensionRegistry
extensionRegistry
);
new
TBuilder
MergeFrom
(
CodedInputStream
input
,
ExtensionRegistryLite
extensionRegistry
);
/// <summary>
/// <summary>
/// Get's the message's type's default instance.
/// Get's the message's type's default instance.
/// <see cref="IMessage{TMessage}.DefaultInstanceForType" />
/// <see cref="IMessage{TMessage}.DefaultInstanceForType" />
/// </summary>
/// </summary>
TMessage
DefaultInstanceForType
{
get
;
}
new
TMessage
DefaultInstanceForType
{
get
;
}
/// <summary>
/// <summary>
/// Clears the field. This is exactly equivalent to calling the generated
/// Clears the field. This is exactly equivalent to calling the generated
...
@@ -258,12 +258,12 @@ namespace Google.ProtocolBuffers {
...
@@ -258,12 +258,12 @@ namespace Google.ProtocolBuffers {
/// write messages in this format.
/// write messages in this format.
/// </summary>
/// </summary>
/// <param name="input"></param>
/// <param name="input"></param>
TBuilder
MergeDelimitedFrom
(
Stream
input
);
new
TBuilder
MergeDelimitedFrom
(
Stream
input
);
/// <summary>
/// <summary>
/// Like MergeDelimitedFrom(Stream) but supporting extensions.
/// Like MergeDelimitedFrom(Stream) but supporting extensions.
/// </summary>
/// </summary>
TBuilder
MergeDelimitedFrom
(
Stream
input
,
ExtensionRegistry
extensionRegistry
);
new
TBuilder
MergeDelimitedFrom
(
Stream
input
,
ExtensionRegistryLite
extensionRegistry
);
#
region
Convenience
methods
#
region
Convenience
methods
/// <summary>
/// <summary>
...
@@ -271,28 +271,28 @@ namespace Google.ProtocolBuffers {
...
@@ -271,28 +271,28 @@ namespace Google.ProtocolBuffers {
/// it with the message being built. This is just a small wrapper around
/// it with the message being built. This is just a small wrapper around
/// MergeFrom(CodedInputStream).
/// MergeFrom(CodedInputStream).
/// </summary>
/// </summary>
TBuilder
MergeFrom
(
ByteString
data
);
new
TBuilder
MergeFrom
(
ByteString
data
);
/// <summary>
/// <summary>
/// Parse <paramref name="data"/> as a message of this type and merge
/// Parse <paramref name="data"/> as a message of this type and merge
/// it with the message being built. This is just a small wrapper around
/// it with the message being built. This is just a small wrapper around
/// MergeFrom(CodedInputStream, ExtensionRegistry).
/// MergeFrom(CodedInputStream, ExtensionRegistry
Lite
).
/// </summary>
/// </summary>
TBuilder
MergeFrom
(
ByteString
data
,
ExtensionRegistry
extensionRegistry
);
new
TBuilder
MergeFrom
(
ByteString
data
,
ExtensionRegistryLite
extensionRegistry
);
/// <summary>
/// <summary>
/// Parse <paramref name="data"/> as a message of this type and merge
/// Parse <paramref name="data"/> as a message of this type and merge
/// it with the message being built. This is just a small wrapper around
/// it with the message being built. This is just a small wrapper around
/// MergeFrom(CodedInputStream).
/// MergeFrom(CodedInputStream).
/// </summary>
/// </summary>
TBuilder
MergeFrom
(
byte
[]
data
);
new
TBuilder
MergeFrom
(
byte
[]
data
);
/// <summary>
/// <summary>
/// Parse <paramref name="data"/> as a message of this type and merge
/// Parse <paramref name="data"/> as a message of this type and merge
/// it with the message being built. This is just a small wrapper around
/// it with the message being built. This is just a small wrapper around
/// MergeFrom(CodedInputStream, ExtensionRegistry).
/// MergeFrom(CodedInputStream, ExtensionRegistry
Lite
).
/// </summary>
/// </summary>
TBuilder
MergeFrom
(
byte
[]
data
,
ExtensionRegistry
extensionRegistry
);
new
TBuilder
MergeFrom
(
byte
[]
data
,
ExtensionRegistryLite
extensionRegistry
);
/// <summary>
/// <summary>
/// Parse <paramref name="input"/> as a message of this type and merge
/// Parse <paramref name="input"/> as a message of this type and merge
...
@@ -304,14 +304,14 @@ namespace Google.ProtocolBuffers {
...
@@ -304,14 +304,14 @@ namespace Google.ProtocolBuffers {
/// to write your message and MmergeDelimitedFrom(Stream) to read it.
/// to write your message and MmergeDelimitedFrom(Stream) to read it.
/// Despite usually reading the entire stream, this method never closes the stream.
/// Despite usually reading the entire stream, this method never closes the stream.
/// </summary>
/// </summary>
TBuilder
MergeFrom
(
Stream
input
);
new
TBuilder
MergeFrom
(
Stream
input
);
/// <summary>
/// <summary>
/// Parse <paramref name="input"/> as a message of this type and merge
/// Parse <paramref name="input"/> as a message of this type and merge
/// it with the message being built. This is just a small wrapper around
/// it with the message being built. This is just a small wrapper around
/// MergeFrom(CodedInputStream, ExtensionRegistry).
/// MergeFrom(CodedInputStream, ExtensionRegistry
Lite
).
/// </summary>
/// </summary>
TBuilder
MergeFrom
(
Stream
input
,
ExtensionRegistry
extensionRegistry
);
new
TBuilder
MergeFrom
(
Stream
input
,
ExtensionRegistryLite
extensionRegistry
);
#
endregion
#
endregion
}
}
}
}
src/ProtocolBuffers/IBuilderLite.cs
View file @
d9c59e66
...
@@ -35,7 +35,6 @@
...
@@ -35,7 +35,6 @@
using
System
;
using
System
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System.IO
;
using
System.IO
;
using
Google.ProtocolBuffers.Descriptors
;
namespace
Google.ProtocolBuffers
{
namespace
Google.ProtocolBuffers
{
...
@@ -47,90 +46,23 @@ namespace Google.ProtocolBuffers {
...
@@ -47,90 +46,23 @@ namespace Google.ProtocolBuffers {
/// use explicit interface implemenation for the non-generic form. This mirrors
/// use explicit interface implemenation for the non-generic form. This mirrors
/// how IEnumerable and IEnumerable<T> work.
/// how IEnumerable and IEnumerable<T> work.
/// </summary>
/// </summary>
public
interface
IBuilder
{
public
interface
IBuilder
Lite
{
/// <summary>
/// <summary>
/// Returns true iff all required fields in the message and all
/// Returns true iff all required fields in the message and all
/// embedded messages are set.
/// embedded messages are set.
/// </summary>
/// </summary>
bool
IsInitialized
{
get
;
}
bool
IsInitialized
{
get
;
}
/// <summary>
IBuilderLite
WeakClear
();
/// Only present in the nongeneric interface - useful for tests, but
IBuilderLite
WeakMergeFrom
(
IMessageLite
message
);
/// not as much in real life.
IBuilderLite
WeakMergeFrom
(
ByteString
data
);
/// </summary>
IBuilderLite
WeakMergeFrom
(
ByteString
data
,
ExtensionRegistryLite
registry
);
IBuilder
SetField
(
FieldDescriptor
field
,
object
value
);
IBuilderLite
WeakMergeFrom
(
CodedInputStream
input
);
IBuilderLite
WeakMergeFrom
(
CodedInputStream
input
,
ExtensionRegistryLite
registry
);
/// <summary>
IMessageLite
WeakBuild
();
/// Only present in the nongeneric interface - useful for tests, but
IMessageLite
WeakBuildPartial
();
/// not as much in real life.
IBuilderLite
WeakClone
();
/// </summary>
IMessageLite
WeakDefaultInstanceForType
{
get
;
}
IBuilder
SetRepeatedField
(
FieldDescriptor
field
,
int
index
,
object
value
);
/// <summary>
/// Behaves like the equivalent property in IMessage<T>.
/// The returned map may or may not reflect future changes to the builder.
/// Either way, the returned map is unmodifiable.
/// </summary>
IDictionary
<
FieldDescriptor
,
object
>
AllFields
{
get
;
}
/// <summary>
/// Allows getting and setting of a field.
/// <see cref="IMessage{TMessage, TBuilder}.Item(FieldDescriptor)"/>
/// </summary>
/// <param name="field"></param>
/// <returns></returns>
object
this
[
FieldDescriptor
field
]
{
get
;
set
;
}
/// <summary>
/// Get the message's type descriptor.
/// <see cref="IMessage{TMessage, TBuilder}.DescriptorForType"/>
/// </summary>
MessageDescriptor
DescriptorForType
{
get
;
}
/// <summary>
/// <see cref="IMessage{TMessage, TBuilder}.GetRepeatedFieldCount"/>
/// </summary>
/// <param name="field"></param>
/// <returns></returns>
int
GetRepeatedFieldCount
(
FieldDescriptor
field
);
/// <summary>
/// Allows getting and setting of a repeated field value.
/// <see cref="IMessage{TMessage, TBuilder}.Item(FieldDescriptor, int)"/>
/// </summary>
object
this
[
FieldDescriptor
field
,
int
index
]
{
get
;
set
;
}
/// <summary>
/// <see cref="IMessage{TMessage, TBuilder}.HasField"/>
/// </summary>
bool
HasField
(
FieldDescriptor
field
);
/// <summary>
/// <see cref="IMessage{TMessage, TBuilder}.UnknownFields"/>
/// </summary>
UnknownFieldSet
UnknownFields
{
get
;
set
;
}
/// <summary>
/// Create a builder for messages of the appropriate type for the given field.
/// Messages built with this can then be passed to the various mutation properties
/// and methods.
/// </summary>
IBuilder
CreateBuilderForField
(
FieldDescriptor
field
);
#
region
Methods
which
are
like
those
of
the
generic
form
,
but
without
any
knowledge
of
the
type
parameters
IBuilder
WeakAddRepeatedField
(
FieldDescriptor
field
,
object
value
);
IBuilder
WeakClear
();
IBuilder
WeakClearField
(
FieldDescriptor
field
);
IBuilder
WeakMergeFrom
(
IMessage
message
);
IBuilder
WeakMergeFrom
(
ByteString
data
);
IBuilder
WeakMergeFrom
(
ByteString
data
,
ExtensionRegistry
registry
);
IBuilder
WeakMergeFrom
(
CodedInputStream
input
);
IBuilder
WeakMergeFrom
(
CodedInputStream
input
,
ExtensionRegistry
registry
);
IMessage
WeakBuild
();
IMessage
WeakBuildPartial
();
IBuilder
WeakClone
();
IMessage
WeakDefaultInstanceForType
{
get
;
}
#
endregion
}
}
/// <summary>
/// <summary>
...
@@ -139,11 +71,9 @@ namespace Google.ProtocolBuffers {
...
@@ -139,11 +71,9 @@ namespace Google.ProtocolBuffers {
/// </summary>
/// </summary>
/// <typeparam name="TMessage">Type of message</typeparam>
/// <typeparam name="TMessage">Type of message</typeparam>
/// <typeparam name="TBuilder">Type of builder</typeparam>
/// <typeparam name="TBuilder">Type of builder</typeparam>
public
interface
IBuilder
<
TMessage
,
TBuilder
>
:
IBuilder
public
interface
IBuilderLite
<
TMessage
,
TBuilder
>
:
IBuilderLite
where
TMessage
:
IMessage
<
TMessage
,
TBuilder
>
where
TMessage
:
IMessageLite
<
TMessage
,
TBuilder
>
where
TBuilder
:
IBuilder
<
TMessage
,
TBuilder
>
{
where
TBuilder
:
IBuilderLite
<
TMessage
,
TBuilder
>
{
TBuilder
SetUnknownFields
(
UnknownFieldSet
unknownFields
);
/// <summary>
/// <summary>
/// Resets all fields to their default values.
/// Resets all fields to their default values.
...
@@ -169,7 +99,7 @@ namespace Google.ProtocolBuffers {
...
@@ -169,7 +99,7 @@ namespace Google.ProtocolBuffers {
/// Merge the specified other message which may be a different implementation of
/// Merge the specified other message which may be a different implementation of
/// the same message descriptor.
/// the same message descriptor.
/// </summary>
/// </summary>
TBuilder
MergeFrom
(
IMessage
other
);
TBuilder
MergeFrom
(
IMessage
Lite
other
);
/// <summary>
/// <summary>
/// Constructs the final message. Once this is called, this Builder instance
/// Constructs the final message. Once this is called, this Builder instance
...
@@ -221,36 +151,14 @@ namespace Google.ProtocolBuffers {
...
@@ -221,36 +151,14 @@ namespace Google.ProtocolBuffers {
/// in <paramref name="extensionRegistry"/>. Extensions not in the registry
/// in <paramref name="extensionRegistry"/>. Extensions not in the registry
/// will be treated as unknown fields.
/// will be treated as unknown fields.
/// </summary>
/// </summary>
TBuilder
MergeFrom
(
CodedInputStream
input
,
ExtensionRegistry
extensionRegistry
);
TBuilder
MergeFrom
(
CodedInputStream
input
,
ExtensionRegistry
Lite
extensionRegistry
);
/// <summary>
/// <summary>
/// Get's the message's type's default instance.
/// Get's the message's type's default instance.
/// <see cref="IMessage{TMessage}.DefaultInstanceForType" />
/// <see cref="IMessage
Lite
{TMessage}.DefaultInstanceForType" />
/// </summary>
/// </summary>
TMessage
DefaultInstanceForType
{
get
;
}
TMessage
DefaultInstanceForType
{
get
;
}
/// <summary>
/// Clears the field. This is exactly equivalent to calling the generated
/// Clear method corresponding to the field.
/// </summary>
/// <param name="field"></param>
/// <returns></returns>
TBuilder
ClearField
(
FieldDescriptor
field
);
/// <summary>
/// Appends the given value as a new element for the specified repeated field.
/// </summary>
/// <exception cref="ArgumentException">the field is not a repeated field,
/// the field does not belong to this builder's type, or the value is
/// of the incorrect type
/// </exception>
TBuilder
AddRepeatedField
(
FieldDescriptor
field
,
object
value
);
/// <summary>
/// Merge some unknown fields into the set for this message.
/// </summary>
TBuilder
MergeUnknownFields
(
UnknownFieldSet
unknownFields
);
/// <summary>
/// <summary>
/// Like MergeFrom(Stream), but does not read until the end of the file.
/// Like MergeFrom(Stream), but does not read until the end of the file.
/// Instead, the size of the message (encoded as a varint) is read first,
/// Instead, the size of the message (encoded as a varint) is read first,
...
@@ -263,7 +171,7 @@ namespace Google.ProtocolBuffers {
...
@@ -263,7 +171,7 @@ namespace Google.ProtocolBuffers {
/// <summary>
/// <summary>
/// Like MergeDelimitedFrom(Stream) but supporting extensions.
/// Like MergeDelimitedFrom(Stream) but supporting extensions.
/// </summary>
/// </summary>
TBuilder
MergeDelimitedFrom
(
Stream
input
,
ExtensionRegistry
extensionRegistry
);
TBuilder
MergeDelimitedFrom
(
Stream
input
,
ExtensionRegistry
Lite
extensionRegistry
);
#
region
Convenience
methods
#
region
Convenience
methods
/// <summary>
/// <summary>
...
@@ -278,7 +186,7 @@ namespace Google.ProtocolBuffers {
...
@@ -278,7 +186,7 @@ namespace Google.ProtocolBuffers {
/// it with the message being built. This is just a small wrapper around
/// it with the message being built. This is just a small wrapper around
/// MergeFrom(CodedInputStream, ExtensionRegistry).
/// MergeFrom(CodedInputStream, ExtensionRegistry).
/// </summary>
/// </summary>
TBuilder
MergeFrom
(
ByteString
data
,
ExtensionRegistry
extensionRegistry
);
TBuilder
MergeFrom
(
ByteString
data
,
ExtensionRegistry
Lite
extensionRegistry
);
/// <summary>
/// <summary>
/// Parse <paramref name="data"/> as a message of this type and merge
/// Parse <paramref name="data"/> as a message of this type and merge
...
@@ -292,7 +200,7 @@ namespace Google.ProtocolBuffers {
...
@@ -292,7 +200,7 @@ namespace Google.ProtocolBuffers {
/// it with the message being built. This is just a small wrapper around
/// it with the message being built. This is just a small wrapper around
/// MergeFrom(CodedInputStream, ExtensionRegistry).
/// MergeFrom(CodedInputStream, ExtensionRegistry).
/// </summary>
/// </summary>
TBuilder
MergeFrom
(
byte
[]
data
,
ExtensionRegistry
extensionRegistry
);
TBuilder
MergeFrom
(
byte
[]
data
,
ExtensionRegistry
Lite
extensionRegistry
);
/// <summary>
/// <summary>
/// Parse <paramref name="input"/> as a message of this type and merge
/// Parse <paramref name="input"/> as a message of this type and merge
...
@@ -311,7 +219,7 @@ namespace Google.ProtocolBuffers {
...
@@ -311,7 +219,7 @@ namespace Google.ProtocolBuffers {
/// it with the message being built. This is just a small wrapper around
/// it with the message being built. This is just a small wrapper around
/// MergeFrom(CodedInputStream, ExtensionRegistry).
/// MergeFrom(CodedInputStream, ExtensionRegistry).
/// </summary>
/// </summary>
TBuilder
MergeFrom
(
Stream
input
,
ExtensionRegistry
extensionRegistry
);
TBuilder
MergeFrom
(
Stream
input
,
ExtensionRegistry
Lite
extensionRegistry
);
#
endregion
#
endregion
}
}
}
}
src/ProtocolBuffers/IMessage.cs
View file @
d9c59e66
...
@@ -43,7 +43,7 @@ namespace Google.ProtocolBuffers {
...
@@ -43,7 +43,7 @@ namespace Google.ProtocolBuffers {
/// Non-generic interface used for all parts of the API which don't require
/// Non-generic interface used for all parts of the API which don't require
/// any type knowledge.
/// any type knowledge.
/// </summary>
/// </summary>
public
interface
IMessage
{
public
interface
IMessage
:
IMessageLite
{
/// <summary>
/// <summary>
/// Returns the message's type's descriptor. This differs from the
/// Returns the message's type's descriptor. This differs from the
/// Descriptor property of each generated message class in that this
/// Descriptor property of each generated message class in that this
...
@@ -110,7 +110,7 @@ namespace Google.ProtocolBuffers {
...
@@ -110,7 +110,7 @@ namespace Google.ProtocolBuffers {
/// Returns true iff all required fields in the message and all embedded
/// Returns true iff all required fields in the message and all embedded
/// messages are set.
/// messages are set.
/// </summary>
/// </summary>
bool
IsInitialized
{
get
;
}
new
bool
IsInitialized
{
get
;
}
/// <summary>
/// <summary>
/// Serializes the message and writes it to the given output stream.
/// Serializes the message and writes it to the given output stream.
...
@@ -124,7 +124,7 @@ namespace Google.ProtocolBuffers {
...
@@ -124,7 +124,7 @@ namespace Google.ProtocolBuffers {
/// of the message before the data, then making sure you limit the input to
/// of the message before the data, then making sure you limit the input to
/// that size when receiving the data. Alternatively, use WriteDelimitedTo(Stream).
/// that size when receiving the data. Alternatively, use WriteDelimitedTo(Stream).
/// </remarks>
/// </remarks>
void
WriteTo
(
CodedOutputStream
output
);
new
void
WriteTo
(
CodedOutputStream
output
);
/// <summary>
/// <summary>
/// Like WriteTo(Stream) but writes the size of the message as a varint before
/// Like WriteTo(Stream) but writes the size of the message as a varint before
...
@@ -134,13 +134,13 @@ namespace Google.ProtocolBuffers {
...
@@ -134,13 +134,13 @@ namespace Google.ProtocolBuffers {
/// YourMessageType.ParseDelimitedFrom(Stream) to parse messages written by this method.
/// YourMessageType.ParseDelimitedFrom(Stream) to parse messages written by this method.
/// </summary>
/// </summary>
/// <param name="output"></param>
/// <param name="output"></param>
void
WriteDelimitedTo
(
Stream
output
);
new
void
WriteDelimitedTo
(
Stream
output
);
/// <summary>
/// <summary>
/// Returns the number of bytes required to encode this message.
/// Returns the number of bytes required to encode this message.
/// The result is only computed on the first call and memoized after that.
/// The result is only computed on the first call and memoized after that.
/// </summary>
/// </summary>
int
SerializedSize
{
get
;
}
new
int
SerializedSize
{
get
;
}
#
region
Comparison
and
hashing
#
region
Comparison
and
hashing
/// <summary>
/// <summary>
...
@@ -149,13 +149,13 @@ namespace Google.ProtocolBuffers {
...
@@ -149,13 +149,13 @@ namespace Google.ProtocolBuffers {
/// (as defined by DescriptorForType) and has identical values
/// (as defined by DescriptorForType) and has identical values
/// for all its fields.
/// for all its fields.
/// </summary>
/// </summary>
bool
Equals
(
object
other
);
new
bool
Equals
(
object
other
);
/// <summary>
/// <summary>
/// Returns the hash code value for this message.
/// Returns the hash code value for this message.
/// TODO(jonskeet): Specify the hash algorithm, but better than the Java one!
/// TODO(jonskeet): Specify the hash algorithm, but better than the Java one!
/// </summary>
/// </summary>
int
GetHashCode
();
new
int
GetHashCode
();
#
endregion
#
endregion
#
region
Convenience
methods
#
region
Convenience
methods
...
@@ -163,19 +163,19 @@ namespace Google.ProtocolBuffers {
...
@@ -163,19 +163,19 @@ namespace Google.ProtocolBuffers {
/// Converts the message to a string in protocol buffer text format.
/// Converts the message to a string in protocol buffer text format.
/// This is just a trivial wrapper around TextFormat.PrintToString.
/// This is just a trivial wrapper around TextFormat.PrintToString.
/// </summary>
/// </summary>
string
ToString
();
new
string
ToString
();
/// <summary>
/// <summary>
/// Serializes the message to a ByteString. This is a trivial wrapper
/// Serializes the message to a ByteString. This is a trivial wrapper
/// around WriteTo(CodedOutputStream).
/// around WriteTo(CodedOutputStream).
/// </summary>
/// </summary>
ByteString
ToByteString
();
new
ByteString
ToByteString
();
/// <summary>
/// <summary>
/// Serializes the message to a byte array. This is a trivial wrapper
/// Serializes the message to a byte array. This is a trivial wrapper
/// around WriteTo(CodedOutputStream).
/// around WriteTo(CodedOutputStream).
/// </summary>
/// </summary>
byte
[]
ToByteArray
();
new
byte
[]
ToByteArray
();
/// <summary>
/// <summary>
/// Serializes the message and writes it to the given stream.
/// Serializes the message and writes it to the given stream.
...
@@ -183,7 +183,7 @@ namespace Google.ProtocolBuffers {
...
@@ -183,7 +183,7 @@ namespace Google.ProtocolBuffers {
/// does not flush or close the stream.
/// does not flush or close the stream.
/// </summary>
/// </summary>
/// <param name="output"></param>
/// <param name="output"></param>
void
WriteTo
(
Stream
output
);
new
void
WriteTo
(
Stream
output
);
#
endregion
#
endregion
/// <summary>
/// <summary>
...
@@ -191,19 +191,19 @@ namespace Google.ProtocolBuffers {
...
@@ -191,19 +191,19 @@ namespace Google.ProtocolBuffers {
/// is typically implemented by strongly typed messages by just returning
/// is typically implemented by strongly typed messages by just returning
/// the result of CreateBuilderForType.
/// the result of CreateBuilderForType.
/// </summary>
/// </summary>
IBuilder
WeakCreateBuilderForType
();
new
IBuilder
WeakCreateBuilderForType
();
/// <summary>
/// <summary>
/// Creates a builder with the same contents as this message. This
/// Creates a builder with the same contents as this message. This
/// is typically implemented by strongly typed messages by just returning
/// is typically implemented by strongly typed messages by just returning
/// the result of ToBuilder.
/// the result of ToBuilder.
/// </summary>
/// </summary>
IBuilder
WeakToBuilder
();
new
IBuilder
WeakToBuilder
();
IMessage
WeakDefaultInstanceForType
{
get
;
}
new
IMessage
WeakDefaultInstanceForType
{
get
;
}
}
}
public
interface
IMessage
<
TMessage
>
:
IMessage
{
public
interface
IMessage
<
TMessage
>
:
IMessage
,
IMessageLite
<
TMessage
>
{
/// <summary>
/// <summary>
/// Returns an instance of this message type with all fields set to
/// Returns an instance of this message type with all fields set to
/// their default values. This may or may not be a singleton. This differs
/// their default values. This may or may not be a singleton. This differs
...
@@ -211,26 +211,26 @@ namespace Google.ProtocolBuffers {
...
@@ -211,26 +211,26 @@ namespace Google.ProtocolBuffers {
/// method is an abstract method of IMessage whereas DefaultInstance is
/// method is an abstract method of IMessage whereas DefaultInstance is
/// a static property of a specific class. They return the same thing.
/// a static property of a specific class. They return the same thing.
/// </summary>
/// </summary>
TMessage
DefaultInstanceForType
{
get
;
}
new
TMessage
DefaultInstanceForType
{
get
;
}
}
}
/// <summary>
/// <summary>
/// Type-safe interface for all generated messages to implement.
/// Type-safe interface for all generated messages to implement.
/// </summary>
/// </summary>
public
interface
IMessage
<
TMessage
,
TBuilder
>
:
IMessage
<
TMessage
>
public
interface
IMessage
<
TMessage
,
TBuilder
>
:
IMessage
<
TMessage
>
,
IMessageLite
<
TMessage
,
TBuilder
>
where
TMessage
:
IMessage
<
TMessage
,
TBuilder
>
where
TMessage
:
IMessage
<
TMessage
,
TBuilder
>
where
TBuilder
:
IBuilder
<
TMessage
,
TBuilder
>
{
where
TBuilder
:
IBuilder
<
TMessage
,
TBuilder
>
{
#
region
Builders
#
region
Builders
/// <summary>
/// <summary>
/// Constructs a new builder for a message of the same type as this message.
/// Constructs a new builder for a message of the same type as this message.
/// </summary>
/// </summary>
TBuilder
CreateBuilderForType
();
new
TBuilder
CreateBuilderForType
();
/// <summary>
/// <summary>
/// Creates a builder with the same contents as this current instance.
/// Creates a builder with the same contents as this current instance.
/// This is typically implemented by strongly typed messages by just
/// This is typically implemented by strongly typed messages by just
/// returning the result of ToBuilder().
/// returning the result of ToBuilder().
/// </summary>
/// </summary>
TBuilder
ToBuilder
();
new
TBuilder
ToBuilder
();
#
endregion
#
endregion
}
}
}
}
src/ProtocolBuffers/IMessageLite.cs
View file @
d9c59e66
...
@@ -35,7 +35,6 @@
...
@@ -35,7 +35,6 @@
using
System
;
using
System
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System.IO
;
using
System.IO
;
using
Google.ProtocolBuffers.Descriptors
;
namespace
Google.ProtocolBuffers
{
namespace
Google.ProtocolBuffers
{
...
@@ -43,68 +42,7 @@ namespace Google.ProtocolBuffers {
...
@@ -43,68 +42,7 @@ namespace Google.ProtocolBuffers {
/// Non-generic interface used for all parts of the API which don't require
/// Non-generic interface used for all parts of the API which don't require
/// any type knowledge.
/// any type knowledge.
/// </summary>
/// </summary>
public
interface
IMessage
{
public
interface
IMessageLite
{
/// <summary>
/// Returns the message's type's descriptor. This differs from the
/// Descriptor property of each generated message class in that this
/// method is an abstract method of IMessage whereas Descriptor is
/// a static property of a specific class. They return the same thing.
/// </summary>
MessageDescriptor
DescriptorForType
{
get
;
}
/// <summary>
/// Returns a collection of all the fields in this message which are set
/// and their corresponding values. A singular ("required" or "optional")
/// field is set iff HasField() returns true for that field. A "repeated"
/// field is set iff GetRepeatedFieldSize() is greater than zero. The
/// values are exactly what would be returned by calling
/// GetField(FieldDescriptor) for each field. The map
/// is guaranteed to be a sorted map, so iterating over it will return fields
/// in order by field number.
/// </summary>
IDictionary
<
FieldDescriptor
,
object
>
AllFields
{
get
;
}
/// <summary>
/// Returns true if the given field is set. This is exactly equivalent
/// to calling the generated "Has" property corresponding to the field.
/// </summary>
/// <exception cref="ArgumentException">the field is a repeated field,
/// or it's not a field of this type</exception>
bool
HasField
(
FieldDescriptor
field
);
/// <summary>
/// Obtains the value of the given field, or the default value if
/// it isn't set. For value type fields, the boxed value is returned.
/// For enum fields, the EnumValueDescriptor for the enum is returned.
/// For embedded message fields, the sub-message
/// is returned. For repeated fields, an IList<T> is returned.
/// </summary>
object
this
[
FieldDescriptor
field
]
{
get
;
}
/// <summary>
/// Returns the number of elements of a repeated field. This is
/// exactly equivalent to calling the generated "Count" property
/// corresponding to the field.
/// </summary>
/// <exception cref="ArgumentException">the field is not a repeated field,
/// or it's not a field of this type</exception>
int
GetRepeatedFieldCount
(
FieldDescriptor
field
);
/// <summary>
/// Gets an element of a repeated field. For value type fields
/// excluding enums, the boxed value is returned. For embedded
/// message fields, the sub-message is returned. For enums, the
/// relevant EnumValueDescriptor is returned.
/// </summary>
/// <exception cref="ArgumentException">the field is not a repeated field,
/// or it's not a field of this type</exception>
/// <exception cref="ArgumentOutOfRangeException">the index is out of
/// range for the repeated field's value</exception>
object
this
[
FieldDescriptor
field
,
int
index
]
{
get
;
}
/// <summary>
/// Returns the unknown fields for this message.
/// </summary>
UnknownFieldSet
UnknownFields
{
get
;
}
/// <summary>
/// <summary>
/// Returns true iff all required fields in the message and all embedded
/// Returns true iff all required fields in the message and all embedded
...
@@ -191,19 +129,19 @@ namespace Google.ProtocolBuffers {
...
@@ -191,19 +129,19 @@ namespace Google.ProtocolBuffers {
/// is typically implemented by strongly typed messages by just returning
/// is typically implemented by strongly typed messages by just returning
/// the result of CreateBuilderForType.
/// the result of CreateBuilderForType.
/// </summary>
/// </summary>
IBuilder
WeakCreateBuilderForType
();
IBuilder
Lite
WeakCreateBuilderForType
();
/// <summary>
/// <summary>
/// Creates a builder with the same contents as this message. This
/// Creates a builder with the same contents as this message. This
/// is typically implemented by strongly typed messages by just returning
/// is typically implemented by strongly typed messages by just returning
/// the result of ToBuilder.
/// the result of ToBuilder.
/// </summary>
/// </summary>
IBuilder
WeakToBuilder
();
IBuilder
Lite
WeakToBuilder
();
IMessage
WeakDefaultInstanceForType
{
get
;
}
IMessage
Lite
WeakDefaultInstanceForType
{
get
;
}
}
}
public
interface
IMessage
<
TMessage
>
:
IMessag
e
{
public
interface
IMessage
Lite
<
TMessage
>
:
IMessageLit
e
{
/// <summary>
/// <summary>
/// Returns an instance of this message type with all fields set to
/// Returns an instance of this message type with all fields set to
/// their default values. This may or may not be a singleton. This differs
/// their default values. This may or may not be a singleton. This differs
...
@@ -217,9 +155,9 @@ namespace Google.ProtocolBuffers {
...
@@ -217,9 +155,9 @@ namespace Google.ProtocolBuffers {
/// <summary>
/// <summary>
/// Type-safe interface for all generated messages to implement.
/// Type-safe interface for all generated messages to implement.
/// </summary>
/// </summary>
public
interface
IMessage
<
TMessage
,
TBuilder
>
:
IMessag
e
<
TMessage
>
public
interface
IMessage
Lite
<
TMessage
,
TBuilder
>
:
IMessageLit
e
<
TMessage
>
where
TMessage
:
IMessage
<
TMessage
,
TBuilder
>
where
TMessage
:
IMessage
Lite
<
TMessage
,
TBuilder
>
where
TBuilder
:
IBuilder
<
TMessage
,
TBuilder
>
{
where
TBuilder
:
IBuilder
Lite
<
TMessage
,
TBuilder
>
{
#
region
Builders
#
region
Builders
/// <summary>
/// <summary>
/// Constructs a new builder for a message of the same type as this message.
/// Constructs a new builder for a message of the same type as this message.
...
...
src/ProtocolBuffers/ProtocolBuffers.csproj
View file @
d9c59e66
...
@@ -84,8 +84,11 @@
...
@@ -84,8 +84,11 @@
<Compile
Include=
"DynamicMessage.cs"
/>
<Compile
Include=
"DynamicMessage.cs"
/>
<Compile
Include=
"ExtendableBuilder.cs"
/>
<Compile
Include=
"ExtendableBuilder.cs"
/>
<Compile
Include=
"ExtendableMessage.cs"
/>
<Compile
Include=
"ExtendableMessage.cs"
/>
<Compile
Include=
"ExtensionInfo.cs"
/>
<Compile
Include=
"ExtensionInfo.cs"
>
<SubType>
Code
</SubType>
</Compile>
<Compile
Include=
"ExtensionRegistry.cs"
/>
<Compile
Include=
"ExtensionRegistry.cs"
/>
<Compile
Include=
"ExtensionRegistryLite.cs"
/>
<Compile
Include=
"FieldAccess\ReflectionUtil.cs"
/>
<Compile
Include=
"FieldAccess\ReflectionUtil.cs"
/>
<Compile
Include=
"FieldAccess\SingleEnumAccessor.cs"
/>
<Compile
Include=
"FieldAccess\SingleEnumAccessor.cs"
/>
<Compile
Include=
"FieldAccess\SingleMessageAccessor.cs"
/>
<Compile
Include=
"FieldAccess\SingleMessageAccessor.cs"
/>
...
@@ -97,12 +100,17 @@
...
@@ -97,12 +100,17 @@
<Compile
Include=
"FieldAccess\RepeatedMessageAccessor.cs"
/>
<Compile
Include=
"FieldAccess\RepeatedMessageAccessor.cs"
/>
<Compile
Include=
"FieldSet.cs"
/>
<Compile
Include=
"FieldSet.cs"
/>
<Compile
Include=
"GeneratedBuilder.cs"
/>
<Compile
Include=
"GeneratedBuilder.cs"
/>
<Compile
Include=
"GeneratedExtensionLite.cs"
/>
<Compile
Include=
"GeneratedRepeatExtension.cs"
/>
<Compile
Include=
"GeneratedRepeatExtension.cs"
/>
<Compile
Include=
"GeneratedSingleExtension.cs"
/>
<Compile
Include=
"GeneratedSingleExtension.cs"
/>
<Compile
Include=
"GeneratedMessage.cs"
/>
<Compile
Include=
"GeneratedMessage.cs"
/>
<Compile
Include=
"IBuilder.cs"
/>
<Compile
Include=
"IBuilder.cs"
/>
<Compile
Include=
"GeneratedExtensionBase.cs"
/>
<Compile
Include=
"GeneratedExtensionBase.cs"
/>
<Compile
Include=
"IBuilderLite.cs"
>
<SubType>
Code
</SubType>
</Compile>
<Compile
Include=
"IMessage.cs"
/>
<Compile
Include=
"IMessage.cs"
/>
<Compile
Include=
"IMessageLite.cs"
/>
<Compile
Include=
"InvalidProtocolBufferException.cs"
/>
<Compile
Include=
"InvalidProtocolBufferException.cs"
/>
<Compile
Include=
"IRpcChannel.cs"
/>
<Compile
Include=
"IRpcChannel.cs"
/>
<Compile
Include=
"IRpcController.cs"
/>
<Compile
Include=
"IRpcController.cs"
/>
...
...
src/ProtocolBuffers/UninitializedMessageException.cs
View file @
d9c59e66
...
@@ -36,8 +36,10 @@ using System;
...
@@ -36,8 +36,10 @@ using System;
using
System.Collections
;
using
System.Collections
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System.Text
;
using
System.Text
;
#if !LITE
using
Google.ProtocolBuffers.Collections
;
using
Google.ProtocolBuffers.Collections
;
using
Google.ProtocolBuffers.Descriptors
;
using
Google.ProtocolBuffers.Descriptors
;
#endif
namespace
Google.ProtocolBuffers
{
namespace
Google.ProtocolBuffers
{
/// <summary>
/// <summary>
...
@@ -47,13 +49,9 @@ namespace Google.ProtocolBuffers {
...
@@ -47,13 +49,9 @@ namespace Google.ProtocolBuffers {
private
readonly
IList
<
string
>
missingFields
;
private
readonly
IList
<
string
>
missingFields
;
public
UninitializedMessageException
(
IMessage
message
)
:
this
(
FindMissingFields
(
message
))
{
}
private
UninitializedMessageException
(
IList
<
string
>
missingFields
)
private
UninitializedMessageException
(
IList
<
string
>
missingFields
)
:
base
(
BuildDescription
(
missingFields
))
{
:
base
(
BuildDescription
(
missingFields
))
{
this
.
missingFields
=
Lists
.
AsReadOnly
(
missingFields
);
this
.
missingFields
=
new
List
<
string
>
(
missingFields
);
}
}
...
@@ -92,6 +90,11 @@ namespace Google.ProtocolBuffers {
...
@@ -92,6 +90,11 @@ namespace Google.ProtocolBuffers {
return
description
.
ToString
();
return
description
.
ToString
();
}
}
#if !LITE
public
UninitializedMessageException
(
IMessage
message
)
:
this
(
FindMissingFields
(
message
))
{
}
/// <summary>
/// <summary>
/// Returns a list of the full "paths" of missing required
/// Returns a list of the full "paths" of missing required
/// fields in the specified message.
/// fields in the specified message.
...
@@ -148,5 +151,6 @@ namespace Google.ProtocolBuffers {
...
@@ -148,5 +151,6 @@ namespace Google.ProtocolBuffers {
result
.
Append
(
'.'
);
result
.
Append
(
'.'
);
return
result
.
ToString
();
return
result
.
ToString
();
}
}
#endif
}
}
}
}
src/ProtocolBuffers/UnknownField.cs
View file @
d9c59e66
...
@@ -172,7 +172,9 @@ namespace Google.ProtocolBuffers {
...
@@ -172,7 +172,9 @@ namespace Google.ProtocolBuffers {
output
.
WriteBytes
(
fieldNumber
,
value
);
output
.
WriteBytes
(
fieldNumber
,
value
);
}
}
foreach
(
UnknownFieldSet
value
in
groupList
)
{
foreach
(
UnknownFieldSet
value
in
groupList
)
{
#pragma warning disable 0612
output
.
WriteUnknownGroup
(
fieldNumber
,
value
);
output
.
WriteUnknownGroup
(
fieldNumber
,
value
);
#pragma warning restore 0612
}
}
}
}
...
@@ -195,7 +197,9 @@ namespace Google.ProtocolBuffers {
...
@@ -195,7 +197,9 @@ namespace Google.ProtocolBuffers {
result
+=
CodedOutputStream
.
ComputeBytesSize
(
fieldNumber
,
value
);
result
+=
CodedOutputStream
.
ComputeBytesSize
(
fieldNumber
,
value
);
}
}
foreach
(
UnknownFieldSet
value
in
groupList
)
{
foreach
(
UnknownFieldSet
value
in
groupList
)
{
#pragma warning disable 0612
result
+=
CodedOutputStream
.
ComputeUnknownGroupSize
(
fieldNumber
,
value
);
result
+=
CodedOutputStream
.
ComputeUnknownGroupSize
(
fieldNumber
,
value
);
#pragma warning restore 0612
}
}
return
result
;
return
result
;
}
}
...
...
src/ProtocolBuffers/UnknownFieldSet.cs
View file @
d9c59e66
...
@@ -51,7 +51,7 @@ namespace Google.ProtocolBuffers {
...
@@ -51,7 +51,7 @@ namespace Google.ProtocolBuffers {
///
///
/// Most users will never need to use this class directly.
/// Most users will never need to use this class directly.
/// </summary>
/// </summary>
public
sealed
class
UnknownFieldSet
{
public
sealed
class
UnknownFieldSet
:
IMessageLite
{
private
static
readonly
UnknownFieldSet
defaultInstance
=
new
UnknownFieldSet
(
new
Dictionary
<
int
,
UnknownField
>());
private
static
readonly
UnknownFieldSet
defaultInstance
=
new
UnknownFieldSet
(
new
Dictionary
<
int
,
UnknownField
>());
...
@@ -237,16 +237,43 @@ namespace Google.ProtocolBuffers {
...
@@ -237,16 +237,43 @@ namespace Google.ProtocolBuffers {
return
CreateBuilder
().
MergeFrom
(
input
).
Build
();
return
CreateBuilder
().
MergeFrom
(
input
).
Build
();
}
}
#
region
IMessageLite
Members
public
bool
IsInitialized
{
get
{
return
fields
!=
null
;
}
}
public
void
WriteDelimitedTo
(
Stream
output
)
{
CodedOutputStream
codedOutput
=
CodedOutputStream
.
CreateInstance
(
output
);
codedOutput
.
WriteRawVarint32
((
uint
)
SerializedSize
);
WriteTo
(
codedOutput
);
codedOutput
.
Flush
();
}
public
IBuilderLite
WeakCreateBuilderForType
()
{
return
new
Builder
();
}
public
IBuilderLite
WeakToBuilder
()
{
return
new
Builder
(
fields
);
}
public
IMessageLite
WeakDefaultInstanceForType
{
get
{
return
defaultInstance
;
}
}
#
endregion
/// <summary>
/// <summary>
/// Builder for UnknownFieldSets.
/// Builder for UnknownFieldSets.
/// </summary>
/// </summary>
public
sealed
class
Builder
public
sealed
class
Builder
:
IBuilderLite
{
{
/// <summary>
/// <summary>
/// Mapping from number to field. Note that by using a SortedList we ensure
/// Mapping from number to field. Note that by using a SortedList we ensure
/// that the fields will be serialized in ascending order.
/// that the fields will be serialized in ascending order.
/// </summary>
/// </summary>
private
IDictionary
<
int
,
UnknownField
>
fields
=
new
SortedList
<
int
,
UnknownField
>()
;
private
IDictionary
<
int
,
UnknownField
>
fields
;
// Optimization: We keep around a builder for the last field that was
// Optimization: We keep around a builder for the last field that was
// modified so that we can efficiently add to it multiple times in a
// modified so that we can efficiently add to it multiple times in a
// row (important when parsing an unknown repeated field).
// row (important when parsing an unknown repeated field).
...
@@ -254,6 +281,11 @@ namespace Google.ProtocolBuffers {
...
@@ -254,6 +281,11 @@ namespace Google.ProtocolBuffers {
private
UnknownField
.
Builder
lastField
;
private
UnknownField
.
Builder
lastField
;
internal
Builder
()
{
internal
Builder
()
{
fields
=
new
SortedList
<
int
,
UnknownField
>();
}
internal
Builder
(
IDictionary
<
int
,
UnknownField
>
dictionary
)
{
fields
=
new
SortedList
<
int
,
UnknownField
>(
dictionary
);
}
}
/// <summary>
/// <summary>
...
@@ -356,7 +388,9 @@ namespace Google.ProtocolBuffers {
...
@@ -356,7 +388,9 @@ namespace Google.ProtocolBuffers {
return
true
;
return
true
;
case
WireFormat
.
WireType
.
StartGroup
:
{
case
WireFormat
.
WireType
.
StartGroup
:
{
Builder
subBuilder
=
CreateBuilder
();
Builder
subBuilder
=
CreateBuilder
();
#pragma warning disable 0612
input
.
ReadUnknownGroup
(
number
,
subBuilder
);
input
.
ReadUnknownGroup
(
number
,
subBuilder
);
#pragma warning restore 0612
GetFieldBuilder
(
number
).
AddGroup
(
subBuilder
.
Build
());
GetFieldBuilder
(
number
).
AddGroup
(
subBuilder
.
Build
());
return
true
;
return
true
;
}
}
...
@@ -463,12 +497,14 @@ namespace Google.ProtocolBuffers {
...
@@ -463,12 +497,14 @@ namespace Google.ProtocolBuffers {
return
this
;
return
this
;
}
}
internal
void
MergeFrom
(
CodedInputStream
input
,
ExtensionRegistry
extensionRegistry
,
IBuilder
builder
)
{
internal
void
MergeFrom
(
CodedInputStream
input
,
ExtensionRegistry
Lite
extensionRegistryLite
,
IBuilder
builder
)
{
while
(
true
)
{
while
(
true
)
{
uint
tag
=
input
.
ReadTag
();
uint
tag
=
input
.
ReadTag
();
if
(
tag
==
0
)
{
if
(
tag
==
0
)
{
break
;
break
;
}
}
ExtensionRegistry
extensionRegistry
=
(
extensionRegistryLite
as
ExtensionRegistry
)
??
ExtensionRegistry
.
CreateInstance
();
if
(!
MergeFieldFrom
(
input
,
extensionRegistry
,
builder
,
tag
))
{
if
(!
MergeFieldFrom
(
input
,
extensionRegistry
,
builder
,
tag
))
{
// end group tag
// end group tag
break
;
break
;
...
@@ -485,7 +521,7 @@ namespace Google.ProtocolBuffers {
...
@@ -485,7 +521,7 @@ 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
bool
MergeFieldFrom
(
CodedInputStream
input
,
internal
bool
MergeFieldFrom
(
CodedInputStream
input
,
ExtensionRegistry
extensionRegistry
,
IBuilder
builder
,
uint
tag
)
{
ExtensionRegistry
extensionRegistry
,
IBuilder
builder
,
uint
tag
)
{
MessageDescriptor
type
=
builder
.
DescriptorForType
;
MessageDescriptor
type
=
builder
.
DescriptorForType
;
...
@@ -672,6 +708,54 @@ namespace Google.ProtocolBuffers {
...
@@ -672,6 +708,54 @@ namespace Google.ProtocolBuffers {
builder
[
field
]
=
subBuilder
.
WeakBuild
();
builder
[
field
]
=
subBuilder
.
WeakBuild
();
}
}
}
}
#
region
IBuilderLite
Members
bool
IBuilderLite
.
IsInitialized
{
get
{
return
fields
!=
null
;
}
}
IBuilderLite
IBuilderLite
.
WeakClear
()
{
return
Clear
();
}
IBuilderLite
IBuilderLite
.
WeakMergeFrom
(
IMessageLite
message
)
{
return
MergeFrom
((
UnknownFieldSet
)
message
);
}
IBuilderLite
IBuilderLite
.
WeakMergeFrom
(
ByteString
data
)
{
return
MergeFrom
(
data
);
}
IBuilderLite
IBuilderLite
.
WeakMergeFrom
(
ByteString
data
,
ExtensionRegistryLite
registry
)
{
return
MergeFrom
(
data
);
}
IBuilderLite
IBuilderLite
.
WeakMergeFrom
(
CodedInputStream
input
)
{
return
MergeFrom
(
input
);
}
IBuilderLite
IBuilderLite
.
WeakMergeFrom
(
CodedInputStream
input
,
ExtensionRegistryLite
registry
)
{
return
MergeFrom
(
input
);
}
IMessageLite
IBuilderLite
.
WeakBuild
()
{
return
Build
();
}
IMessageLite
IBuilderLite
.
WeakBuildPartial
()
{
return
Build
();
}
IBuilderLite
IBuilderLite
.
WeakClone
()
{
return
Build
().
WeakToBuilder
();
}
IMessageLite
IBuilderLite
.
WeakDefaultInstanceForType
{
get
{
return
DefaultInstance
;
}
}
#
endregion
}
}
}
}
}
}
src/ProtocolBuffers/WireFormat.cs
View file @
d9c59e66
...
@@ -33,7 +33,9 @@
...
@@ -33,7 +33,9 @@
#endregion
#endregion
using
System
;
using
System
;
#if !LITE
using
Google.ProtocolBuffers.Descriptors
;
using
Google.ProtocolBuffers.Descriptors
;
#endif
namespace
Google.ProtocolBuffers
{
namespace
Google.ProtocolBuffers
{
...
@@ -115,6 +117,7 @@ namespace Google.ProtocolBuffers {
...
@@ -115,6 +117,7 @@ namespace Google.ProtocolBuffers {
return
(
uint
)
(
fieldNumber
<<
TagTypeBits
)
|
(
uint
)
wireType
;
return
(
uint
)
(
fieldNumber
<<
TagTypeBits
)
|
(
uint
)
wireType
;
}
}
#if !LITE
[
CLSCompliant
(
false
)]
[
CLSCompliant
(
false
)]
public
static
uint
MakeTag
(
FieldDescriptor
field
)
{
public
static
uint
MakeTag
(
FieldDescriptor
field
)
{
return
MakeTag
(
field
.
FieldNumber
,
GetWireType
(
field
));
return
MakeTag
(
field
.
FieldNumber
,
GetWireType
(
field
));
...
@@ -170,5 +173,6 @@ namespace Google.ProtocolBuffers {
...
@@ -170,5 +173,6 @@ namespace Google.ProtocolBuffers {
throw
new
ArgumentOutOfRangeException
(
"No such field type"
);
throw
new
ArgumentOutOfRangeException
(
"No such field type"
);
}
}
}
}
#endif
}
}
}
}
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