From 7429b91edafef18585d55ada62ba4ff01b88958c Mon Sep 17 00:00:00 2001 From: Josh Haberman Date: Mon, 18 Jul 2016 15:58:58 -0700 Subject: JavaScript: move extension binary info to separate struct. --- src/google/protobuf/compiler/js/js_generator.cc | 50 ++++++++++++++++++++----- 1 file changed, 40 insertions(+), 10 deletions(-) (limited to 'src/google/protobuf/compiler/js/js_generator.cc') diff --git a/src/google/protobuf/compiler/js/js_generator.cc b/src/google/protobuf/compiler/js/js_generator.cc index e030066e..d3852a95 100755 --- a/src/google/protobuf/compiler/js/js_generator.cc +++ b/src/google/protobuf/compiler/js/js_generator.cc @@ -2524,6 +2524,29 @@ void Generator::GenerateClassExtensionFieldInfo(const GeneratorOptions& options, "$class$.extensions = {};\n" "\n", "class", GetPath(options, desc)); + + if (options.binary) { + printer->Print( + "\n" + "/**\n" + " * The extensions registered with this message class. This is a " + "map of\n" + " * extension field number to fieldInfo object.\n" + " *\n" + " * For example:\n" + " * { 123: {fieldIndex: 123, fieldName: {my_field_name: 0}, " + "ctor: proto.example.MyMessage} }\n" + " *\n" + " * fieldName contains the JsCompiler renamed field name property " + "so that it\n" + " * works in OPTIMIZED mode.\n" + " *\n" + " * @type {!Object.}\n" + " */\n" + "$class$.extensionsBinary = {};\n" + "\n", + "class", GetPath(options, desc)); + } } } @@ -2571,7 +2594,7 @@ void Generator::GenerateClassDeserializeBinary(const GeneratorOptions& options, " default:\n"); if (IsExtendable(desc)) { printer->Print( - " jspb.Message.readBinaryExtension(msg, reader, $extobj$,\n" + " jspb.Message.readBinaryExtension(msg, reader, $extobj$Binary,\n" " $class$.prototype.getExtension,\n" " $class$.prototype.setExtension);\n" " break;\n", @@ -2705,8 +2728,8 @@ void Generator::GenerateClassSerializeBinary(const GeneratorOptions& options, if (IsExtendable(desc)) { printer->Print( - " jspb.Message.serializeBinaryExtensions(this, writer, $extobj$,\n" - " $class$.prototype.getExtension);\n", + " jspb.Message.serializeBinaryExtensions(this, writer,\n" + " $extobj$Binary, $class$.prototype.getExtension);\n", "extobj", JSExtensionsObjectName(options, desc->file(), desc), "class", GetPath(options, desc)); } @@ -2874,7 +2897,7 @@ void Generator::GenerateExtension(const GeneratorOptions& options, " /** @type {?function((boolean|undefined),!jspb.Message=): " "!Object} */ (\n" " $toObject$),\n" - " $repeated$", + " $repeated$);\n", "index", SimpleItoa(field->number()), "name", JSObjectFieldName(options, field), "ctor", (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE ? @@ -2886,12 +2909,18 @@ void Generator::GenerateExtension(const GeneratorOptions& options, if (options.binary) { printer->Print( - ",\n" + "\n" + "$extendName$Binary[$index$] = new jspb.ExtensionFieldBinaryInfo(\n" + " $class$.$name$,\n" " $binaryReaderFn$,\n" " $binaryWriterFn$,\n" " $binaryMessageSerializeFn$,\n" - " $binaryMessageDeserializeFn$,\n" - " $isPacked$);\n", + " $binaryMessageDeserializeFn$,\n", + "extendName", JSExtensionsObjectName(options, field->file(), + field->containing_type()), + "index", SimpleItoa(field->number()), + "class", extension_scope, + "name", JSObjectFieldName(options, field), "binaryReaderFn", JSBinaryReaderMethodName(options, field), "binaryWriterFn", JSBinaryWriterMethodName(options, field), "binaryMessageSerializeFn", @@ -2901,10 +2930,11 @@ void Generator::GenerateExtension(const GeneratorOptions& options, "binaryMessageDeserializeFn", (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) ? (SubmessageTypeRef(options, field) + - ".deserializeBinaryFromReader") : "null", + ".deserializeBinaryFromReader") : "null"); + + printer->Print( + " $isPacked$);\n", "isPacked", (field->is_packed() ? "true" : "false")); - } else { - printer->Print(");\n"); } printer->Print( -- cgit v1.2.3