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
70ff8617
Commit
70ff8617
authored
Aug 14, 2008
by
Jon Skeet
Committed by
unknown
Aug 14, 2008
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improved generation for C\# files
committer: Jon Skeet <skeet@pobox.com>
parent
baa2bf54
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
121 additions
and
259 deletions
+121
-259
csharp_enum.cc
src/google/protobuf/compiler/csharp/csharp_enum.cc
+10
-105
csharp_enum_field.cc
src/google/protobuf/compiler/csharp/csharp_enum_field.cc
+5
-5
csharp_extension.cc
src/google/protobuf/compiler/csharp/csharp_extension.cc
+4
-4
csharp_file.cc
src/google/protobuf/compiler/csharp/csharp_file.cc
+48
-96
csharp_helpers.cc
src/google/protobuf/compiler/csharp/csharp_helpers.cc
+6
-6
csharp_message.cc
src/google/protobuf/compiler/csharp/csharp_message.cc
+0
-0
csharp_message_field.cc
src/google/protobuf/compiler/csharp/csharp_message_field.cc
+4
-4
csharp_primitive_field.cc
...google/protobuf/compiler/csharp/csharp_primitive_field.cc
+24
-18
csharp_service.cc
src/google/protobuf/compiler/csharp/csharp_service.cc
+20
-20
main.cc
src/google/protobuf/compiler/main.cc
+0
-1
No files found.
src/google/protobuf/compiler/csharp/csharp_enum.cc
View file @
70ff8617
...
...
@@ -58,8 +58,7 @@ void EnumGenerator::Generate(io::Printer* printer) {
descriptor_
->
containing_type
()
==
NULL
&&
descriptor_
->
file
()
->
options
().
csharp_multiple_files
();
printer
->
Print
(
"public $static$ enum $classname$ {
\r\n
"
,
"static"
,
is_own_file
?
""
:
"static"
,
"public enum $classname$ {
\r\n
"
,
"classname"
,
descriptor_
->
name
());
printer
->
Indent
();
...
...
@@ -68,16 +67,18 @@ void EnumGenerator::Generate(io::Printer* printer) {
vars
[
"name"
]
=
canonical_values_
[
i
]
->
name
();
vars
[
"index"
]
=
SimpleItoa
(
canonical_values_
[
i
]
->
index
());
vars
[
"number"
]
=
SimpleItoa
(
canonical_values_
[
i
]
->
number
());
// TODO(jonskeet): Change CONSTANT_CASE into PascalCase
printer
->
Print
(
vars
,
"$name$($index$, $number$),
\r\n
"
);
"[pb::DescriptorIndex($index$)]
\r\n
"
"$name$ = $number$,
\r\n
"
);
}
printer
->
Print
(
";
\r\n
"
"
\r\n
"
);
printer
->
Outdent
();
printer
->
Print
(
"}
\r\n\r\n
"
);
// -----------------------------------------------------------------
// TODO(jonskeet): Think about aliases!
/*
for (int i = 0; i < aliases_.size(); i++) {
map<string, string> vars;
vars["classname"] = descriptor_->name();
...
...
@@ -85,103 +86,7 @@ void EnumGenerator::Generate(io::Printer* printer) {
vars["canonical_name"] = aliases_[i].canonical_value->name();
printer->Print(vars,
"public static final $classname$ $name$ = $canonical_name$;\r\n");
}
// -----------------------------------------------------------------
printer
->
Print
(
"
\r\n
"
"public final int getNumber() { return value; }
\r\n
"
"
\r\n
"
"public static $classname$ valueOf(int value) {
\r\n
"
" switch (value) {
\r\n
"
,
"classname"
,
descriptor_
->
name
());
printer
->
Indent
();
printer
->
Indent
();
for
(
int
i
=
0
;
i
<
canonical_values_
.
size
();
i
++
)
{
printer
->
Print
(
"case $number$: return $name$;
\r\n
"
,
"name"
,
canonical_values_
[
i
]
->
name
(),
"number"
,
SimpleItoa
(
canonical_values_
[
i
]
->
number
()));
}
printer
->
Outdent
();
printer
->
Outdent
();
printer
->
Print
(
" default: return null;
\r\n
"
" }
\r\n
"
"}
\r\n
"
"
\r\n
"
);
// -----------------------------------------------------------------
// Reflection
printer
->
Print
(
"public final com.google.protobuf.Descriptors.EnumValueDescriptor
\r\n
"
" getValueDescriptor() {
\r\n
"
" return getDescriptor().getValues().get(index);
\r\n
"
"}
\r\n
"
"public final com.google.protobuf.Descriptors.EnumDescriptor
\r\n
"
" getDescriptorForType() {
\r\n
"
" return getDescriptor();
\r\n
"
"}
\r\n
"
"public static final com.google.protobuf.Descriptors.EnumDescriptor
\r\n
"
" getDescriptor() {
\r\n
"
);
// TODO(kenton): Cache statically? Note that we can't access descriptors
// at module init time because it wouldn't work with descriptor.proto, but
// we can cache the value the first time getDescriptor() is called.
if
(
descriptor_
->
containing_type
()
==
NULL
)
{
printer
->
Print
(
" return $file$.getDescriptor().getEnumTypes().get($index$);
\r\n
"
,
"file"
,
ClassName
(
descriptor_
->
file
()),
"index"
,
SimpleItoa
(
descriptor_
->
index
()));
}
else
{
printer
->
Print
(
" return $parent$.getDescriptor().getEnumTypes().get($index$);
\r\n
"
,
"parent"
,
ClassName
(
descriptor_
->
containing_type
()),
"index"
,
SimpleItoa
(
descriptor_
->
index
()));
}
printer
->
Print
(
"}
\r\n
"
"
\r\n
"
"private static final $classname$[] VALUES = {
\r\n
"
" "
,
"classname"
,
descriptor_
->
name
());
for
(
int
i
=
0
;
i
<
descriptor_
->
value_count
();
i
++
)
{
printer
->
Print
(
"$name$, "
,
"name"
,
descriptor_
->
value
(
i
)
->
name
());
}
printer
->
Print
(
"
\r\n
"
"};
\r\n
"
"public static $classname$ valueOf(
\r\n
"
" com.google.protobuf.Descriptors.EnumValueDescriptor desc) {
\r\n
"
" if (desc.getType() != getDescriptor()) {
\r\n
"
" throw new java.lang.IllegalArgumentException(
\r\n
"
"
\"
EnumValueDescriptor is not for this type.
\"
);
\r\n
"
" }
\r\n
"
" return VALUES[desc.getIndex()];
\r\n
"
"}
\r\n
"
,
"classname"
,
descriptor_
->
name
());
// -----------------------------------------------------------------
printer
->
Print
(
"private final int index;
\r\n
"
"private final int value;
\r\n
"
"private $classname$(int index, int value) {
\r\n
"
" this.index = index;
\r\n
"
" this.value = value;
\r\n
"
"}
\r\n
"
,
"classname"
,
descriptor_
->
name
());
printer
->
Outdent
();
printer
->
Print
(
"}
\r\n\r\n
"
);
}*/
}
}
// namespace csharp
...
...
src/google/protobuf/compiler/csharp/csharp_enum_field.cc
View file @
70ff8617
...
...
@@ -132,7 +132,7 @@ void EnumFieldGenerator::
GenerateSerializedSizeCode
(
io
::
Printer
*
printer
)
const
{
printer
->
Print
(
variables_
,
"if (has$capitalized_name$()) {
\r\n
"
" size +=
com.google.protobuf.
CodedOutputStream
\r\n
"
" size +=
pb::
CodedOutputStream
\r\n
"
" .computeEnumSize($number$, get$capitalized_name$().getNumber());
\r\n
"
"}
\r\n
"
);
}
...
...
@@ -172,7 +172,7 @@ GenerateBuilderMembers(io::Printer* printer) const {
// could hold on to the returned list and modify it after the message
// has been built, thus mutating the message which is supposed to be
// immutable.
"public
java.util.
List<$type$> get$capitalized_name$List() {
\r\n
"
"public
global::System.Collections.Generic::I
List<$type$> get$capitalized_name$List() {
\r\n
"
" return java.util.Collections.unmodifiableList(result.$name$_);
\r\n
"
"}
\r\n
"
"public int get$capitalized_name$Count() {
\r\n
"
...
...
@@ -192,8 +192,8 @@ GenerateBuilderMembers(io::Printer* printer) const {
" result.$name$_.add(value);
\r\n
"
" return this;
\r\n
"
"}
\r\n
"
"public Builder addAll$capitalized_name$(
\r\n
"
"
java.lang.Iterable<? extends $type$> values)
{
\r\n
"
"public Builder addAll$capitalized_name$
<T>
(
\r\n
"
"
global::System.Collections.Generic.IEnumerable<T> values) where T : $type$
{
\r\n
"
" if (result.$name$_.isEmpty()) {
\r\n
"
" result.$name$_ = new java.util.ArrayList<$type$>();
\r\n
"
" }
\r\n
"
...
...
@@ -250,7 +250,7 @@ void RepeatedEnumFieldGenerator::
GenerateSerializedSizeCode
(
io
::
Printer
*
printer
)
const
{
printer
->
Print
(
variables_
,
"for ($type$ element : get$capitalized_name$List()) {
\r\n
"
" size +=
com.google.protobuf.
CodedOutputStream
\r\n
"
" size +=
pb::
CodedOutputStream
\r\n
"
" .computeEnumSize($number$, element.getNumber());
\r\n
"
"}
\r\n
"
);
}
...
...
src/google/protobuf/compiler/csharp/csharp_extension.cc
View file @
70ff8617
...
...
@@ -57,20 +57,20 @@ void ExtensionGenerator::Generate(io::Printer* printer) {
if
(
descriptor_
->
is_repeated
())
{
printer
->
Print
(
vars
,
"public static final
\r\n
"
"
com.google.protobuf.
GeneratedMessage.GeneratedExtension<
\r\n
"
"
pb::
GeneratedMessage.GeneratedExtension<
\r\n
"
" $containing_type$,
\r\n
"
" java.util.List<$type$>> $name$ =
\r\n
"
"
com.google.protobuf.
GeneratedMessage
\r\n
"
"
pb::
GeneratedMessage
\r\n
"
" .newRepeatedGeneratedExtension(
\r\n
"
" getDescriptor().getExtensions().get($index$),
\r\n
"
" $type$.class);
\r\n
"
);
}
else
{
printer
->
Print
(
vars
,
"public static final
\r\n
"
"
com.google.protobuf.
GeneratedMessage.GeneratedExtension<
\r\n
"
"
pb::
GeneratedMessage.GeneratedExtension<
\r\n
"
" $containing_type$,
\r\n
"
" $type$> $name$ =
\r\n
"
"
com.google.protobuf.
GeneratedMessage.newGeneratedExtension(
\r\n
"
"
pb::
GeneratedMessage.newGeneratedExtension(
\r\n
"
" getDescriptor().getExtensions().get($index$),
\r\n
"
" $type$.class);
\r\n
"
);
}
...
...
src/google/protobuf/compiler/csharp/csharp_file.cc
View file @
70ff8617
...
...
@@ -69,7 +69,7 @@ bool FileGenerator::Validate(string* error) {
if
(
found_conflict
)
{
error
->
assign
(
file_
->
name
());
error
->
append
(
": Cannot generate
Java output because the file's outer
class name,
\"
"
);
": Cannot generate
C# output because the file's top-level
class name,
\"
"
);
error
->
append
(
classname_
);
error
->
append
(
"
\"
, matches the name of one of the types declared inside it. "
...
...
@@ -81,67 +81,25 @@ bool FileGenerator::Validate(string* error) {
return
true
;
}
// Shameless copy of CEscape, but using backslash-u encoding
// Still won't really work for anything non-ASCII.
static
int
UnicodeEscapeInternal
(
const
char
*
src
,
int
src_len
,
char
*
dest
,
int
dest_len
)
{
const
char
*
src_end
=
src
+
src_len
;
int
used
=
0
;
for
(;
src
<
src_end
;
src
++
)
{
if
(
dest_len
-
used
<
2
)
// Need space for two letter escape
return
-
1
;
bool
is_hex_escape
=
false
;
switch
(
*
src
)
{
case
'\n'
:
dest
[
used
++
]
=
'\\'
;
dest
[
used
++
]
=
'n'
;
break
;
case
'\r'
:
dest
[
used
++
]
=
'\\'
;
dest
[
used
++
]
=
'r'
;
break
;
case
'\t'
:
dest
[
used
++
]
=
'\\'
;
dest
[
used
++
]
=
't'
;
break
;
case
'\"'
:
dest
[
used
++
]
=
'\\'
;
dest
[
used
++
]
=
'\"'
;
break
;
case
'\''
:
dest
[
used
++
]
=
'\\'
;
dest
[
used
++
]
=
'\''
;
break
;
case
'\\'
:
dest
[
used
++
]
=
'\\'
;
dest
[
used
++
]
=
'\\'
;
break
;
default
:
if
(
*
src
<
0x20
||
*
src
>
0x7E
)
{
if
(
dest_len
-
used
<
6
)
// need space for 6 letter escape
return
-
1
;
sprintf
(
dest
+
used
,
"
\\
u00%02x"
,
static_cast
<
uint8
>
(
*
src
));
used
+=
6
;
}
else
{
dest
[
used
++
]
=
*
src
;
break
;
}
}
}
if
(
dest_len
-
used
<
1
)
// make sure that there is room for \0
return
-
1
;
dest
[
used
]
=
'\0'
;
// doesn't count towards return value though
return
used
;
}
string
UnicodeEscape
(
const
string
&
src
)
{
const
int
dest_length
=
src
.
size
()
*
6
+
1
;
// Maximum possible expansion
scoped_array
<
char
>
dest
(
new
char
[
dest_length
]);
const
int
len
=
UnicodeEscapeInternal
(
src
.
data
(),
src
.
size
(),
dest
.
get
(),
dest_length
);
GOOGLE_DCHECK_GE
(
len
,
0
);
return
string
(
dest
.
get
(),
len
);
}
void
FileGenerator
::
Generate
(
io
::
Printer
*
printer
)
{
// We don't import anything because we refer to all classes by their
// fully-qualified names in the generated source.
printer
->
Print
(
"// Generated by the protocol buffer compiler. DO NOT EDIT!
\r\n
"
"
\r\n
"
);
// Namespace alias to avoid lines getting horribly long
printer
->
Print
(
"using pb = global::Google.ProtocolBuffers;
\r\n\r\n
"
);
if
(
!
csharp_namespace_
.
empty
())
{
printer
->
Print
(
"
package $package$;
\r\n
"
"
namespace $namespace$ {
\r\n
"
"
\r\n
"
,
"package"
,
csharp_namespace_
);
"namespace"
,
csharp_namespace_
);
printer
->
Indent
();
}
printer
->
Print
(
"public
final
class $classname$ {
\r\n
"
"public
sealed
class $classname$ {
\r\n
"
" private $classname$() {}
\r\n
"
,
"classname"
,
classname_
);
printer
->
Indent
();
...
...
@@ -149,69 +107,50 @@ void FileGenerator::Generate(io::Printer* printer) {
// -----------------------------------------------------------------
// Embed the descriptor. We simply serialize the entire FileDescriptorProto
// and embed it as a string literal, which is parsed and built into real
// descriptors at initialization time. We unfortunately have to put it in
// a string literal, not a byte array, because apparently using a literal
// byte array causes the Java compiler to generate *instructions* to
// initialize each and every byte of the array, e.g. as if you typed:
// b[0] = 123; b[1] = 456; b[2] = 789;
// This makes huge bytecode files and can easily hit the compiler's internal
// code size limits (error "code to large"). String literals are apparently
// embedded raw, which is what we want.
// and embed it as a byte array, which is parsed and built into real
// descriptors at initialization time.
FileDescriptorProto
file_proto
;
file_
->
CopyTo
(
&
file_proto
);
string
file_data
;
file_proto
.
SerializeToString
(
&
file_data
);
printer
->
Print
(
"public static com.google.protobuf.Descriptors.FileDescriptor
\r\n
"
" getDescriptor() {
\r\n
"
" return descriptor;
\r\n
"
"public static pb::Descriptors.FileDescriptor Descriptor {
\r\n
"
" get { return descriptor; }
\r\n
"
"}
\r\n
"
"private static final com.google.protobuf.Descriptors.FileDescriptor
\r\n
"
" descriptor = buildDescriptor();
\r\n
"
"private static
\r\n
"
" com.google.protobuf.Descriptors.FileDescriptor
\r\n
"
" buildDescriptor() {
\r\n
"
" string descriptorData =
\r\n
"
);
"private static readonly pb::Descriptors.FileDescriptor descriptor = pb::Descriptors.FileDescriptor.InternalBuildGeneratedFileFrom (
\r\n
"
" new byte[] {"
);
printer
->
Indent
();
printer
->
Indent
();
printer
->
Indent
();
printer
->
Indent
();
// Only write 40 bytes per line.
static
const
int
kBytesPerLine
=
40
;
for
(
int
i
=
0
;
i
<
file_data
.
size
();
i
+=
kBytesPerLine
)
{
if
(
i
>
0
)
printer
->
Print
(
" +
\r\n
"
);
printer
->
Print
(
"
\"
$data$
\"
"
,
"data"
,
UnicodeEscape
(
file_data
.
substr
(
i
,
kBytesPerLine
)));
}
printer
->
Print
(
";
\r\n
"
);
// Only write 20 bytes per line.
static
const
int
kBytesPerLine
=
20
;
char
buffer
[
3
];
for
(
int
i
=
0
;
i
<
file_data
.
size
();
i
++
)
{
if
((
i
%
kBytesPerLine
)
==
0
)
{
printer
->
Print
(
"
\r\n
"
);
}
// TODO(jonskeet): There must be a better way of doing this!
sprintf
(
buffer
,
"%02x"
,
static_cast
<
uint8
>
(
file_data
[
i
]));
printer
->
Print
(
"0x$val$, "
,
"val"
,
buffer
);
}
printer
->
Outdent
();
printer
->
Print
(
"try {
\r\n
"
" return com.google.protobuf.Descriptors.FileDescriptor
\r\n
"
" .internalBuildGeneratedFileFrom(descriptorData,
\r\n
"
" new com.google.protobuf.Descriptors.FileDescriptor[] {
\r\n
"
);
printer
->
Outdent
();
printer
->
Print
(
"
\r\n
}, new pb::Descriptors.FileDescriptor[] {
\r\n
"
);
for
(
int
i
=
0
;
i
<
file_
->
dependency_count
();
i
++
)
{
printer
->
Print
(
" $dependency$.getDescriptor(),
\r\n
"
,
"dependency"
,
ClassName
(
file_
->
dependency
(
i
)));
}
printer
->
Print
(
" });
\r\n
"
"} catch (Exception e) {
\r\n
"
" throw new RuntimeException(
\r\n
"
"
\"
Failed to parse protocol buffer descriptor for
\"
+
\r\n
"
"
\"\\\"
$filename$
\\\"
.
\"
, e);
\r\n
"
"}
\r\n
"
,
"filename"
,
file_
->
name
());
printer
->
Print
(
"});
\r\n
"
);
printer
->
Outdent
();
printer
->
Print
(
"}
\r\n
"
"
\r\n
"
);
printer
->
Outdent
();
printer
->
Print
(
"
\r\n
"
);
// -----------------------------------------------------------------
...
...
@@ -241,6 +180,10 @@ void FileGenerator::Generate(io::Printer* printer) {
printer
->
Outdent
();
printer
->
Print
(
"}
\r\n
"
);
if
(
!
csharp_namespace_
.
empty
())
{
printer
->
Outdent
();
printer
->
Print
(
"}
\r\n
"
);
}
}
template
<
typename
GeneratorClass
,
typename
DescriptorClass
>
...
...
@@ -259,14 +202,23 @@ static void GenerateSibling(const string& package_dir,
printer
.
Print
(
"// Generated by the protocol buffer compiler. DO NOT EDIT!
\r\n
"
"
\r\n
"
);
// Namespace alias to avoid lines getting horribly long
printer
.
Print
(
"using pb = global::Google.ProtocolBuffers;
\r\n\r\n
"
);
if
(
!
csharp_namespace
.
empty
())
{
printer
.
Print
(
"
package $package$;
\r\n
"
"
namespace $namespace$ {
\r\n
"
"
\r\n
"
,
"package"
,
csharp_namespace
);
"namespace"
,
csharp_namespace
);
printer
.
Indent
();
}
GeneratorClass
(
descriptor
).
Generate
(
&
printer
);
if
(
!
csharp_namespace
.
empty
())
{
printer
.
Outdent
();
printer
.
Print
(
"}
\r\n
"
);
}
}
void
FileGenerator
::
GenerateSiblings
(
const
string
&
package_dir
,
...
...
src/google/protobuf/compiler/csharp/csharp_helpers.cc
View file @
70ff8617
...
...
@@ -206,13 +206,13 @@ JavaType GetJavaType(FieldDescriptor::Type field_type) {
const
char
*
BoxedPrimitiveTypeName
(
JavaType
type
)
{
switch
(
type
)
{
case
JAVATYPE_INT
:
return
"
java.lang.Integer
"
;
case
JAVATYPE_LONG
:
return
"
java.lang.L
ong"
;
case
JAVATYPE_FLOAT
:
return
"
java.lang.F
loat"
;
case
JAVATYPE_DOUBLE
:
return
"
java.lang.D
ouble"
;
case
JAVATYPE_BOOLEAN
:
return
"
java.lang.Boolean
"
;
case
JAVATYPE_INT
:
return
"
int
"
;
case
JAVATYPE_LONG
:
return
"
l
ong"
;
case
JAVATYPE_FLOAT
:
return
"
f
loat"
;
case
JAVATYPE_DOUBLE
:
return
"
d
ouble"
;
case
JAVATYPE_BOOLEAN
:
return
"
bool
"
;
case
JAVATYPE_STRING
:
return
"string"
;
case
JAVATYPE_BYTES
:
return
"
com.google.protobuf.
ByteString"
;
case
JAVATYPE_BYTES
:
return
"
pb::
ByteString"
;
case
JAVATYPE_ENUM
:
return
NULL
;
case
JAVATYPE_MESSAGE
:
return
NULL
;
...
...
src/google/protobuf/compiler/csharp/csharp_message.cc
View file @
70ff8617
This diff is collapsed.
Click to expand it.
src/google/protobuf/compiler/csharp/csharp_message_field.cc
View file @
70ff8617
...
...
@@ -153,7 +153,7 @@ void MessageFieldGenerator::
GenerateSerializedSizeCode
(
io
::
Printer
*
printer
)
const
{
printer
->
Print
(
variables_
,
"if (has$capitalized_name$()) {
\r\n
"
" size +=
com.google.protobuf.
CodedOutputStream
\r\n
"
" size +=
pb::
CodedOutputStream
\r\n
"
" .compute$group_or_message$Size($number$, get$capitalized_name$());
\r\n
"
"}
\r\n
"
);
}
...
...
@@ -225,8 +225,8 @@ GenerateBuilderMembers(io::Printer* printer) const {
" result.$name$_.add(builderForValue.build());
\r\n
"
" return this;
\r\n
"
"}
\r\n
"
"public Builder addAll$capitalized_name$(
\r\n
"
"
java.lang.Iterable<? extends $type$> values)
{
\r\n
"
"public Builder addAll$capitalized_name$
<T>
(
\r\n
"
"
global::System.Collections.Generic.IEnumerable<T> values) where T : $type$
{
\r\n
"
" if (result.$name$_.isEmpty()) {
\r\n
"
" result.$name$_ = new java.util.ArrayList<$type$>();
\r\n
"
" }
\r\n
"
...
...
@@ -288,7 +288,7 @@ void RepeatedMessageFieldGenerator::
GenerateSerializedSizeCode
(
io
::
Printer
*
printer
)
const
{
printer
->
Print
(
variables_
,
"for ($type$ element : get$capitalized_name$List()) {
\r\n
"
" size +=
com.google.protobuf.
CodedOutputStream
\r\n
"
" size +=
pb::
CodedOutputStream
\r\n
"
" .compute$group_or_message$Size($number$, element);
\r\n
"
"}
\r\n
"
);
}
...
...
src/google/protobuf/compiler/csharp/csharp_primitive_field.cc
View file @
70ff8617
...
...
@@ -44,7 +44,7 @@ const char* PrimitiveTypeName(JavaType type) {
case
JAVATYPE_DOUBLE
:
return
"double"
;
case
JAVATYPE_BOOLEAN
:
return
"boolean"
;
case
JAVATYPE_STRING
:
return
"string"
;
case
JAVATYPE_BYTES
:
return
"
com.google.protobuf.
ByteString"
;
case
JAVATYPE_BYTES
:
return
"
pb::
ByteString"
;
case
JAVATYPE_ENUM
:
return
NULL
;
case
JAVATYPE_MESSAGE
:
return
NULL
;
...
...
@@ -128,7 +128,7 @@ string DefaultValue(const FieldDescriptor* field) {
}
if
(
isBytes
&&
!
field
->
has_default_value
())
{
return
"
com.google.protobuf.ByteString.EMPTY
"
;
return
"
pb::ByteString.Empty
"
;
}
// Escaping strings correctly for Java and generating efficient
...
...
@@ -136,7 +136,7 @@ string DefaultValue(const FieldDescriptor* field) {
// whole problem by just grabbing the default value from the descriptor.
return
strings
::
Substitute
(
"(($0) $1.getDescriptor().getFields().get($2).getDefaultValue())"
,
isBytes
?
"
com.google.protobuf.
ByteString"
:
"string"
,
isBytes
?
"
pb::
ByteString"
:
"string"
,
ClassName
(
field
->
containing_type
()),
field
->
index
());
}
...
...
@@ -181,27 +181,33 @@ PrimitiveFieldGenerator::~PrimitiveFieldGenerator() {}
void
PrimitiveFieldGenerator
::
GenerateMembers
(
io
::
Printer
*
printer
)
const
{
printer
->
Print
(
variables_
,
"private bool
ean
has$capitalized_name$;
\r\n
"
"private bool has$capitalized_name$;
\r\n
"
"private $type$ $name$_ = $default$;
\r\n
"
"public boolean has$capitalized_name$() { return has$capitalized_name$; }
\r\n
"
"public $type$ get$capitalized_name$() { return $name$_; }
\r\n
"
);
"public boolean Has$capitalized_name$ {
\r\n
"
" get { return has$capitalized_name$; }
\r\n
"
"}
\r\n
"
"public $type$ $capitalized_name$ {
\r\n
"
" get { return $name$_; }
\r\n
"
"}
\r\n
"
);
}
void
PrimitiveFieldGenerator
::
GenerateBuilderMembers
(
io
::
Printer
*
printer
)
const
{
printer
->
Print
(
variables_
,
"public boolean has$capitalized_name$() {
\r\n
"
" return result.has$capitalized_name$();
\r\n
"
"}
\r\n
"
"public $type$ get$capitalized_name$() {
\r\n
"
" return result.get$capitalized_name$();
\r\n
"
"public boolean Has$capitalized_name$ {
\r\n
"
" get { return result.Has$capitalized_name$; }
\r\n
"
"}
\r\n
"
"public Builder set$capitalized_name$($type$ value) {
\r\n
"
" result.has$capitalized_name$ = true;
\r\n
"
" result.$name$_ = value;
\r\n
"
" return this;
\r\n
"
// TODO(jonskeet): Consider whether this is really the right pattern,
// or whether we want a method returning a Builder. This allows for
// object initializers.
"public $type$ $capitalized_name$ {
\r\n
"
" get { return result.$capitalized_name$; }
\r\n
"
" set {
\r\n
"
" result.has$capitalized_name$ = true;
\r\n
"
" result.$name$_ = value;
\r\n
"
" }
\r\n
"
"}
\r\n
"
"public Builder
c
lear$capitalized_name$() {
\r\n
"
"public Builder
C
lear$capitalized_name$() {
\r\n
"
" result.has$capitalized_name$ = false;
\r\n
"
" result.$name$_ = $default$;
\r\n
"
" return this;
\r\n
"
...
...
@@ -239,7 +245,7 @@ void PrimitiveFieldGenerator::
GenerateSerializedSizeCode
(
io
::
Printer
*
printer
)
const
{
printer
->
Print
(
variables_
,
"if (has$capitalized_name$()) {
\r\n
"
" size +=
com.google.protobuf.
CodedOutputStream
\r\n
"
" size +=
pb::
CodedOutputStream
\r\n
"
" .compute$capitalized_type$Size($number$, get$capitalized_name$());
\r\n
"
"}
\r\n
"
);
}
...
...
@@ -351,7 +357,7 @@ void RepeatedPrimitiveFieldGenerator::
GenerateSerializedSizeCode
(
io
::
Printer
*
printer
)
const
{
printer
->
Print
(
variables_
,
"for ($type$ element : get$capitalized_name$List()) {
\r\n
"
" size +=
com.google.protobuf.
CodedOutputStream
\r\n
"
" size +=
pb::
CodedOutputStream
\r\n
"
" .compute$capitalized_type$Size($number$, element);
\r\n
"
"}
\r\n
"
);
}
...
...
src/google/protobuf/compiler/csharp/csharp_service.cc
View file @
70ff8617
...
...
@@ -39,7 +39,7 @@ void ServiceGenerator::Generate(io::Printer* printer) {
bool
is_own_file
=
descriptor_
->
file
()
->
options
().
csharp_multiple_files
();
printer
->
Print
(
"public $static$ abstract class $classname$
\r\n
"
" implements
com.google.protobuf.
Service {
\r\n
"
,
" implements
pb::
Service {
\r\n
"
,
"static"
,
is_own_file
?
""
:
"static"
,
"classname"
,
descriptor_
->
name
());
printer
->
Indent
();
...
...
@@ -53,20 +53,20 @@ void ServiceGenerator::Generate(io::Printer* printer) {
vars
[
"output"
]
=
ClassName
(
method
->
output_type
());
printer
->
Print
(
vars
,
"public abstract void $name$(
\r\n
"
"
com.google.protobuf.
RpcController controller,
\r\n
"
"
pb::
RpcController controller,
\r\n
"
" $input$ request,
\r\n
"
"
com.google.protobuf.
RpcCallback<$output$> done);
\r\n
"
);
"
pb::
RpcCallback<$output$> done);
\r\n
"
);
}
// Generate getDescriptor() and getDescriptorForType().
printer
->
Print
(
"
\r\n
"
"public static final
\r\n
"
"
com.google.protobuf.
Descriptors.ServiceDescriptor
\r\n
"
"
pb::
Descriptors.ServiceDescriptor
\r\n
"
" getDescriptor() {
\r\n
"
" return $file$.getDescriptor().getServices().get($index$);
\r\n
"
"}
\r\n
"
"public final
com.google.protobuf.
Descriptors.ServiceDescriptor
\r\n
"
"public final
pb::
Descriptors.ServiceDescriptor
\r\n
"
" getDescriptorForType() {
\r\n
"
" return getDescriptor();
\r\n
"
"}
\r\n
"
,
...
...
@@ -87,11 +87,11 @@ void ServiceGenerator::GenerateCallMethod(io::Printer* printer) {
printer
->
Print
(
"
\r\n
"
"public final void callMethod(
\r\n
"
"
com.google.protobuf.
Descriptors.MethodDescriptor method,
\r\n
"
"
com.google.protobuf.
RpcController controller,
\r\n
"
"
com.google.protobuf.
Message request,
\r\n
"
"
com.google.protobuf.
RpcCallback<
\r\n
"
"
com.google.protobuf.
Message> done) {
\r\n
"
"
pb::
Descriptors.MethodDescriptor method,
\r\n
"
"
pb::
RpcController controller,
\r\n
"
"
pb::
Message request,
\r\n
"
"
pb::
RpcCallback<
\r\n
"
"
pb::
Message> done) {
\r\n
"
" if (method.getService() != getDescriptor()) {
\r\n
"
" throw new java.lang.IllegalArgumentException(
\r\n
"
"
\"
Service.callMethod() given method descriptor for wrong
\"
+
\r\n
"
...
...
@@ -111,7 +111,7 @@ void ServiceGenerator::GenerateCallMethod(io::Printer* printer) {
printer
->
Print
(
vars
,
"case $index$:
\r\n
"
" this.$method$(controller, ($input$)request,
\r\n
"
"
com.google.protobuf.
RpcUtil.<$output$>specializeCallback(
\r\n
"
"
pb::
RpcUtil.<$output$>specializeCallback(
\r\n
"
" done));
\r\n
"
" return;
\r\n
"
);
}
...
...
@@ -132,9 +132,9 @@ void ServiceGenerator::GenerateCallMethod(io::Printer* printer) {
void
ServiceGenerator
::
GenerateGetPrototype
(
RequestOrResponse
which
,
io
::
Printer
*
printer
)
{
printer
->
Print
(
"public final
com.google.protobuf.
Message
\r\n
"
"public final
pb::
Message
\r\n
"
" get$request_or_response$Prototype(
\r\n
"
"
com.google.protobuf.
Descriptors.MethodDescriptor method) {
\r\n
"
"
pb::
Descriptors.MethodDescriptor method) {
\r\n
"
" if (method.getService() != getDescriptor()) {
\r\n
"
" throw new java.lang.IllegalArgumentException(
\r\n
"
"
\"
Service.get$request_or_response$Prototype() given method
\"
+
\r\n
"
...
...
@@ -172,7 +172,7 @@ void ServiceGenerator::GenerateGetPrototype(RequestOrResponse which,
void
ServiceGenerator
::
GenerateStub
(
io
::
Printer
*
printer
)
{
printer
->
Print
(
"public static Stub newStub(
\r\n
"
"
com.google.protobuf.
RpcChannel channel) {
\r\n
"
"
pb::
RpcChannel channel) {
\r\n
"
" return new Stub(channel);
\r\n
"
"}
\r\n
"
"
\r\n
"
...
...
@@ -181,13 +181,13 @@ void ServiceGenerator::GenerateStub(io::Printer* printer) {
printer
->
Indent
();
printer
->
Print
(
"private Stub(
com.google.protobuf.
RpcChannel channel) {
\r\n
"
"private Stub(
pb::
RpcChannel channel) {
\r\n
"
" this.channel = channel;
\r\n
"
"}
\r\n
"
"
\r\n
"
"private final
com.google.protobuf.
RpcChannel channel;
\r\n
"
"private final
pb::
RpcChannel channel;
\r\n
"
"
\r\n
"
"public
com.google.protobuf.
RpcChannel getChannel() {
\r\n
"
"public
pb::
RpcChannel getChannel() {
\r\n
"
" return channel;
\r\n
"
"}
\r\n
"
);
...
...
@@ -201,15 +201,15 @@ void ServiceGenerator::GenerateStub(io::Printer* printer) {
printer
->
Print
(
vars
,
"
\r\n
"
"public void $method$(
\r\n
"
"
com.google.protobuf.
RpcController controller,
\r\n
"
"
pb::
RpcController controller,
\r\n
"
" $input$ request,
\r\n
"
"
com.google.protobuf.
RpcCallback<$output$> done) {
\r\n
"
"
pb::
RpcCallback<$output$> done) {
\r\n
"
" channel.callMethod(
\r\n
"
" getDescriptor().getMethods().get($index$),
\r\n
"
" controller,
\r\n
"
" request,
\r\n
"
" $output$.getDefaultInstance(),
\r\n
"
"
com.google.protobuf.
RpcUtil.generalizeCallback(
\r\n
"
"
pb::
RpcUtil.generalizeCallback(
\r\n
"
" done,
\r\n
"
" $output$.class,
\r\n
"
" $output$.getDefaultInstance()));
\r\n
"
...
...
src/google/protobuf/compiler/main.cc
View file @
70ff8617
...
...
@@ -36,7 +36,6 @@ int main(int argc, char* argv[]) {
cli
.
RegisterGenerator
(
"--java_out"
,
&
java_generator
,
"Generate Java source file."
);
// Proto2 Python
google
::
protobuf
::
compiler
::
python
::
Generator
py_generator
;
cli
.
RegisterGenerator
(
"--python_out"
,
&
py_generator
,
...
...
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