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
d3f2d098
Commit
d3f2d098
authored
Feb 08, 2010
by
Jon Skeet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow creation of namespace directories
parent
55a212d3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
92 additions
and
10 deletions
+92
-10
csharp_options.proto
protos/google/protobuf/csharp_options.proto
+24
-0
Generator.cs
src/ProtoGen/Generator.cs
+18
-1
CSharpOptions.cs
src/ProtocolBuffers/DescriptorProtos/CSharpOptions.cs
+50
-9
No files found.
protos/google/protobuf/csharp_options.proto
View file @
d3f2d098
...
@@ -5,12 +5,36 @@ import "google/protobuf/descriptor.proto";
...
@@ -5,12 +5,36 @@ import "google/protobuf/descriptor.proto";
package
google
.
protobuf
;
package
google
.
protobuf
;
message
CSharpFileOptions
{
message
CSharpFileOptions
{
// Namespace for generated classes; defaults to the package.
optional
string
namespace
=
1
;
optional
string
namespace
=
1
;
// Name of the "umbrella" class used for metadata about all
// the messages within this file. Default is based on the name
// of the file.
optional
string
umbrella_classname
=
2
;
optional
string
umbrella_classname
=
2
;
// Whether classes should be public (true) or internal (false)
optional
bool
public_classes
=
3
[
default
=
true
];
optional
bool
public_classes
=
3
[
default
=
true
];
// Whether to generate a single file for everything within the
// .proto file (false), or one file per message (true).
// This option is not currently honored; please log a feature
// request if you really want it.
optional
bool
multiple_files
=
4
;
optional
bool
multiple_files
=
4
;
// Whether to nest messages within a single umbrella class (true)
// or create the umbrella class as a peer, with messages as
// top-level classes in the namespace (false)
optional
bool
nest_classes
=
5
;
optional
bool
nest_classes
=
5
;
// Generate appropriate support for Code Contracts
// (Ongoing; support should improve over time)
optional
bool
code_contracts
=
6
;
optional
bool
code_contracts
=
6
;
// Create subdirectories for namespaces, e.g. namespace "Foo.Bar"
// would generate files within [output directory]/Foo/Bar
optional
bool
expand_namespace_directories
=
7
;
}
}
extend
FileOptions
{
extend
FileOptions
{
...
...
src/ProtoGen/Generator.cs
View file @
d3f2d098
...
@@ -82,12 +82,29 @@ namespace Google.ProtocolBuffers.ProtoGen {
...
@@ -82,12 +82,29 @@ namespace Google.ProtocolBuffers.ProtoGen {
/// </summary>
/// </summary>
private
void
Generate
(
FileDescriptor
descriptor
)
{
private
void
Generate
(
FileDescriptor
descriptor
)
{
UmbrellaClassGenerator
ucg
=
new
UmbrellaClassGenerator
(
descriptor
);
UmbrellaClassGenerator
ucg
=
new
UmbrellaClassGenerator
(
descriptor
);
using
(
TextWriter
textWriter
=
File
.
CreateText
(
Path
.
Combine
(
options
.
OutputDirectory
,
descriptor
.
CSharpOptions
.
UmbrellaClassname
+
".cs"
)))
{
using
(
TextWriter
textWriter
=
File
.
CreateText
(
GetOutputFile
(
descriptor
)))
{
TextGenerator
writer
=
new
TextGenerator
(
textWriter
);
TextGenerator
writer
=
new
TextGenerator
(
textWriter
);
ucg
.
Generate
(
writer
);
ucg
.
Generate
(
writer
);
}
}
}
}
private
string
GetOutputFile
(
FileDescriptor
descriptor
)
{
CSharpFileOptions
fileOptions
=
descriptor
.
CSharpOptions
;
string
filename
=
descriptor
.
CSharpOptions
.
UmbrellaClassname
+
".cs"
;
string
outputDirectory
=
options
.
OutputDirectory
;
if
(
fileOptions
.
ExpandNamespaceDirectories
)
{
string
package
=
fileOptions
.
Namespace
;
if
(!
string
.
IsNullOrEmpty
(
package
))
{
string
[]
bits
=
package
.
Split
(
'.'
);
foreach
(
string
bit
in
bits
)
{
outputDirectory
=
Path
.
Combine
(
outputDirectory
,
bit
);
}
Directory
.
CreateDirectory
(
outputDirectory
);
}
}
return
Path
.
Combine
(
outputDirectory
,
filename
);
}
/// <summary>
/// <summary>
/// Resolves any dependencies and converts FileDescriptorProtos into FileDescriptors.
/// Resolves any dependencies and converts FileDescriptorProtos into FileDescriptors.
/// The list returned is in the same order as the protos are listed in the descriptor set.
/// The list returned is in the same order as the protos are listed in the descriptor set.
...
...
src/ProtocolBuffers/DescriptorProtos/CSharpOptions.cs
View file @
d3f2d098
...
@@ -37,22 +37,22 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
...
@@ -37,22 +37,22 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
byte
[]
descriptorData
=
global
::
System
.
Convert
.
FromBase64String
(
byte
[]
descriptorData
=
global
::
System
.
Convert
.
FromBase64String
(
"CiRnb29nbGUvcHJvdG9idWYvY3NoYXJwX29wdGlvbnMucHJvdG8SD2dvb2ds"
+
"CiRnb29nbGUvcHJvdG9idWYvY3NoYXJwX29wdGlvbnMucHJvdG8SD2dvb2ds"
+
"ZS5wcm90b2J1ZhogZ29vZ2xlL3Byb3RvYnVmL2Rlc2NyaXB0b3IucHJvdG8i"
+
"ZS5wcm90b2J1ZhogZ29vZ2xlL3Byb3RvYnVmL2Rlc2NyaXB0b3IucHJvdG8i"
+
"
pg
EKEUNTaGFycEZpbGVPcHRpb25zEhEKCW5hbWVzcGFjZRgBIAEoCRIaChJ1"
+
"
zA
EKEUNTaGFycEZpbGVPcHRpb25zEhEKCW5hbWVzcGFjZRgBIAEoCRIaChJ1"
+
"bWJyZWxsYV9jbGFzc25hbWUYAiABKAkSHAoOcHVibGljX2NsYXNzZXMYAyAB"
+
"bWJyZWxsYV9jbGFzc25hbWUYAiABKAkSHAoOcHVibGljX2NsYXNzZXMYAyAB"
+
"KAg6BHRydWUSFgoObXVsdGlwbGVfZmlsZXMYBCABKAgSFAoMbmVzdF9jbGFz"
+
"KAg6BHRydWUSFgoObXVsdGlwbGVfZmlsZXMYBCABKAgSFAoMbmVzdF9jbGFz"
+
"c2VzGAUgASgIEhYKDmNvZGVfY29udHJhY3RzGAYgASgI
IisKEkNTaGFycEZp
"
+
"c2VzGAUgASgIEhYKDmNvZGVfY29udHJhY3RzGAYgASgI
EiQKHGV4cGFuZF9u
"
+
"
ZWxkT3B0aW9ucxIVCg1wcm9wZXJ0eV9uYW1lGAEgASgJOl4KE2NzaGFycF9m
"
+
"
YW1lc3BhY2VfZGlyZWN0b3JpZXMYByABKAgiKwoSQ1NoYXJwRmllbGRPcHRp
"
+
"
aWxlX29wdGlvbnMSHC5nb29nbGUucHJvdG9idWYuRmlsZU9wdGlvbnMY6Acg
"
+
"
b25zEhUKDXByb3BlcnR5X25hbWUYASABKAk6XgoTY3NoYXJwX2ZpbGVfb3B0
"
+
"
ASgLMiIuZ29vZ2xlLnByb3RvYnVmLkNTaGFycEZpbGVPcHRpb25zOmEKFGNz
"
+
"
aW9ucxIcLmdvb2dsZS5wcm90b2J1Zi5GaWxlT3B0aW9ucxjoByABKAsyIi5n
"
+
"
aGFycF9maWVsZF9vcHRpb25zEh0uZ29vZ2xlLnByb3RvYnVmLkZpZWxkT3B0
"
+
"
b29nbGUucHJvdG9idWYuQ1NoYXJwRmlsZU9wdGlvbnM6YQoUY3NoYXJwX2Zp
"
+
"
aW9ucxjoByABKAsyIy5nb29nbGUucHJvdG9idWYuQ1NoYXJwRmllbGRPcHRp
"
+
"
ZWxkX29wdGlvbnMSHS5nb29nbGUucHJvdG9idWYuRmllbGRPcHRpb25zGOgH
"
+
"
b25z
"
);
"
IAEoCzIjLmdvb2dsZS5wcm90b2J1Zi5DU2hhcnBGaWVsZE9wdGlvbnM=
"
);
pbd
::
FileDescriptor
.
InternalDescriptorAssigner
assigner
=
delegate
(
pbd
::
FileDescriptor
root
)
{
pbd
::
FileDescriptor
.
InternalDescriptorAssigner
assigner
=
delegate
(
pbd
::
FileDescriptor
root
)
{
descriptor
=
root
;
descriptor
=
root
;
internal__static_google_protobuf_CSharpFileOptions__Descriptor
=
Descriptor
.
MessageTypes
[
0
];
internal__static_google_protobuf_CSharpFileOptions__Descriptor
=
Descriptor
.
MessageTypes
[
0
];
internal__static_google_protobuf_CSharpFileOptions__FieldAccessorTable
=
internal__static_google_protobuf_CSharpFileOptions__FieldAccessorTable
=
new
pb
::
FieldAccess
.
FieldAccessorTable
<
global
::
Google
.
ProtocolBuffers
.
DescriptorProtos
.
CSharpFileOptions
,
global
::
Google
.
ProtocolBuffers
.
DescriptorProtos
.
CSharpFileOptions
.
Builder
>(
internal__static_google_protobuf_CSharpFileOptions__Descriptor
,
new
pb
::
FieldAccess
.
FieldAccessorTable
<
global
::
Google
.
ProtocolBuffers
.
DescriptorProtos
.
CSharpFileOptions
,
global
::
Google
.
ProtocolBuffers
.
DescriptorProtos
.
CSharpFileOptions
.
Builder
>(
internal__static_google_protobuf_CSharpFileOptions__Descriptor
,
new
string
[]
{
"Namespace"
,
"UmbrellaClassname"
,
"PublicClasses"
,
"MultipleFiles"
,
"NestClasses"
,
"CodeContracts"
,
});
new
string
[]
{
"Namespace"
,
"UmbrellaClassname"
,
"PublicClasses"
,
"MultipleFiles"
,
"NestClasses"
,
"CodeContracts"
,
"ExpandNamespaceDirectories"
,
});
internal__static_google_protobuf_CSharpFieldOptions__Descriptor
=
Descriptor
.
MessageTypes
[
1
];
internal__static_google_protobuf_CSharpFieldOptions__Descriptor
=
Descriptor
.
MessageTypes
[
1
];
internal__static_google_protobuf_CSharpFieldOptions__FieldAccessorTable
=
internal__static_google_protobuf_CSharpFieldOptions__FieldAccessorTable
=
new
pb
::
FieldAccess
.
FieldAccessorTable
<
global
::
Google
.
ProtocolBuffers
.
DescriptorProtos
.
CSharpFieldOptions
,
global
::
Google
.
ProtocolBuffers
.
DescriptorProtos
.
CSharpFieldOptions
.
Builder
>(
internal__static_google_protobuf_CSharpFieldOptions__Descriptor
,
new
pb
::
FieldAccess
.
FieldAccessorTable
<
global
::
Google
.
ProtocolBuffers
.
DescriptorProtos
.
CSharpFieldOptions
,
global
::
Google
.
ProtocolBuffers
.
DescriptorProtos
.
CSharpFieldOptions
.
Builder
>(
internal__static_google_protobuf_CSharpFieldOptions__Descriptor
,
...
@@ -152,6 +152,16 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
...
@@ -152,6 +152,16 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
get
{
return
codeContracts_
;
}
get
{
return
codeContracts_
;
}
}
}
public
const
int
ExpandNamespaceDirectoriesFieldNumber
=
7
;
private
bool
hasExpandNamespaceDirectories
;
private
bool
expandNamespaceDirectories_
=
false
;
public
bool
HasExpandNamespaceDirectories
{
get
{
return
hasExpandNamespaceDirectories
;
}
}
public
bool
ExpandNamespaceDirectories
{
get
{
return
expandNamespaceDirectories_
;
}
}
public
override
bool
IsInitialized
{
public
override
bool
IsInitialized
{
get
{
get
{
return
true
;
return
true
;
...
@@ -177,6 +187,9 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
...
@@ -177,6 +187,9 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
if
(
HasCodeContracts
)
{
if
(
HasCodeContracts
)
{
output
.
WriteBool
(
6
,
CodeContracts
);
output
.
WriteBool
(
6
,
CodeContracts
);
}
}
if
(
HasExpandNamespaceDirectories
)
{
output
.
WriteBool
(
7
,
ExpandNamespaceDirectories
);
}
UnknownFields
.
WriteTo
(
output
);
UnknownFields
.
WriteTo
(
output
);
}
}
...
@@ -205,6 +218,9 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
...
@@ -205,6 +218,9 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
if
(
HasCodeContracts
)
{
if
(
HasCodeContracts
)
{
size
+=
pb
::
CodedOutputStream
.
ComputeBoolSize
(
6
,
CodeContracts
);
size
+=
pb
::
CodedOutputStream
.
ComputeBoolSize
(
6
,
CodeContracts
);
}
}
if
(
HasExpandNamespaceDirectories
)
{
size
+=
pb
::
CodedOutputStream
.
ComputeBoolSize
(
7
,
ExpandNamespaceDirectories
);
}
size
+=
UnknownFields
.
SerializedSize
;
size
+=
UnknownFields
.
SerializedSize
;
memoizedSerializedSize
=
size
;
memoizedSerializedSize
=
size
;
return
size
;
return
size
;
...
@@ -315,6 +331,9 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
...
@@ -315,6 +331,9 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
if
(
other
.
HasCodeContracts
)
{
if
(
other
.
HasCodeContracts
)
{
CodeContracts
=
other
.
CodeContracts
;
CodeContracts
=
other
.
CodeContracts
;
}
}
if
(
other
.
HasExpandNamespaceDirectories
)
{
ExpandNamespaceDirectories
=
other
.
ExpandNamespaceDirectories
;
}
this
.
MergeUnknownFields
(
other
.
UnknownFields
);
this
.
MergeUnknownFields
(
other
.
UnknownFields
);
return
this
;
return
this
;
}
}
...
@@ -371,6 +390,10 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
...
@@ -371,6 +390,10 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
CodeContracts
=
input
.
ReadBool
();
CodeContracts
=
input
.
ReadBool
();
break
;
break
;
}
}
case
56
:
{
ExpandNamespaceDirectories
=
input
.
ReadBool
();
break
;
}
}
}
}
}
}
}
...
@@ -485,6 +508,24 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
...
@@ -485,6 +508,24 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
result
.
codeContracts_
=
false
;
result
.
codeContracts_
=
false
;
return
this
;
return
this
;
}
}
public
bool
HasExpandNamespaceDirectories
{
get
{
return
result
.
HasExpandNamespaceDirectories
;
}
}
public
bool
ExpandNamespaceDirectories
{
get
{
return
result
.
ExpandNamespaceDirectories
;
}
set
{
SetExpandNamespaceDirectories
(
value
);
}
}
public
Builder
SetExpandNamespaceDirectories
(
bool
value
)
{
result
.
hasExpandNamespaceDirectories
=
true
;
result
.
expandNamespaceDirectories_
=
value
;
return
this
;
}
public
Builder
ClearExpandNamespaceDirectories
()
{
result
.
hasExpandNamespaceDirectories
=
false
;
result
.
expandNamespaceDirectories_
=
false
;
return
this
;
}
}
}
static
CSharpFileOptions
()
{
static
CSharpFileOptions
()
{
object
.
ReferenceEquals
(
global
::
Google
.
ProtocolBuffers
.
DescriptorProtos
.
CSharpOptions
.
Descriptor
,
null
);
object
.
ReferenceEquals
(
global
::
Google
.
ProtocolBuffers
.
DescriptorProtos
.
CSharpOptions
.
Descriptor
,
null
);
...
...
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