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
487da48a
Commit
487da48a
authored
Nov 08, 2010
by
csharptest
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix for repeated extensions.
parent
80824a51
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
47 additions
and
47 deletions
+47
-47
ExtensionGenerator.cs
src/ProtoGen/ExtensionGenerator.cs
+5
-3
EnumLite.cs
src/ProtocolBuffers/EnumLite.cs
+2
-2
GeneratedExtensionLite.cs
src/ProtocolBuffers/GeneratedExtensionLite.cs
+31
-33
LiteTest.cs
src/ProtocolBuffersLite.Test/LiteTest.cs
+9
-9
UnitTestLiteProtoFile.cs
...tocolBuffersLite.Test/TestProtos/UnitTestLiteProtoFile.cs
+0
-0
No files found.
src/ProtoGen/ExtensionGenerator.cs
View file @
487da48a
...
...
@@ -73,7 +73,8 @@ namespace Google.ProtocolBuffers.ProtoGen {
if
(!
Descriptor
.
IsCLSCompliant
&&
Descriptor
.
File
.
CSharpOptions
.
ClsCompliance
)
{
writer
.
WriteLine
(
"[global::System.CLSCompliant(false)]"
);
}
writer
.
WriteLine
(
"{0} static pb::GeneratedExtensionLite<{1}, {2}> {3};"
,
ClassAccessLevel
,
extends
,
type
,
name
);
writer
.
WriteLine
(
"{0} static pb::{4}<{1}, {2}> {3};"
,
ClassAccessLevel
,
extends
,
type
,
name
,
Descriptor
.
IsRepeated
?
"GeneratedRepeatExtensionLite"
:
"GeneratedExtensionLite"
);
}
else
if
(
Descriptor
.
IsRepeated
)
{
if
(!
Descriptor
.
IsCLSCompliant
&&
Descriptor
.
File
.
CSharpOptions
.
ClsCompliance
)
{
writer
.
WriteLine
(
"[global::System.CLSCompliant(false)]"
);
...
...
@@ -91,10 +92,11 @@ namespace Google.ProtocolBuffers.ProtoGen {
if
(
UseLiteRuntime
)
{
writer
.
WriteLine
(
"{0}.{1} = "
,
scope
,
name
);
writer
.
Indent
();
writer
.
WriteLine
(
"new pb::
GeneratedExtensionLite<{0}, {1}>(
"
,
extends
,
type
);
writer
.
WriteLine
(
"new pb::
{0}<{1}, {2}>("
,
Descriptor
.
IsRepeated
?
"GeneratedRepeatExtensionLite"
:
"GeneratedExtensionLite
"
,
extends
,
type
);
writer
.
Indent
();
writer
.
WriteLine
(
"{0}.DefaultInstance,"
,
extends
);
writer
.
WriteLine
(
"{0},"
,
Descriptor
.
HasDefaultValue
?
DefaultValue
:
IsNullableType
?
"null"
:
"default("
+
type
+
")"
);
if
(!
Descriptor
.
IsRepeated
)
writer
.
WriteLine
(
"{0},"
,
Descriptor
.
HasDefaultValue
?
DefaultValue
:
IsNullableType
?
"null"
:
"default("
+
type
+
")"
);
writer
.
WriteLine
(
"{0},"
,
(
Descriptor
.
MappedType
==
MappedType
.
Message
)
?
type
+
".DefaultInstance"
:
"null"
);
writer
.
WriteLine
(
"{0},"
,
(
Descriptor
.
MappedType
==
MappedType
.
Enum
)
?
"new EnumLiteMap<"
+
type
+
">()"
:
"null"
);
writer
.
WriteLine
(
"{0},"
,
Descriptor
.
Index
);
...
...
src/ProtocolBuffers/EnumLite.cs
View file @
487da48a
...
...
@@ -66,7 +66,7 @@ namespace Google.ProtocolBuffers {
}
public
class
EnumLiteMap
<
TEnum
>
:
IEnumLiteMap
<
IEnumLite
>
where
TEnum
:
struct
,
IComparable
,
IFormattable
,
IConvertible
{
where
TEnum
:
struct
,
IComparable
,
IFormattable
{
struct
EnumValue
:
IEnumLite
,
IComparable
<
IEnumLite
>
{
int
_value
;
...
...
@@ -86,7 +86,7 @@ namespace Google.ProtocolBuffers {
public
EnumLiteMap
()
{
items
=
new
SortedList
<
int
,
IEnumLite
>();
foreach
(
TEnum
evalue
in
Enum
.
GetValues
(
typeof
(
TEnum
)))
items
.
Add
(
evalue
.
ToInt32
(
CultureInfo
.
InvariantCulture
),
new
EnumValue
(
evalue
.
ToInt32
(
CultureInfo
.
InvariantCultur
e
)));
items
.
Add
(
Convert
.
ToInt32
(
evalue
),
new
EnumValue
(
Convert
.
ToInt32
(
evalu
e
)));
}
IEnumLite
IEnumLiteMap
.
FindValueByNumber
(
int
number
)
{
...
...
src/ProtocolBuffers/GeneratedExtensionLite.cs
View file @
487da48a
...
...
@@ -126,7 +126,32 @@ namespace Google.ProtocolBuffers {
return
FieldNumber
.
CompareTo
(
other
.
FieldNumber
);
}
}
public
class
GeneratedRepeatExtensionLite
<
TContainingType
,
TExtensionType
>
:
GeneratedExtensionLite
<
TContainingType
,
IList
<
TExtensionType
>>
where
TContainingType
:
IMessageLite
{
public
GeneratedRepeatExtensionLite
(
TContainingType
containingTypeDefaultInstance
,
IMessageLite
messageDefaultInstance
,
IEnumLiteMap
enumTypeMap
,
int
number
,
FieldType
type
,
bool
isPacked
)
:
base
(
containingTypeDefaultInstance
,
new
List
<
TExtensionType
>(),
messageDefaultInstance
,
enumTypeMap
,
number
,
type
,
isPacked
)
{
}
public
override
object
ToReflectionType
(
object
value
)
{
IList
<
TExtensionType
>
result
=
new
List
<
TExtensionType
>();
foreach
(
object
element
in
(
IEnumerable
)
value
)
{
result
.
Add
((
TExtensionType
)
SingularToReflectionType
(
element
));
}
return
result
;
}
public
override
object
FromReflectionType
(
object
value
)
{
// Must convert the whole list.
List
<
TExtensionType
>
result
=
new
List
<
TExtensionType
>();
foreach
(
object
element
in
(
IEnumerable
)
value
)
{
result
.
Add
((
TExtensionType
)
SingularFromReflectionType
(
element
));
}
return
result
;
}
}
public
class
GeneratedExtensionLite
<
TContainingType
,
TExtensionType
>
:
IGeneratedExtensionLite
where
TContainingType
:
IMessageLite
{
...
...
@@ -166,8 +191,8 @@ namespace Google.ProtocolBuffers {
false
/* isRepeated */
,
false
/* isPacked */
))
{
}
/** For use by generated code only. */
p
ublic
GeneratedExtensionLite
(
/**
Repeating fields:
For use by generated code only. */
p
rotected
GeneratedExtensionLite
(
TContainingType
containingTypeDefaultInstance
,
TExtensionType
defaultValue
,
IMessageLite
messageDefaultInstance
,
...
...
@@ -231,48 +256,21 @@ namespace Google.ProtocolBuffers {
/// for enums use EnumValueDescriptors but the native accessors use
/// the generated enum type.
/// </summary>
public
object
ToReflectionType
(
object
value
)
{
if
(
descriptor
.
IsRepeated
)
{
if
(
descriptor
.
MappedType
==
MappedType
.
Enum
)
{
// Must convert the whole list.
IList
<
object
>
result
=
new
List
<
object
>();
foreach
(
object
element
in
(
IEnumerable
)
value
)
{
result
.
Add
(
SingularToReflectionType
(
element
));
}
return
result
;
}
else
{
return
value
;
}
}
else
{
public
virtual
object
ToReflectionType
(
object
value
)
{
return
SingularToReflectionType
(
value
);
}
}
/// <summary>
/// Like ToReflectionType(object) but for a single element.
/// </summary>
internal
O
bject
SingularToReflectionType
(
object
value
)
{
public
o
bject
SingularToReflectionType
(
object
value
)
{
return
descriptor
.
MappedType
==
MappedType
.
Enum
?
descriptor
.
EnumType
.
FindValueByNumber
((
int
)
value
)
:
value
;
}
public
object
FromReflectionType
(
object
value
)
{
if
(
descriptor
.
IsRepeated
)
{
if
(
Descriptor
.
MappedType
==
MappedType
.
Message
||
Descriptor
.
MappedType
==
MappedType
.
Enum
)
{
// Must convert the whole list.
List
<
TExtensionType
>
result
=
new
List
<
TExtensionType
>();
foreach
(
object
element
in
(
IEnumerable
)
value
)
{
result
.
Add
((
TExtensionType
)
SingularFromReflectionType
(
element
));
}
return
result
;
}
else
{
return
value
;
}
}
else
{
public
virtual
object
FromReflectionType
(
object
value
)
{
return
SingularFromReflectionType
(
value
);
}
}
public
object
SingularFromReflectionType
(
object
value
)
{
...
...
src/ProtocolBuffersLite.Test/LiteTest.cs
View file @
487da48a
...
...
@@ -32,6 +32,8 @@
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endregion
using
System
;
using
System.Collections.Generic
;
using
System.IO
;
using
Google.ProtocolBuffers.Descriptors
;
using
Google.ProtocolBuffers.TestProtos
;
...
...
@@ -81,8 +83,7 @@ namespace Google.ProtocolBuffers {
TestAllExtensionsLite
message
=
TestAllExtensionsLite
.
CreateBuilder
()
.
SetExtension
(
UnitTestLiteProtoFile
.
OptionalInt32ExtensionLite
,
123
)
#warning broken
// .AddExtension(UnitTestLiteProtoFile.RepeatedStringExtensionLite, "hello")
.
AddExtension
(
UnitTestLiteProtoFile
.
RepeatedStringExtensionLite
,
"hello"
)
.
SetExtension
(
UnitTestLiteProtoFile
.
OptionalNestedEnumExtensionLite
,
TestAllTypesLite
.
Types
.
NestedEnum
.
BAZ
)
.
SetExtension
(
UnitTestLiteProtoFile
.
OptionalNestedMessageExtensionLite
,
...
...
@@ -96,13 +97,12 @@ namespace Google.ProtocolBuffers {
Assert
.
AreEqual
(
123
,
(
int
)
message2
.
GetExtension
(
UnitTestLiteProtoFile
.
OptionalInt32ExtensionLite
));
#warning broken type infrence
//Assert.AreEqual(1, message2.GetExtensionCount(
// UnitTestLiteProtoFile.RepeatedStringExtensionLite));
//Assert.AreEqual(1, message2.GetExtension(
// UnitTestLiteProtoFile.RepeatedStringExtensionLite, 0));
//Assert.AreEqual("hello", message2.GetExtension(
// UnitTestLiteProtoFile.RepeatedStringExtensionLite, 0));
Assert
.
AreEqual
(
1
,
message2
.
GetExtensionCount
(
UnitTestLiteProtoFile
.
RepeatedStringExtensionLite
));
Assert
.
AreEqual
(
1
,
message2
.
GetExtension
(
UnitTestLiteProtoFile
.
RepeatedStringExtensionLite
).
Count
);
Assert
.
AreEqual
(
"hello"
,
message2
.
GetExtension
(
UnitTestLiteProtoFile
.
RepeatedStringExtensionLite
,
0
));
Assert
.
AreEqual
(
TestAllTypesLite
.
Types
.
NestedEnum
.
BAZ
,
message2
.
GetExtension
(
UnitTestLiteProtoFile
.
OptionalNestedEnumExtensionLite
));
Assert
.
AreEqual
(
7
,
message2
.
GetExtension
(
...
...
src/ProtocolBuffersLite.Test/TestProtos/UnitTestLiteProtoFile.cs
View file @
487da48a
This diff is collapsed.
Click to expand it.
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