Skip to content

Commit 36960c2

Browse files
committed
Fix serialization and deserialization generated code.
1 parent d31e215 commit 36960c2

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

generator/js_generator.cc

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3266,7 +3266,7 @@ void Generator::GenerateClassDeserializeBinary(const GeneratorOptions& options,
32663266
// TODO(cfallin): Handle lazy decoding when requested by field option and/or
32673267
// by default for 'bytes' fields and packed repeated fields.
32683268

3269-
const std::string classSymbol = GetMessagePath(options, desc);
3269+
const std::string classSymbol = desc->name();
32703270

32713271
printer->Print(
32723272
"/**\n"
@@ -3275,12 +3275,12 @@ void Generator::GenerateClassDeserializeBinary(const GeneratorOptions& options,
32753275
" * @return {!$class$}\n"
32763276
" */\n",
32773277
"class", classSymbol);
3278-
GenerateMethodStart(options, printer, classSymbol.c_str(), "deserializeBinary");
32793278
printer->Print(
3280-
"(bytes) {\n"
3279+
"$methodstart$(bytes) {\n"
32813280
" var reader = new jspb.BinaryReader(bytes);\n"
32823281
" var msg = new $class$;\n"
32833282
" return $class$.deserializeBinaryFromReader(msg, reader);\n",
3283+
"methodstart", this->MethodStartStatic(options, classSymbol.c_str(), "deserializeBinary"),
32843284
"class", classSymbol);
32853285

32863286
GenerateMethodEnd(options, printer);
@@ -3297,15 +3297,15 @@ printer->Print(
32973297
" * @return {!$class$}\n"
32983298
" */\n",
32993299
"class", classSymbol);
3300-
GenerateMethodStart(options, printer, classSymbol.c_str(), "deserializeBinaryFromReader");
33013300
printer->Print(
3302-
"(msg, reader) {\n"
3301+
"$methodstart$(msg, reader) {\n"
33033302
" while (reader.nextField()) {\n"
33043303
" if (reader.isEndGroup()) {\n"
33053304
" break;\n"
33063305
" }\n"
33073306
" var field = reader.getFieldNumber();\n"
3308-
" switch (field) {\n");
3307+
" switch (field) {\n",
3308+
"methodstart", MethodStartStatic(options, classSymbol.c_str(), "deserializeBinaryFromReader"));
33093309

33103310
for (int i = 0; i < desc->field_count(); i++) {
33113311
if (!IgnoreField(desc->field(i))) {
@@ -3442,19 +3442,19 @@ void Generator::GenerateClassSerializeBinary(const GeneratorOptions& options,
34423442
io::Printer* printer,
34433443
const Descriptor* desc) const {
34443444

3445-
const std::string classSymbol = GetMessagePath(options, desc);
3445+
const std::string classSymbol = desc->name();
34463446

34473447
printer->Print(
34483448
"/**\n"
34493449
" * Serializes the message to binary data (in protobuf wire format).\n"
34503450
" * @return {!Uint8Array}\n"
34513451
" */\n");
3452-
GenerateMethodStart(options, printer, classSymbol.c_str(), "serializeBinary");
34533452
printer->Print(
3454-
"() {\n"
3453+
"$methodstart$() {\n"
34553454
" var writer = new jspb.BinaryWriter();\n"
3456-
" $class$.serializeBinaryToWriter(this, writer);\n"
3455+
" this.constructor.serializeBinaryToWriter(this, writer);\n"
34573456
" return writer.getResultBuffer();\n",
3457+
"methodstart", MethodStart(options, classSymbol.c_str(), "serializeBinary"),
34583458
"class", classSymbol);
34593459

34603460
GenerateMethodEnd(options, printer);
@@ -3468,12 +3468,11 @@ void Generator::GenerateClassSerializeBinary(const GeneratorOptions& options,
34683468
" * @param {!$class$} message\n"
34693469
" * @param {!jspb.BinaryWriter} writer\n"
34703470
" * @suppress {unusedLocalVariables} f is only used for nested messages\n"
3471-
" */\n",
3471+
" */\n"
3472+
"$methodstart$(message, writer) {\n"
3473+
" var f = undefined;\n",
3474+
"methodstart", MethodStartStatic(options, classSymbol.c_str(), "serializeBinaryToWriter"),
34723475
"class", classSymbol);
3473-
GenerateMethodStart(options, printer, classSymbol.c_str(), "serializeBinaryToWriter");
3474-
printer->Print(
3475-
"(message, writer) {\n"
3476-
" var f = undefined;\n");
34773476

34783477
for (int i = 0; i < desc->field_count(); i++) {
34793478
if (!IgnoreField(desc->field(i))) {

0 commit comments

Comments
 (0)