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 {
...
@@ -73,7 +73,8 @@ namespace Google.ProtocolBuffers.ProtoGen {
if
(!
Descriptor
.
IsCLSCompliant
&&
Descriptor
.
File
.
CSharpOptions
.
ClsCompliance
)
{
if
(!
Descriptor
.
IsCLSCompliant
&&
Descriptor
.
File
.
CSharpOptions
.
ClsCompliance
)
{
writer
.
WriteLine
(
"[global::System.CLSCompliant(false)]"
);
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
)
{
}
else
if
(
Descriptor
.
IsRepeated
)
{
if
(!
Descriptor
.
IsCLSCompliant
&&
Descriptor
.
File
.
CSharpOptions
.
ClsCompliance
)
{
if
(!
Descriptor
.
IsCLSCompliant
&&
Descriptor
.
File
.
CSharpOptions
.
ClsCompliance
)
{
writer
.
WriteLine
(
"[global::System.CLSCompliant(false)]"
);
writer
.
WriteLine
(
"[global::System.CLSCompliant(false)]"
);
...
@@ -91,10 +92,11 @@ namespace Google.ProtocolBuffers.ProtoGen {
...
@@ -91,10 +92,11 @@ namespace Google.ProtocolBuffers.ProtoGen {
if
(
UseLiteRuntime
)
{
if
(
UseLiteRuntime
)
{
writer
.
WriteLine
(
"{0}.{1} = "
,
scope
,
name
);
writer
.
WriteLine
(
"{0}.{1} = "
,
scope
,
name
);
writer
.
Indent
();
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
.
Indent
();
writer
.
WriteLine
(
"{0}.DefaultInstance,"
,
extends
);
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
.
Message
)
?
type
+
".DefaultInstance"
:
"null"
);
writer
.
WriteLine
(
"{0},"
,
(
Descriptor
.
MappedType
==
MappedType
.
Enum
)
?
"new EnumLiteMap<"
+
type
+
">()"
:
"null"
);
writer
.
WriteLine
(
"{0},"
,
(
Descriptor
.
MappedType
==
MappedType
.
Enum
)
?
"new EnumLiteMap<"
+
type
+
">()"
:
"null"
);
writer
.
WriteLine
(
"{0},"
,
Descriptor
.
Index
);
writer
.
WriteLine
(
"{0},"
,
Descriptor
.
Index
);
...
...
src/ProtocolBuffers/EnumLite.cs
View file @
487da48a
...
@@ -66,7 +66,7 @@ namespace Google.ProtocolBuffers {
...
@@ -66,7 +66,7 @@ namespace Google.ProtocolBuffers {
}
}
public
class
EnumLiteMap
<
TEnum
>
:
IEnumLiteMap
<
IEnumLite
>
public
class
EnumLiteMap
<
TEnum
>
:
IEnumLiteMap
<
IEnumLite
>
where
TEnum
:
struct
,
IComparable
,
IFormattable
,
IConvertible
{
where
TEnum
:
struct
,
IComparable
,
IFormattable
{
struct
EnumValue
:
IEnumLite
,
IComparable
<
IEnumLite
>
{
struct
EnumValue
:
IEnumLite
,
IComparable
<
IEnumLite
>
{
int
_value
;
int
_value
;
...
@@ -86,7 +86,7 @@ namespace Google.ProtocolBuffers {
...
@@ -86,7 +86,7 @@ namespace Google.ProtocolBuffers {
public
EnumLiteMap
()
{
public
EnumLiteMap
()
{
items
=
new
SortedList
<
int
,
IEnumLite
>();
items
=
new
SortedList
<
int
,
IEnumLite
>();
foreach
(
TEnum
evalue
in
Enum
.
GetValues
(
typeof
(
TEnum
)))
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
)
{
IEnumLite
IEnumLiteMap
.
FindValueByNumber
(
int
number
)
{
...
...
src/ProtocolBuffers/GeneratedExtensionLite.cs
View file @
487da48a
...
@@ -126,7 +126,32 @@ namespace Google.ProtocolBuffers {
...
@@ -126,7 +126,32 @@ namespace Google.ProtocolBuffers {
return
FieldNumber
.
CompareTo
(
other
.
FieldNumber
);
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
public
class
GeneratedExtensionLite
<
TContainingType
,
TExtensionType
>
:
IGeneratedExtensionLite
where
TContainingType
:
IMessageLite
{
where
TContainingType
:
IMessageLite
{
...
@@ -166,8 +191,8 @@ namespace Google.ProtocolBuffers {
...
@@ -166,8 +191,8 @@ namespace Google.ProtocolBuffers {
false
/* isRepeated */
,
false
/* isPacked */
))
{
false
/* isRepeated */
,
false
/* isPacked */
))
{
}
}
/** For use by generated code only. */
/**
Repeating fields:
For use by generated code only. */
p
ublic
GeneratedExtensionLite
(
p
rotected
GeneratedExtensionLite
(
TContainingType
containingTypeDefaultInstance
,
TContainingType
containingTypeDefaultInstance
,
TExtensionType
defaultValue
,
TExtensionType
defaultValue
,
IMessageLite
messageDefaultInstance
,
IMessageLite
messageDefaultInstance
,
...
@@ -231,48 +256,21 @@ namespace Google.ProtocolBuffers {
...
@@ -231,48 +256,21 @@ namespace Google.ProtocolBuffers {
/// for enums use EnumValueDescriptors but the native accessors use
/// for enums use EnumValueDescriptors but the native accessors use
/// the generated enum type.
/// the generated enum type.
/// </summary>
/// </summary>
public
object
ToReflectionType
(
object
value
)
{
public
virtual
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
{
return
SingularToReflectionType
(
value
);
return
SingularToReflectionType
(
value
);
}
}
}
/// <summary>
/// <summary>
/// Like ToReflectionType(object) but for a single element.
/// Like ToReflectionType(object) but for a single element.
/// </summary>
/// </summary>
internal
O
bject
SingularToReflectionType
(
object
value
)
{
public
o
bject
SingularToReflectionType
(
object
value
)
{
return
descriptor
.
MappedType
==
MappedType
.
Enum
return
descriptor
.
MappedType
==
MappedType
.
Enum
?
descriptor
.
EnumType
.
FindValueByNumber
((
int
)
value
)
?
descriptor
.
EnumType
.
FindValueByNumber
((
int
)
value
)
:
value
;
:
value
;
}
}
public
object
FromReflectionType
(
object
value
)
{
public
virtual
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
{
return
SingularFromReflectionType
(
value
);
return
SingularFromReflectionType
(
value
);
}
}
}
public
object
SingularFromReflectionType
(
object
value
)
{
public
object
SingularFromReflectionType
(
object
value
)
{
...
...
src/ProtocolBuffersLite.Test/LiteTest.cs
View file @
487da48a
...
@@ -32,6 +32,8 @@
...
@@ -32,6 +32,8 @@
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endregion
#endregion
using
System
;
using
System.Collections.Generic
;
using
System.IO
;
using
System.IO
;
using
Google.ProtocolBuffers.Descriptors
;
using
Google.ProtocolBuffers.Descriptors
;
using
Google.ProtocolBuffers.TestProtos
;
using
Google.ProtocolBuffers.TestProtos
;
...
@@ -81,8 +83,7 @@ namespace Google.ProtocolBuffers {
...
@@ -81,8 +83,7 @@ namespace Google.ProtocolBuffers {
TestAllExtensionsLite
message
=
TestAllExtensionsLite
message
=
TestAllExtensionsLite
.
CreateBuilder
()
TestAllExtensionsLite
.
CreateBuilder
()
.
SetExtension
(
UnitTestLiteProtoFile
.
OptionalInt32ExtensionLite
,
123
)
.
SetExtension
(
UnitTestLiteProtoFile
.
OptionalInt32ExtensionLite
,
123
)
#warning broken
.
AddExtension
(
UnitTestLiteProtoFile
.
RepeatedStringExtensionLite
,
"hello"
)
// .AddExtension(UnitTestLiteProtoFile.RepeatedStringExtensionLite, "hello")
.
SetExtension
(
UnitTestLiteProtoFile
.
OptionalNestedEnumExtensionLite
,
.
SetExtension
(
UnitTestLiteProtoFile
.
OptionalNestedEnumExtensionLite
,
TestAllTypesLite
.
Types
.
NestedEnum
.
BAZ
)
TestAllTypesLite
.
Types
.
NestedEnum
.
BAZ
)
.
SetExtension
(
UnitTestLiteProtoFile
.
OptionalNestedMessageExtensionLite
,
.
SetExtension
(
UnitTestLiteProtoFile
.
OptionalNestedMessageExtensionLite
,
...
@@ -96,13 +97,12 @@ namespace Google.ProtocolBuffers {
...
@@ -96,13 +97,12 @@ namespace Google.ProtocolBuffers {
Assert
.
AreEqual
(
123
,
(
int
)
message2
.
GetExtension
(
Assert
.
AreEqual
(
123
,
(
int
)
message2
.
GetExtension
(
UnitTestLiteProtoFile
.
OptionalInt32ExtensionLite
));
UnitTestLiteProtoFile
.
OptionalInt32ExtensionLite
));
#warning broken type infrence
Assert
.
AreEqual
(
1
,
message2
.
GetExtensionCount
(
//Assert.AreEqual(1, message2.GetExtensionCount(
UnitTestLiteProtoFile
.
RepeatedStringExtensionLite
));
// UnitTestLiteProtoFile.RepeatedStringExtensionLite));
Assert
.
AreEqual
(
1
,
message2
.
GetExtension
(
//Assert.AreEqual(1, message2.GetExtension(
UnitTestLiteProtoFile
.
RepeatedStringExtensionLite
).
Count
);
// UnitTestLiteProtoFile.RepeatedStringExtensionLite, 0));
Assert
.
AreEqual
(
"hello"
,
message2
.
GetExtension
(
//Assert.AreEqual("hello", message2.GetExtension(
UnitTestLiteProtoFile
.
RepeatedStringExtensionLite
,
0
));
// UnitTestLiteProtoFile.RepeatedStringExtensionLite, 0));
Assert
.
AreEqual
(
TestAllTypesLite
.
Types
.
NestedEnum
.
BAZ
,
message2
.
GetExtension
(
Assert
.
AreEqual
(
TestAllTypesLite
.
Types
.
NestedEnum
.
BAZ
,
message2
.
GetExtension
(
UnitTestLiteProtoFile
.
OptionalNestedEnumExtensionLite
));
UnitTestLiteProtoFile
.
OptionalNestedEnumExtensionLite
));
Assert
.
AreEqual
(
7
,
message2
.
GetExtension
(
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