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
49fcd4f7
Commit
49fcd4f7
authored
Jan 27, 2009
by
Jon Skeet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merge extensions correctly
parent
642a8140
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
21 additions
and
7 deletions
+21
-7
MessageGenerator.cs
src/ProtoGen/MessageGenerator.cs
+4
-0
GeneratedMessageTest.cs
src/ProtocolBuffers.Test/GeneratedMessageTest.cs
+0
-2
UnitTestMessageSetProtoFile.cs
...colBuffers.Test/TestProtos/UnitTestMessageSetProtoFile.cs
+1
-0
UnitTestProtoFile.cs
src/ProtocolBuffers.Test/TestProtos/UnitTestProtoFile.cs
+3
-0
DescriptorProtoFile.cs
src/ProtocolBuffers/DescriptorProtos/DescriptorProtoFile.cs
+7
-0
DynamicMessage.cs
src/ProtocolBuffers/DynamicMessage.cs
+2
-5
ExtendableBuilder.cs
src/ProtocolBuffers/ExtendableBuilder.cs
+4
-0
No files found.
src/ProtoGen/MessageGenerator.cs
View file @
49fcd4f7
...
@@ -351,6 +351,10 @@ namespace Google.ProtocolBuffers.ProtoGen {
...
@@ -351,6 +351,10 @@ namespace Google.ProtocolBuffers.ProtoGen {
foreach
(
FieldDescriptor
field
in
Descriptor
.
Fields
)
{
foreach
(
FieldDescriptor
field
in
Descriptor
.
Fields
)
{
SourceGenerators
.
CreateFieldGenerator
(
field
).
GenerateMergingCode
(
writer
);
SourceGenerators
.
CreateFieldGenerator
(
field
).
GenerateMergingCode
(
writer
);
}
}
// if message type has extensions
if
(
Descriptor
.
Proto
.
ExtensionRangeCount
>
0
)
{
writer
.
WriteLine
(
" this.MergeExtensionFields(other);"
);
}
writer
.
WriteLine
(
"this.MergeUnknownFields(other.UnknownFields);"
);
writer
.
WriteLine
(
"this.MergeUnknownFields(other.UnknownFields);"
);
writer
.
WriteLine
(
"return this;"
);
writer
.
WriteLine
(
"return this;"
);
writer
.
Outdent
();
writer
.
Outdent
();
...
...
src/ProtocolBuffers.Test/GeneratedMessageTest.cs
View file @
49fcd4f7
...
@@ -313,7 +313,6 @@ namespace Google.ProtocolBuffers {
...
@@ -313,7 +313,6 @@ namespace Google.ProtocolBuffers {
.
GetExtensionCount
(
UnitTestProtoFile
.
RepeatedInt32Extension
));
.
GetExtensionCount
(
UnitTestProtoFile
.
RepeatedInt32Extension
));
}
}
/* Reinstate this test in the commit where it's fixed...
[
Test
]
[
Test
]
public
void
ExtensionMergeFrom
()
{
public
void
ExtensionMergeFrom
()
{
TestAllExtensions
original
=
TestAllExtensions
.
CreateBuilder
()
TestAllExtensions
original
=
TestAllExtensions
.
CreateBuilder
()
...
@@ -323,7 +322,6 @@ namespace Google.ProtocolBuffers {
...
@@ -323,7 +322,6 @@ namespace Google.ProtocolBuffers {
Assert
.
IsTrue
((
merged
.
HasExtension
(
UnitTestProtoFile
.
OptionalInt32Extension
)));
Assert
.
IsTrue
((
merged
.
HasExtension
(
UnitTestProtoFile
.
OptionalInt32Extension
)));
Assert
.
AreEqual
(
1
,
(
int
)
merged
.
GetExtension
(
UnitTestProtoFile
.
OptionalInt32Extension
));
Assert
.
AreEqual
(
1
,
(
int
)
merged
.
GetExtension
(
UnitTestProtoFile
.
OptionalInt32Extension
));
}
}
*/
/* Removed multiple files option for the moment
/* Removed multiple files option for the moment
[Test]
[Test]
...
...
src/ProtocolBuffers.Test/TestProtos/UnitTestMessageSetProtoFile.cs
View file @
49fcd4f7
...
@@ -194,6 +194,7 @@ namespace Google.ProtocolBuffers.TestProtos {
...
@@ -194,6 +194,7 @@ namespace Google.ProtocolBuffers.TestProtos {
public
override
Builder
MergeFrom
(
TestMessageSet
other
)
{
public
override
Builder
MergeFrom
(
TestMessageSet
other
)
{
if
(
other
==
TestMessageSet
.
DefaultInstance
)
return
this
;
if
(
other
==
TestMessageSet
.
DefaultInstance
)
return
this
;
this
.
MergeExtensionFields
(
other
);
this
.
MergeUnknownFields
(
other
.
UnknownFields
);
this
.
MergeUnknownFields
(
other
.
UnknownFields
);
return
this
;
return
this
;
}
}
...
...
src/ProtocolBuffers.Test/TestProtos/UnitTestProtoFile.cs
View file @
49fcd4f7
...
@@ -4884,6 +4884,7 @@ namespace Google.ProtocolBuffers.TestProtos {
...
@@ -4884,6 +4884,7 @@ namespace Google.ProtocolBuffers.TestProtos {
public
override
Builder
MergeFrom
(
TestAllExtensions
other
)
{
public
override
Builder
MergeFrom
(
TestAllExtensions
other
)
{
if
(
other
==
TestAllExtensions
.
DefaultInstance
)
return
this
;
if
(
other
==
TestAllExtensions
.
DefaultInstance
)
return
this
;
this
.
MergeExtensionFields
(
other
);
this
.
MergeUnknownFields
(
other
.
UnknownFields
);
this
.
MergeUnknownFields
(
other
.
UnknownFields
);
return
this
;
return
this
;
}
}
...
@@ -7597,6 +7598,7 @@ namespace Google.ProtocolBuffers.TestProtos {
...
@@ -7597,6 +7598,7 @@ namespace Google.ProtocolBuffers.TestProtos {
public
override
Builder
MergeFrom
(
TestEmptyMessageWithExtensions
other
)
{
public
override
Builder
MergeFrom
(
TestEmptyMessageWithExtensions
other
)
{
if
(
other
==
TestEmptyMessageWithExtensions
.
DefaultInstance
)
return
this
;
if
(
other
==
TestEmptyMessageWithExtensions
.
DefaultInstance
)
return
this
;
this
.
MergeExtensionFields
(
other
);
this
.
MergeUnknownFields
(
other
.
UnknownFields
);
this
.
MergeUnknownFields
(
other
.
UnknownFields
);
return
this
;
return
this
;
}
}
...
@@ -10714,6 +10716,7 @@ namespace Google.ProtocolBuffers.TestProtos {
...
@@ -10714,6 +10716,7 @@ namespace Google.ProtocolBuffers.TestProtos {
if
(
other
.
HasMyFloat
)
{
if
(
other
.
HasMyFloat
)
{
MyFloat
=
other
.
MyFloat
;
MyFloat
=
other
.
MyFloat
;
}
}
this
.
MergeExtensionFields
(
other
);
this
.
MergeUnknownFields
(
other
.
UnknownFields
);
this
.
MergeUnknownFields
(
other
.
UnknownFields
);
return
this
;
return
this
;
}
}
...
...
src/ProtocolBuffers/DescriptorProtos/DescriptorProtoFile.cs
View file @
49fcd4f7
...
@@ -3936,6 +3936,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
...
@@ -3936,6 +3936,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
if
(
other
.
uninterpretedOption_
.
Count
!=
0
)
{
if
(
other
.
uninterpretedOption_
.
Count
!=
0
)
{
base
.
AddRange
(
other
.
uninterpretedOption_
,
result
.
uninterpretedOption_
);
base
.
AddRange
(
other
.
uninterpretedOption_
,
result
.
uninterpretedOption_
);
}
}
this
.
MergeExtensionFields
(
other
);
this
.
MergeUnknownFields
(
other
.
UnknownFields
);
this
.
MergeUnknownFields
(
other
.
UnknownFields
);
return
this
;
return
this
;
}
}
...
@@ -4273,6 +4274,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
...
@@ -4273,6 +4274,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
if
(
other
.
uninterpretedOption_
.
Count
!=
0
)
{
if
(
other
.
uninterpretedOption_
.
Count
!=
0
)
{
base
.
AddRange
(
other
.
uninterpretedOption_
,
result
.
uninterpretedOption_
);
base
.
AddRange
(
other
.
uninterpretedOption_
,
result
.
uninterpretedOption_
);
}
}
this
.
MergeExtensionFields
(
other
);
this
.
MergeUnknownFields
(
other
.
UnknownFields
);
this
.
MergeUnknownFields
(
other
.
UnknownFields
);
return
this
;
return
this
;
}
}
...
@@ -4565,6 +4567,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
...
@@ -4565,6 +4567,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
if
(
other
.
uninterpretedOption_
.
Count
!=
0
)
{
if
(
other
.
uninterpretedOption_
.
Count
!=
0
)
{
base
.
AddRange
(
other
.
uninterpretedOption_
,
result
.
uninterpretedOption_
);
base
.
AddRange
(
other
.
uninterpretedOption_
,
result
.
uninterpretedOption_
);
}
}
this
.
MergeExtensionFields
(
other
);
this
.
MergeUnknownFields
(
other
.
UnknownFields
);
this
.
MergeUnknownFields
(
other
.
UnknownFields
);
return
this
;
return
this
;
}
}
...
@@ -4839,6 +4842,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
...
@@ -4839,6 +4842,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
if
(
other
.
uninterpretedOption_
.
Count
!=
0
)
{
if
(
other
.
uninterpretedOption_
.
Count
!=
0
)
{
base
.
AddRange
(
other
.
uninterpretedOption_
,
result
.
uninterpretedOption_
);
base
.
AddRange
(
other
.
uninterpretedOption_
,
result
.
uninterpretedOption_
);
}
}
this
.
MergeExtensionFields
(
other
);
this
.
MergeUnknownFields
(
other
.
UnknownFields
);
this
.
MergeUnknownFields
(
other
.
UnknownFields
);
return
this
;
return
this
;
}
}
...
@@ -5063,6 +5067,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
...
@@ -5063,6 +5067,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
if
(
other
.
uninterpretedOption_
.
Count
!=
0
)
{
if
(
other
.
uninterpretedOption_
.
Count
!=
0
)
{
base
.
AddRange
(
other
.
uninterpretedOption_
,
result
.
uninterpretedOption_
);
base
.
AddRange
(
other
.
uninterpretedOption_
,
result
.
uninterpretedOption_
);
}
}
this
.
MergeExtensionFields
(
other
);
this
.
MergeUnknownFields
(
other
.
UnknownFields
);
this
.
MergeUnknownFields
(
other
.
UnknownFields
);
return
this
;
return
this
;
}
}
...
@@ -5287,6 +5292,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
...
@@ -5287,6 +5292,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
if
(
other
.
uninterpretedOption_
.
Count
!=
0
)
{
if
(
other
.
uninterpretedOption_
.
Count
!=
0
)
{
base
.
AddRange
(
other
.
uninterpretedOption_
,
result
.
uninterpretedOption_
);
base
.
AddRange
(
other
.
uninterpretedOption_
,
result
.
uninterpretedOption_
);
}
}
this
.
MergeExtensionFields
(
other
);
this
.
MergeUnknownFields
(
other
.
UnknownFields
);
this
.
MergeUnknownFields
(
other
.
UnknownFields
);
return
this
;
return
this
;
}
}
...
@@ -5511,6 +5517,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
...
@@ -5511,6 +5517,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
if
(
other
.
uninterpretedOption_
.
Count
!=
0
)
{
if
(
other
.
uninterpretedOption_
.
Count
!=
0
)
{
base
.
AddRange
(
other
.
uninterpretedOption_
,
result
.
uninterpretedOption_
);
base
.
AddRange
(
other
.
uninterpretedOption_
,
result
.
uninterpretedOption_
);
}
}
this
.
MergeExtensionFields
(
other
);
this
.
MergeUnknownFields
(
other
.
UnknownFields
);
this
.
MergeUnknownFields
(
other
.
UnknownFields
);
return
this
;
return
this
;
}
}
...
...
src/ProtocolBuffers/DynamicMessage.cs
View file @
49fcd4f7
...
@@ -284,15 +284,12 @@ namespace Google.ProtocolBuffers {
...
@@ -284,15 +284,12 @@ namespace Google.ProtocolBuffers {
throw
new
ArgumentException
(
"MergeFrom(IMessage) can only merge messages of the same type."
);
throw
new
ArgumentException
(
"MergeFrom(IMessage) can only merge messages of the same type."
);
}
}
fields
.
MergeFrom
(
other
);
fields
.
MergeFrom
(
other
);
MergeUnknownFields
(
other
.
UnknownFields
);
return
this
;
return
this
;
}
}
public
override
Builder
MergeFrom
(
DynamicMessage
other
)
{
public
override
Builder
MergeFrom
(
DynamicMessage
other
)
{
if
(
other
.
DescriptorForType
!=
type
)
{
return
MergeFrom
((
IMessage
)
other
);
throw
new
ArgumentException
(
"MergeFrom(IMessage) can only merge messages of the same type."
);
}
fields
.
MergeFrom
(
other
);
return
this
;
}
}
public
override
DynamicMessage
Build
()
{
public
override
DynamicMessage
Build
()
{
...
...
src/ProtocolBuffers/ExtendableBuilder.cs
View file @
49fcd4f7
...
@@ -166,5 +166,9 @@ namespace Google.ProtocolBuffers {
...
@@ -166,5 +166,9 @@ namespace Google.ProtocolBuffers {
return
base
.
AddRepeatedField
(
field
,
value
);
return
base
.
AddRepeatedField
(
field
,
value
);
}
}
}
}
protected
void
MergeExtensionFields
(
ExtendableMessage
<
TMessage
,
TBuilder
>
other
)
{
MessageBeingBuilt
.
Extensions
.
MergeFrom
(
other
.
Extensions
);
}
}
}
}
}
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