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
c2c42053
Commit
c2c42053
authored
Aug 10, 2015
by
Jon Skeet
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #699 from jskeet/validate_packed
Make FieldDescriptor.IsPacked work appropriately.
parents
59806299
547d8e82
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
4 deletions
+19
-4
FieldAccessTest.cs
...rp/src/Google.Protobuf.Test/Reflection/FieldAccessTest.cs
+1
-1
FieldDescriptor.cs
csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs
+5
-3
PartialClasses.cs
csharp/src/Google.Protobuf/Reflection/PartialClasses.cs
+13
-0
No files found.
csharp/src/Google.Protobuf.Test/Reflection/FieldAccessTest.cs
View file @
c2c42053
...
...
@@ -213,6 +213,6 @@ namespace Google.Protobuf.Reflection
var
descriptor
=
TestAllTypes
.
Descriptor
;
Assert
.
Throws
<
KeyNotFoundException
>(()
=>
descriptor
.
Fields
[
999999
].
ToString
());
Assert
.
Throws
<
KeyNotFoundException
>(()
=>
descriptor
.
Fields
[
"not found"
].
ToString
());
}
}
}
}
csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs
View file @
c2c42053
...
...
@@ -168,14 +168,16 @@ namespace Google.Protobuf.Reflection
get
{
return
fieldType
==
FieldType
.
Message
&&
messageType
.
Proto
.
Options
!=
null
&&
messageType
.
Proto
.
Options
.
MapEntry
;
}
}
// TODO(jonskeet): Check whether this is correct with proto3, where we default to packed...
/// <summary>
/// Returns <c>true</c> if this field is a packed, repeated field; <c>false</c> otherwise.
/// </summary>
public
bool
IsPacked
{
get
{
return
Proto
.
Options
!=
null
&&
Proto
.
Options
.
Packed
;
}
// Note the || rather than && here - we're effectively defaulting to packed, because that *is*
// the default in proto3, which is all we support. We may give the wrong result for the protos
// within descriptor.proto, but that's okay, as they're never exposed and we don't use IsPacked
// within the runtime.
get
{
return
Proto
.
Options
==
null
||
Proto
.
Options
.
Packed
;
}
}
/// <summary>
...
...
csharp/src/Google.Protobuf/Reflection/PartialClasses.cs
View file @
c2c42053
...
...
@@ -44,4 +44,16 @@ namespace Google.Protobuf.Reflection
OneofIndex
=
-
1
;
}
}
internal
partial
class
FieldOptions
{
// We can't tell the difference between "explicitly set to false" and "not set"
// in proto3, but we need to tell the difference for FieldDescriptor.IsPacked.
// This won't work if we ever need to support proto2, but at that point we'll be
// able to remove this hack and use field presence instead.
partial
void
OnConstruction
()
{
Packed
=
true
;
}
}
}
\ No newline at end of file
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