├── .bazelrc ├── .github ├── ISSUE_TEMPLATE │ └── limited-issue-and-fr-support.md ├── pull_request_template.md └── workflows │ ├── build.yml │ ├── codeql.yml │ └── scorecard.yml ├── .gitignore ├── BUILD.bazel ├── LICENSE-asserts.md ├── LICENSE.md ├── MODULE.bazel ├── MODULE.bazel.lock ├── README.md ├── asserts.js ├── binary ├── arith.js ├── arith_test.js ├── constants.js ├── decoder.js ├── decoder_test.js ├── encoder.js ├── message_test.js ├── proto_test.js ├── reader.js ├── reader_test.js ├── utf8.js ├── utils.js ├── utils_test.js ├── writer.js └── writer_test.js ├── commonjs ├── export.js ├── export_testdeps.js ├── import_test.js ├── jasmine.json ├── rewrite_tests_for_commonjs.js ├── strict_test.js ├── test6 │ └── test6.proto └── test7 │ └── test7.proto ├── compatibility_tests ├── v3.0.0 │ ├── binary │ │ ├── arith_test.js │ │ ├── decoder_test.js │ │ ├── proto_test.js │ │ ├── reader_test.js │ │ ├── utils_test.js │ │ └── writer_test.js │ ├── commonjs │ │ ├── export_asserts.js │ │ ├── export_testdeps.js │ │ ├── import_test.js │ │ ├── jasmine.json │ │ ├── rewrite_tests_for_commonjs.js │ │ ├── test6 │ │ │ └── test6.proto │ │ └── test7 │ │ │ └── test7.proto │ ├── data.proto │ ├── debug_test.js │ ├── jasmine1.json │ ├── jasmine2.json │ ├── jasmine3.json │ ├── message_test.js │ ├── proto3_test.js │ ├── proto3_test.proto │ ├── test.proto │ ├── test.sh │ ├── test2.proto │ ├── test3.proto │ ├── test4.proto │ ├── test5.proto │ ├── testbinary.proto │ └── testempty.proto └── v3.1.0 │ ├── binary │ ├── arith_test.js │ ├── decoder_test.js │ ├── proto_test.js │ ├── reader_test.js │ ├── utils_test.js │ └── writer_test.js │ ├── commonjs │ ├── test6 │ │ └── test6.proto │ └── test7 │ │ └── test7.proto │ ├── data.proto │ ├── debug_test.js │ ├── maps_test.js │ ├── message_test.js │ ├── proto3_test.js │ ├── proto3_test.proto │ ├── test.proto │ ├── test2.proto │ ├── test3.proto │ ├── test4.proto │ ├── test5.proto │ ├── testbinary.proto │ └── testempty.proto ├── debug.js ├── debug_test.js ├── docs └── index.md ├── experimental ├── benchmarks │ └── code_size │ │ ├── apps_jspb │ │ ├── all_types_proto2.js │ │ ├── all_types_proto3.js │ │ ├── popular_types_proto2.js │ │ └── popular_types_proto3.js │ │ ├── code_size_base.js │ │ └── kernel │ │ ├── all_types.js │ │ └── popular_types.js └── runtime │ ├── bytestring.js │ ├── bytestring_internal.js │ ├── bytestring_test.js │ ├── int64.js │ ├── int64_test.js │ ├── internal │ ├── checks.js │ └── checks_test.js │ ├── kernel │ ├── binary_storage.js │ ├── binary_storage_test.js │ ├── bool_test_pairs.js │ ├── buffer_decoder.js │ ├── buffer_decoder_helper.js │ ├── buffer_decoder_test.js │ ├── conformance │ │ ├── conformance_request.js │ │ ├── conformance_response.js │ │ ├── conformance_testee.js │ │ ├── conformance_testee_runner_node.js │ │ ├── test_all_types_proto2.js │ │ ├── test_all_types_proto3.js │ │ └── wire_format.js │ ├── double_test_pairs.js │ ├── field.js │ ├── fixed32_test_pairs.js │ ├── float_test_pairs.js │ ├── indexer.js │ ├── indexer_test.js │ ├── int32_test_pairs.js │ ├── int64_test_pairs.js │ ├── internal_message.js │ ├── kernel.js │ ├── kernel_compatibility_test.js │ ├── kernel_repeated_test.js │ ├── kernel_test.js │ ├── message_set.js │ ├── message_set_test.js │ ├── packed_bool_test_pairs.js │ ├── packed_double_test_pairs.js │ ├── packed_fixed32_test_pairs.js │ ├── packed_float_test_pairs.js │ ├── packed_int32_test_pairs.js │ ├── packed_int64_test_pairs.js │ ├── packed_sfixed32_test_pairs.js │ ├── packed_sfixed64_test_pairs.js │ ├── packed_sint32_test_pairs.js │ ├── packed_sint64_test_pairs.js │ ├── packed_uint32_test_pairs.js │ ├── reader.js │ ├── reader_test.js │ ├── sfixed32_test_pairs.js │ ├── sfixed64_test_pairs.js │ ├── sint32_test_pairs.js │ ├── sint64_test_pairs.js │ ├── storage.js │ ├── tag.js │ ├── tag_test.js │ ├── textencoding.js │ ├── textencoding_test.js │ ├── typed_arrays.js │ ├── typed_arrays_test.js │ ├── uint32_test_pairs.js │ ├── uint8arrays.js │ ├── uint8arrays_test.js │ ├── wire_type.js │ ├── writer.js │ └── writer_test.js │ └── testing │ ├── binary │ └── test_message.js │ ├── ensure_custom_equality_test.js │ └── jasmine_protobuf.js ├── generator ├── BUILD.bazel ├── js_generator.cc ├── js_generator.h ├── protoc-gen-js.cc ├── well_known_types_embed.cc └── well_known_types_embed.h ├── gulpfile.js ├── jasmine.json ├── map.js ├── maps_test.js ├── message.js ├── message_test.js ├── node_loader.js ├── package-lock.json ├── package.json ├── proto3_test.js ├── protobuf_javascript_release.bzl ├── protos ├── data.proto ├── proto3_test.proto ├── test.proto ├── test10.proto ├── test11.proto ├── test12.proto ├── test13.proto ├── test14.proto ├── test15.proto ├── test2.proto ├── test3.proto ├── test4.proto ├── test5.proto ├── test8.proto ├── test9.proto ├── testbinary.proto ├── testempty.proto └── testlargenumbers.proto ├── test_bootstrap.js └── yarn.lock /.bazelrc: -------------------------------------------------------------------------------- 1 | build --cxxopt=-std=c++17 --host_cxxopt=-std=c++17 2 | 3 | build:dbg --compilation_mode=dbg 4 | 5 | build:opt --compilation_mode=opt 6 | 7 | build:san-common --config=dbg --strip=never --copt=-O0 --copt=-fno-omit-frame-pointer 8 | 9 | build:asan --config=san-common --copt=-fsanitize=address --linkopt=-fsanitize=address 10 | # ASAN hits ODR violations with shared linkage due to rules_proto. 11 | build:asan --dynamic_mode=off 12 | 13 | build:msan --config=san-common --copt=-fsanitize=memory --linkopt=-fsanitize=memory 14 | build:msan --copt=-fsanitize-memory-track-origins 15 | build:msan --copt=-fsanitize-memory-use-after-dtor 16 | build:msan --action_env=MSAN_OPTIONS=poison_in_dtor=1 17 | 18 | build:tsan --config=san-common --copt=-fsanitize=thread --linkopt=-fsanitize=thread 19 | 20 | build:ubsan --config=san-common --copt=-fsanitize=undefined --linkopt=-fsanitize=undefined 21 | build:ubsan --action_env=UBSAN_OPTIONS=halt_on_error=1:print_stacktrace=1 22 | # Workaround for the fact that Bazel links with $CC, not $CXX 23 | # https://github.com/bazelbuild/bazel/issues/11122#issuecomment-613746748 24 | build:ubsan --copt=-fno-sanitize=function --copt=-fno-sanitize=vptr 25 | 26 | # Important: this flag ensures that we remain compliant with the C++ layering 27 | # check. 28 | build --features=layering_check 29 | 30 | common --repo_env=BAZEL_NO_APPLE_CPP_TOOLCHAIN=1 31 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/limited-issue-and-fr-support.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Limited Issue and FR support 3 | about: Template for limited support 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | Due to our limited support resources, feature requests will generally not be accepted, except for those referring to build or tooling integration. 11 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | Due to our limited support resources, we are focusing our attention on small bug fixes that have limited compatibility concerns. Most other PRs will be rejected. 2 | -------------------------------------------------------------------------------- /.github/workflows/codeql.yml: -------------------------------------------------------------------------------- 1 | # For most projects, this workflow file will not need changing; you simply need 2 | # to commit it to your repository. 3 | # 4 | # You may wish to alter this file to override the set of languages analyzed, 5 | # or to provide custom queries or build logic. 6 | # 7 | # ******** NOTE ******** 8 | # We have attempted to detect the languages in your repository. Please check 9 | # the `language` matrix defined below to confirm you have the correct set of 10 | # supported CodeQL languages. 11 | # 12 | name: "CodeQL" 13 | 14 | permissions: read-all 15 | 16 | # update in build.yml and codeql.yml at same time 17 | env: 18 | PROTOC_VERSION: "31.0" 19 | 20 | on: 21 | push: 22 | branches: [ "main" ] 23 | pull_request: 24 | # The branches below must be a subset of the branches above 25 | branches: [ "main" ] 26 | schedule: 27 | - cron: '45 15 * * 4' 28 | 29 | jobs: 30 | analyze: 31 | name: Analyze 32 | runs-on: ubuntu-latest 33 | permissions: 34 | actions: read 35 | contents: read 36 | security-events: write 37 | 38 | strategy: 39 | fail-fast: false 40 | matrix: 41 | language: [ 'cpp', 'javascript' ] 42 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] 43 | # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support 44 | 45 | env: 46 | PROTOC: protoc-release/bin/protoc 47 | PROTOC_INC: protoc-release/include 48 | PROTOC_PLATFORM: linux-x86_64 49 | 50 | steps: 51 | - name: Checkout repository 52 | uses: actions/checkout@v4 53 | 54 | # Initializes the CodeQL tools for scanning. 55 | - name: Initialize CodeQL 56 | uses: github/codeql-action/init@v3 57 | with: 58 | languages: ${{ matrix.language }} 59 | # If you wish to specify custom queries, you can do so here or in a config file. 60 | # By default, queries listed here will override any specified in a config file. 61 | # Prefix the list here with "+" to use these queries and those in the config file. 62 | 63 | # Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs 64 | # queries: security-extended,security-and-quality 65 | 66 | 67 | # ℹ️ Command-line programs to run using the OS shell. 68 | # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun 69 | 70 | - name: Install Protoc 71 | run: | 72 | echo "Fetching protoc" 73 | curl --header 'Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \ 74 | -L https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-${PROTOC_PLATFORM}.zip \ 75 | --output protoc-release.zip 76 | unzip protoc-release.zip -d protoc-release 77 | rm protoc-release.zip 78 | 79 | - run: npm ci 80 | 81 | - run: npm test 82 | 83 | - name: Perform CodeQL Analysis 84 | uses: github/codeql-action/analyze@v3 85 | -------------------------------------------------------------------------------- /.github/workflows/scorecard.yml: -------------------------------------------------------------------------------- 1 | # This workflow uses actions that are not certified by GitHub. They are provided 2 | # by a third-party and are governed by separate terms of service, privacy 3 | # policy, and support documentation. 4 | 5 | name: Scorecard supply-chain security 6 | on: 7 | # For Branch-Protection check. Only the default branch is supported. See 8 | # https://github.com/ossf/scorecard/blob/main/docs/checks.md#branch-protection 9 | branch_protection_rule: 10 | # To guarantee Maintained check is occasionally updated. See 11 | # https://github.com/ossf/scorecard/blob/main/docs/checks.md#maintained 12 | schedule: 13 | - cron: '32 5 * * 0' 14 | push: 15 | branches: [ "main" ] 16 | 17 | # Declare default permissions as read only. 18 | permissions: read-all 19 | 20 | jobs: 21 | analysis: 22 | name: Scorecard analysis 23 | runs-on: ubuntu-latest 24 | permissions: 25 | # Needed to upload the results to code-scanning dashboard. 26 | security-events: write 27 | # Needed to publish results and get a badge (see publish_results below). 28 | id-token: write 29 | # Uncomment the permissions below if installing in a private repository. 30 | # contents: read 31 | # actions: read 32 | 33 | steps: 34 | - name: "Checkout code" 35 | uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 36 | with: 37 | persist-credentials: false 38 | 39 | - name: "Run analysis" 40 | uses: ossf/scorecard-action@0864cf19026789058feabb7e87baa5f140aac736 # v2.3.1 41 | with: 42 | results_file: results.sarif 43 | results_format: sarif 44 | # (Optional) "write" PAT token. Uncomment the `repo_token` line below if: 45 | # - you want to enable the Branch-Protection check on a *public* repository, or 46 | # - you are installing Scorecard on a *private* repository 47 | # To create the PAT, follow the steps in https://github.com/ossf/scorecard-action?tab=readme-ov-file#authentication-with-fine-grained-pat-optional. 48 | # repo_token: ${{ secrets.SCORECARD_TOKEN }} 49 | 50 | # Public repositories: 51 | # - Publish results to OpenSSF REST API for easy access by consumers 52 | # - Allows the repository to include the Scorecard badge. 53 | # - See https://github.com/ossf/scorecard-action#publishing-results. 54 | # For private repositories: 55 | # - `publish_results` will always be set to `false`, regardless 56 | # of the value entered here. 57 | publish_results: true 58 | 59 | # Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF 60 | # format to the repository Actions tab. 61 | - name: "Upload artifact" 62 | uses: actions/upload-artifact@97a0fba1372883ab732affbe8f94b823f91727db # v3.pre.node20 63 | with: 64 | name: SARIF file 65 | path: results.sarif 66 | retention-days: 5 67 | 68 | # Upload the results to GitHub's code scanning dashboard (optional). 69 | # Commenting out will disable upload of results to your repo's Code Scanning dashboard 70 | - name: "Upload to code-scanning" 71 | uses: github/codeql-action/upload-sarif@v3 72 | with: 73 | sarif_file: results.sarif 74 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | node_modules 3 | commonjs_out 4 | google/protobuf 5 | bazel-* 6 | /deps.js 7 | /testproto_libs1.js 8 | /testproto_libs2.js 9 | /google-protobuf.js 10 | -------------------------------------------------------------------------------- /BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Protobuf JS runtime 2 | # 3 | # See also code generation logic under generator/ 4 | 5 | load("@rules_pkg//:mappings.bzl", "pkg_attributes", "pkg_files", "strip_prefix") 6 | load("@rules_pkg//:pkg.bzl", "pkg_tar", "pkg_zip") 7 | load("//:protobuf_javascript_release.bzl", "package_naming") 8 | 9 | config_setting( 10 | name = "x64_x86_windows", 11 | values = {"cpu": "x64_x86_windows"}, 12 | ) 13 | 14 | config_setting( 15 | name = "x64_windows", 16 | values = {"cpu": "x64_windows"}, 17 | ) 18 | 19 | config_setting( 20 | name = "k8", 21 | values = {"cpu": "k8"}, 22 | ) 23 | 24 | package_naming( 25 | name = "protobuf_javascript_pkg_naming", 26 | platform = select({ 27 | ":k8": "linux-x86_64", # currently the only supported build type in Github Actions 28 | ":x64_x86_windows": "win32", 29 | ":x64_windows": "win64", 30 | "//conditions:default": "" # continues with current behavior when no --cpu is specified allowing existing internal builds to function 31 | }) 32 | ) 33 | 34 | pkg_files( 35 | name = "plugin_files", 36 | srcs = ["//generator:protoc-gen-js"], 37 | attributes = pkg_attributes(mode = "0555"), 38 | prefix = "bin/", 39 | ) 40 | 41 | pkg_files( 42 | name = "dist_files", 43 | srcs = glob([ 44 | "google/protobuf/*.js", 45 | "google/protobuf/compiler/*.js" 46 | ]) + [ 47 | "google-protobuf.js", 48 | "package.json", 49 | "README.md", 50 | "LICENSE.md", 51 | "LICENSE-asserts.md", 52 | ], 53 | strip_prefix = strip_prefix.from_root(""), 54 | ) 55 | 56 | pkg_tar( 57 | name = "dist_tar", 58 | srcs = [ 59 | ":dist_files", 60 | ":plugin_files", 61 | ], 62 | extension = "tar.gz", 63 | package_file_name = "protobuf-javascript-{version}-{platform}.tar.gz", 64 | package_variables = ":protobuf_javascript_pkg_naming", 65 | ) 66 | 67 | pkg_zip( 68 | name = "dist_zip", 69 | srcs = [ 70 | ":dist_files", 71 | ":plugin_files", 72 | ], 73 | package_file_name = "protobuf-javascript-{version}-{platform}.zip", 74 | package_variables = ":protobuf_javascript_pkg_naming", 75 | ) 76 | 77 | filegroup( 78 | name = "dist_all", 79 | srcs = [ 80 | ":dist_tar", 81 | ":dist_zip", 82 | ] 83 | ) 84 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2022, Google Inc. 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | 3. Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /MODULE.bazel: -------------------------------------------------------------------------------- 1 | module(name = "protobuf_javascript", version = "3.21.4") 2 | 3 | bazel_dep(name = "protobuf", version = "31.0", repo_name = "com_google_protobuf") 4 | bazel_dep(name = "rules_pkg", version = "1.0.1") 5 | bazel_dep(name = "abseil-cpp", version = "20250127.0") 6 | -------------------------------------------------------------------------------- /binary/message_test.js: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://protobuf.dev/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Test suite is written using Jasmine -- see http://jasmine.github.io/ 32 | 33 | goog.setTestOnly(); 34 | 35 | // CommonJS-LoadFromFile: ../protos/test_pb proto.jspb.test 36 | goog.require('proto.jspb.test.Deeply.Nested.Message'); 37 | 38 | // CommonJS-LoadFromFile: ../protos/test2_pb proto.jspb.test 39 | goog.require('proto.jspb.test.ForeignNestedFieldMessage'); 40 | 41 | describe('Message test suite', () => { 42 | // Verify that we can successfully use a field referring to a nested message 43 | // from a different .proto file. 44 | it('testForeignNestedMessage', () => { 45 | const msg = new proto.jspb.test.ForeignNestedFieldMessage(); 46 | const nested = new proto.jspb.test.Deeply.Nested.Message(); 47 | nested.setCount(5); 48 | msg.setDeeplyNestedMessage(nested); 49 | expect(msg.getDeeplyNestedMessage().getCount()).toEqual(5); 50 | 51 | // After a serialization-deserialization round trip we should get back the 52 | // same data we started with. 53 | const serialized = msg.serializeBinary(); 54 | const deserialized = 55 | proto.jspb.test.ForeignNestedFieldMessage.deserializeBinary(serialized); 56 | expect(deserialized.getDeeplyNestedMessage().getCount()).toEqual(5); 57 | }); 58 | }); 59 | -------------------------------------------------------------------------------- /commonjs/export.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @fileoverview Export symbols needed by generated code in CommonJS style. 3 | * 4 | * This effectively is our canonical list of what we publicly export from 5 | * the google-protobuf.js file that we build at distribution time. 6 | */ 7 | 8 | goog.provide('jspb.Export'); 9 | 10 | goog.require('goog.object'); 11 | 12 | goog.require('jspb.debug'); 13 | goog.require('jspb.BinaryReader'); 14 | goog.require('jspb.BinaryWriter'); 15 | goog.require('jspb.ExtensionFieldBinaryInfo'); 16 | goog.require('jspb.ExtensionFieldInfo'); 17 | goog.require('jspb.Message'); 18 | goog.require('jspb.Map'); 19 | 20 | 21 | if (typeof exports === 'object') { 22 | exports['debug'] = jspb.debug; 23 | exports['Map'] = jspb.Map; 24 | exports['Message'] = jspb.Message; 25 | 26 | exports['BinaryReader'] = jspb.BinaryReader; 27 | exports['BinaryWriter'] = jspb.BinaryWriter; 28 | exports['ExtensionFieldInfo'] = jspb.ExtensionFieldInfo; 29 | exports['ExtensionFieldBinaryInfo'] = jspb.ExtensionFieldBinaryInfo; 30 | 31 | // These are used by generated code but should not be used directly by clients. 32 | exports['exportSymbol'] = goog.exportSymbol; 33 | exports['inherits'] = goog.inherits; 34 | exports['object'] = {extend: goog.object.extend}; 35 | exports['typeOf'] = goog.typeOf; 36 | } 37 | -------------------------------------------------------------------------------- /commonjs/export_testdeps.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @fileoverview Export symbols needed by tests in CommonJS style. 3 | * 4 | * This file is like export.js, but for symbols that are only used by tests. 5 | * However we exclude assert functions here, because they are exported into 6 | * the global namespace, so those are handled as a special case in 7 | * export_asserts.js. 8 | */ 9 | 10 | goog.provide('jspb.ExportTestDeps'); 11 | 12 | goog.require('goog.crypt.base64'); 13 | goog.require('goog.testing.PropertyReplacer'); 14 | 15 | goog.require('jspb.debug'); 16 | goog.require('jspb.BinaryReader'); 17 | goog.require('jspb.BinaryWriter'); 18 | goog.require('jspb.ExtensionFieldBinaryInfo'); 19 | goog.require('jspb.ExtensionFieldInfo'); 20 | goog.require('jspb.Message'); 21 | goog.require('jspb.Map'); 22 | 23 | if (typeof exports === 'object') { 24 | exports['goog'] = { 25 | 'crypt': { 26 | 'byteArrayToString': goog.crypt.byteArrayToString, 27 | 'byteArrayToHex': goog.crypt.byteArrayToHex, 28 | 'base64': { 29 | 'Alphabet': goog.crypt.base64.Alphabet, 30 | 'encodeByteArray': goog.crypt.base64.encodeByteArray, 31 | 'encodeString': goog.crypt.base64.encodeString, 32 | 'decodeStringToUint8Array': goog.crypt.base64.decodeStringToUint8Array 33 | } 34 | }, 35 | 36 | 'testing': { 37 | 'PropertyReplacer': goog.testing.PropertyReplacer, 38 | }, 39 | 40 | 'userAgent': goog.userAgent, 41 | 42 | 'exportSymbol': goog.exportSymbol, 43 | 'array': goog.array, 44 | 'object': goog.object, 45 | 'requireType': goog.requireType, 46 | }; 47 | 48 | exports['jspb'] = { 49 | 'debug': jspb.debug, 50 | 'BinaryReader': jspb.BinaryReader, 51 | 'BinaryWriter': jspb.BinaryWriter, 52 | 'ExtensionFieldBinaryInfo': jspb.ExtensionFieldBinaryInfo, 53 | 'ExtensionFieldInfo': jspb.ExtensionFieldInfo, 54 | 'Message': jspb.Message, 55 | 'Map': jspb.Map, 56 | }; 57 | // exports['exportSymbol'] = goog.exportSymbol; 58 | // exports['inherits'] = goog.inherits; 59 | // exports['object'] = {extend: goog.object.extend}; 60 | // exports['typeOf'] = goog.typeOf; 61 | // exports['requireType'] = goog.requireType; 62 | 63 | // The COMPILED variable is set by Closure compiler to "true" when it compiles 64 | // JavaScript, so in practice this is equivalent to "exports.COMPILED = true". 65 | // This will disable some debugging functionality in debug.js, such as 66 | // attempting to check names that have been optimized away. 67 | exports['COMPILED'] = COMPILED; 68 | } 69 | -------------------------------------------------------------------------------- /commonjs/import_test.js: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2016 Google Inc. All rights reserved. 3 | // https://protobuf.dev/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Test suite is written using Jasmine -- see http://jasmine.github.io/ 32 | 33 | 34 | 35 | const googleProtobuf = require('google-protobuf'); 36 | const global = Function('return this')(); 37 | 38 | googleProtobuf.exportSymbol('jspb.Message', googleProtobuf.Message, global); 39 | 40 | var test7_pb = require('./test7/test7_pb'); 41 | googleProtobuf.exportSymbol('proto.jspb.test.framing.FramingMessage', test7_pb.FramingMessage, global); 42 | 43 | describe('Import test suite', () => { 44 | it('testImportedMessage', () => { 45 | const framing1 = new proto.jspb.test.framing.FramingMessage([]); 46 | const framing2 = new proto.jspb.test.framing.FramingMessage([]); 47 | expect(framing1.toObject()).toEqual(framing2.toObject()); 48 | }); 49 | }); 50 | -------------------------------------------------------------------------------- /commonjs/jasmine.json: -------------------------------------------------------------------------------- 1 | { 2 | "spec_dir": "", 3 | "spec_files": [ 4 | "*_test.js", 5 | "binary/*_test.js" 6 | ], 7 | "helpers": [ 8 | ], 9 | "env": { 10 | "stopSpecOnExpectationFailure": true, 11 | "stopOnSpecFailure": true, 12 | "random": false 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /commonjs/rewrite_tests_for_commonjs.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @fileoverview Utility to translate test files to CommonJS imports. 3 | * 4 | * This is a somewhat hacky tool designed to do one very specific thing. 5 | * All of the test files in *_test.js are written with Closure-style 6 | * imports (goog.require()). This works great for running the tests 7 | * against Closure-style generated code, but we also want to run the 8 | * tests against CommonJS-style generated code without having to fork 9 | * the tests. 10 | * 11 | * Closure-style imports import each individual type by name. This is 12 | * very different than CommonJS imports which are by file. So we put 13 | * special comments in these tests like: 14 | * 15 | * // CommonJS-LoadFromFile: test_pb 16 | * goog.require('proto.jspb.test.CloneExtension'); 17 | * goog.require('proto.jspb.test.Complex'); 18 | * goog.require('proto.jspb.test.DefaultValues'); 19 | * 20 | * This script parses that special comment and uses it to generate proper 21 | * CommonJS require() statements so that the tests can run and pass using 22 | * CommonJS imports. The script will change the above statements into: 23 | * 24 | * var test_pb = require('test_pb'); 25 | * googleProtobuf.exportSymbol('proto.jspb.test.CloneExtension', test_pb.CloneExtension, global); 26 | * googleProtobuf.exportSymbol('proto.jspb.test.Complex', test_pb.Complex, global); 27 | * googleProtobuf.exportSymbol('proto.jspb.test.DefaultValues', test_pb.DefaultValues, global); 28 | * 29 | * (The "exportSymbol" function will define the given names in the global 30 | * namespace, taking care not to overwrite any previous value for 31 | * "proto.jspb.test"). 32 | */ 33 | 34 | var lineReader = require('readline').createInterface({ 35 | input: process.stdin, 36 | output: process.stdout 37 | }); 38 | 39 | function tryStripPrefix(str, prefix) { 40 | if (str.lastIndexOf(prefix) !== 0) { 41 | throw "String: " + str + " didn't start with: " + prefix; 42 | } 43 | return str.substr(prefix.length); 44 | } 45 | 46 | function camelCase(str) { 47 | var ret = ''; 48 | var ucaseNext = false; 49 | for (var i = 0; i < str.length; i++) { 50 | if (str[i] == '-') { 51 | ucaseNext = true; 52 | } else if (ucaseNext) { 53 | ret += str[i].toUpperCase(); 54 | ucaseNext = false; 55 | } else { 56 | ret += str[i]; 57 | } 58 | } 59 | return ret; 60 | } 61 | 62 | var module = null; 63 | var pkg = null; 64 | 65 | // Header: goes in every file at the top. 66 | console.log("var global = Function('return this')();"); 67 | console.log("var googleProtobuf = require('google-protobuf');"); 68 | console.log("var testdeps = require('testdeps_commonjs');"); 69 | console.log("global.COMPILED = testdeps.COMPILED;"); 70 | console.log("global.goog = testdeps.goog;"); 71 | console.log("global.jspb = googleProtobuf.jspb;"); 72 | console.log(""); 73 | 74 | lineReader.on('line', function(line) { 75 | var isRequire = line.match(/goog\.require\('([^']*)'\)/); 76 | var isLoadFromFile = line.match(/CommonJS-LoadFromFile: (\S*) (.*)/); 77 | var isSetTestOnly = line.match(/goog.setTestOnly()/); 78 | if (isRequire) { 79 | if (module) { // Skip goog.require() lines before the first directive. 80 | var fullSym = isRequire[1]; 81 | // Skip lines importing from jspb.*, these are handled by the header above. 82 | if (fullSym.match(/^jspb\./)) return; 83 | var sym = tryStripPrefix(fullSym, pkg); 84 | console.log("googleProtobuf.exportSymbol('" + fullSym + "', " + module + sym + ', global);'); 85 | } 86 | } else if (isLoadFromFile) { 87 | var module_path = isLoadFromFile[1].split('/'); 88 | module = camelCase(module_path[module_path.length - 1]); 89 | pkg = isLoadFromFile[2]; 90 | 91 | if (module != "googleProtobuf") { // We unconditionally require this in the header. 92 | console.log("var " + module + " = require('./" + isLoadFromFile[1] + "');"); 93 | } 94 | } else if (!isSetTestOnly) { // Remove goog.setTestOnly() lines. 95 | console.log(line); 96 | } 97 | }); 98 | -------------------------------------------------------------------------------- /commonjs/strict_test.js: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2016 Google Inc. All rights reserved. 3 | // https://protobuf.dev/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Test suite is written using Jasmine -- see http://jasmine.github.io/ 32 | 33 | 34 | 35 | const googleProtobuf = require('google-protobuf'); 36 | const global = Function('return this')(); 37 | 38 | const test9_pb = require('./protos/test9_pb'); 39 | const test10_pb = require('./protos/test10_pb'); 40 | 41 | describe('Strict test suite', () => { 42 | it('testImportedMessage', () => { 43 | const simple1 = new test9_pb.jspb.exttest.strict.nine.Simple9() 44 | const simple2 = new test9_pb.jspb.exttest.strict.nine.Simple9() 45 | expect(simple1.toObject()).toEqual(simple2.toObject()); 46 | }); 47 | 48 | it('testGlobalScopePollution', () => { 49 | expect(global.jspb.exttest).toBeUndefined(); 50 | }); 51 | 52 | describe('with imports', () => { 53 | it('testImportedMessage', () => { 54 | const simple1 = new test10_pb.jspb.exttest.strict.ten.Simple10() 55 | const simple2 = new test10_pb.jspb.exttest.strict.ten.Simple10() 56 | expect(simple1.toObject()).toEqual(simple2.toObject()); 57 | }); 58 | 59 | it('testGlobalScopePollution', () => { 60 | expect(global.jspb.exttest).toBeUndefined(); 61 | }); 62 | }); 63 | }); 64 | -------------------------------------------------------------------------------- /commonjs/test6/test6.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2016 Google Inc. All rights reserved. 3 | // https://protobuf.dev/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto3"; 32 | 33 | option java_package = "com.google.apps.jspb.proto"; 34 | option java_multiple_files = true; 35 | 36 | package jspb.test.importing; 37 | 38 | message ImportedMessage { 39 | string string_value = 1; 40 | } 41 | -------------------------------------------------------------------------------- /commonjs/test7/test7.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2016 Google Inc. All rights reserved. 3 | // https://protobuf.dev/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto3"; 32 | 33 | option java_package = "com.google.apps.jspb.proto"; 34 | option java_multiple_files = true; 35 | 36 | package jspb.test.framing; 37 | 38 | import "test6/test6.proto"; 39 | 40 | message FramingMessage { 41 | jspb.test.importing.ImportedMessage imported_message = 1; 42 | } 43 | -------------------------------------------------------------------------------- /compatibility_tests/v3.0.0/commonjs/export_asserts.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @fileoverview Exports symbols needed only by tests. 3 | * 4 | * This file exports several Closure Library symbols that are only 5 | * used by tests. It is used to generate a file 6 | * closure_asserts_commonjs.js that is only used at testing time. 7 | */ 8 | 9 | goog.require('goog.testing.asserts'); 10 | 11 | var global = Function('return this')(); 12 | 13 | // All of the closure "assert" functions are exported at the global level. 14 | // 15 | // The Google Closure assert functions start with assert, eg. 16 | // assertThrows 17 | // assertNotThrows 18 | // assertTrue 19 | // ... 20 | // 21 | // The one exception is the "fail" function. 22 | function shouldExport(str) { 23 | return str.lastIndexOf('assert') === 0 || str == 'fail'; 24 | } 25 | 26 | for (var key in global) { 27 | if ((typeof key == "string") && global.hasOwnProperty(key) && 28 | shouldExport(key)) { 29 | exports[key] = global[key]; 30 | } 31 | } 32 | 33 | // The COMPILED variable is set by Closure compiler to "true" when it compiles 34 | // JavaScript, so in practice this is equivalent to "exports.COMPILED = true". 35 | // This will disable some debugging functionality in debug.js. We could 36 | // investigate whether this can/should be enabled in CommonJS builds. 37 | exports.COMPILED = COMPILED 38 | -------------------------------------------------------------------------------- /compatibility_tests/v3.0.0/commonjs/export_testdeps.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @fileoverview Export symbols needed by tests in CommonJS style. 3 | * 4 | * This file is like export.js, but for symbols that are only used by tests. 5 | * However we exclude assert functions here, because they are exported into 6 | * the global namespace, so those are handled as a special case in 7 | * export_asserts.js. 8 | */ 9 | 10 | goog.require('goog.crypt.base64'); 11 | goog.require('jspb.arith.Int64'); 12 | goog.require('jspb.arith.UInt64'); 13 | goog.require('jspb.BinaryEncoder'); 14 | goog.require('jspb.BinaryDecoder'); 15 | goog.require('jspb.utils'); 16 | 17 | exports.goog = goog; 18 | exports.jspb = jspb; 19 | -------------------------------------------------------------------------------- /compatibility_tests/v3.0.0/commonjs/import_test.js: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2016 Google Inc. All rights reserved. 3 | // https://protobuf.dev/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Test suite is written using Jasmine -- see http://jasmine.github.io/ 32 | 33 | 34 | 35 | var googleProtobuf = require('google-protobuf'); 36 | var asserts = require('closure_asserts_commonjs'); 37 | var global = Function('return this')(); 38 | 39 | // Bring asserts into the global namespace. 40 | googleProtobuf.object.extend(global, asserts); 41 | googleProtobuf.exportSymbol('jspb.Message', googleProtobuf.Message, global); 42 | 43 | var test7_pb = require('./test7/test7_pb'); 44 | googleProtobuf.exportSymbol('proto.jspb.test.framing.FramingMessage', test7_pb.FramingMessage, global); 45 | 46 | describe('Import test suite', function() { 47 | it('testImportedMessage', function() { 48 | var framing1 = new proto.jspb.test.framing.FramingMessage([]); 49 | var framing2 = new proto.jspb.test.framing.FramingMessage([]); 50 | assertObjectEquals(framing1.toObject(), framing2.toObject()); 51 | }); 52 | }); 53 | -------------------------------------------------------------------------------- /compatibility_tests/v3.0.0/commonjs/jasmine.json: -------------------------------------------------------------------------------- 1 | { 2 | "spec_dir": "", 3 | "spec_files": [ 4 | "*_test.js", 5 | "binary/proto_test.js" 6 | ], 7 | "helpers": [ 8 | ] 9 | } 10 | -------------------------------------------------------------------------------- /compatibility_tests/v3.0.0/commonjs/rewrite_tests_for_commonjs.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @fileoverview Utility to translate test files to CommonJS imports. 3 | * 4 | * This is a somewhat hacky tool designed to do one very specific thing. 5 | * All of the test files in *_test.js are written with Closure-style 6 | * imports (goog.require()). This works great for running the tests 7 | * against Closure-style generated code, but we also want to run the 8 | * tests against CommonJS-style generated code without having to fork 9 | * the tests. 10 | * 11 | * Closure-style imports import each individual type by name. This is 12 | * very different than CommonJS imports which are by file. So we put 13 | * special comments in these tests like: 14 | * 15 | * // CommonJS-LoadFromFile: test_pb 16 | * goog.require('proto.jspb.test.CloneExtension'); 17 | * goog.require('proto.jspb.test.Complex'); 18 | * goog.require('proto.jspb.test.DefaultValues'); 19 | * 20 | * This script parses that special comment and uses it to generate proper 21 | * CommonJS require() statements so that the tests can run and pass using 22 | * CommonJS imports. The script will change the above statements into: 23 | * 24 | * var test_pb = require('test_pb'); 25 | * googleProtobuf.exportSymbol('proto.jspb.test.CloneExtension', test_pb.CloneExtension, global); 26 | * googleProtobuf.exportSymbol('proto.jspb.test.Complex', test_pb.Complex, global); 27 | * googleProtobuf.exportSymbol('proto.jspb.test.DefaultValues', test_pb.DefaultValues, global); 28 | * 29 | * (The "exportSymbol" function will define the given names in the global 30 | * namespace, taking care not to overwrite any previous value for 31 | * "proto.jspb.test"). 32 | */ 33 | 34 | var lineReader = require('readline').createInterface({ 35 | input: process.stdin, 36 | output: process.stdout 37 | }); 38 | 39 | function tryStripPrefix(str, prefix) { 40 | if (str.lastIndexOf(prefix) !== 0) { 41 | throw "String: " + str + " didn't start with: " + prefix; 42 | } 43 | return str.substr(prefix.length); 44 | } 45 | 46 | function camelCase(str) { 47 | var ret = ''; 48 | var ucaseNext = false; 49 | for (var i = 0; i < str.length; i++) { 50 | if (str[i] == '-') { 51 | ucaseNext = true; 52 | } else if (ucaseNext) { 53 | ret += str[i].toUpperCase(); 54 | ucaseNext = false; 55 | } else { 56 | ret += str[i]; 57 | } 58 | } 59 | return ret; 60 | } 61 | 62 | var module = null; 63 | var pkg = null; 64 | 65 | // Header: goes in every file at the top. 66 | console.log("var global = Function('return this')();"); 67 | console.log("var googleProtobuf = require('google-protobuf');"); 68 | console.log("var testdeps = require('testdeps_commonjs');"); 69 | console.log("global.goog = testdeps.goog;"); 70 | console.log("global.jspb = testdeps.jspb;"); 71 | console.log("var asserts = require('closure_asserts_commonjs');"); 72 | console.log(""); 73 | console.log("// Bring asserts into the global namespace."); 74 | console.log("googleProtobuf.object.extend(global, asserts);"); 75 | 76 | lineReader.on('line', function(line) { 77 | var isRequire = line.match(/goog\.require\('([^']*)'\)/); 78 | var isLoadFromFile = line.match(/CommonJS-LoadFromFile: (\S*) (.*)/); 79 | var isSetTestOnly = line.match(/goog.setTestOnly()/); 80 | if (isRequire) { 81 | if (module) { // Skip goog.require() lines before the first directive. 82 | var fullSym = isRequire[1]; 83 | var sym = tryStripPrefix(fullSym, pkg); 84 | console.log("googleProtobuf.exportSymbol('" + fullSym + "', " + module + sym + ', global);'); 85 | } 86 | } else if (isLoadFromFile) { 87 | var module_path = isLoadFromFile[1].split('/'); 88 | module = camelCase(module_path[module_path.length - 1]); 89 | pkg = isLoadFromFile[2]; 90 | 91 | if (module != "googleProtobuf") { // We unconditionally require this in the header. 92 | console.log("var " + module + " = require('./" + isLoadFromFile[1] + "');"); 93 | } 94 | } else if (!isSetTestOnly) { // Remove goog.setTestOnly() lines. 95 | console.log(line); 96 | } 97 | }); 98 | -------------------------------------------------------------------------------- /compatibility_tests/v3.0.0/commonjs/test6/test6.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2016 Google Inc. All rights reserved. 3 | // https://protobuf.dev/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto3"; 32 | 33 | option java_package = "com.google.apps.jspb.proto"; 34 | option java_multiple_files = true; 35 | 36 | package jspb.test.importing; 37 | 38 | message ImportedMessage { 39 | string string_value = 1; 40 | } 41 | -------------------------------------------------------------------------------- /compatibility_tests/v3.0.0/commonjs/test7/test7.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2016 Google Inc. All rights reserved. 3 | // https://protobuf.dev/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto3"; 32 | 33 | option java_package = "com.google.apps.jspb.proto"; 34 | option java_multiple_files = true; 35 | 36 | package jspb.test.framing; 37 | 38 | import "test6/test6.proto"; 39 | 40 | message FramingMessage { 41 | jspb.test.importing.ImportedMessage imported_message = 1; 42 | } 43 | -------------------------------------------------------------------------------- /compatibility_tests/v3.0.0/data.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://protobuf.dev/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Author: mwr@google.com (Mark Rawling) 32 | 33 | syntax = "proto2"; 34 | 35 | option java_package = "com.google.apps.jspb.proto"; 36 | option java_multiple_files = true; 37 | 38 | package jspb.test; 39 | 40 | // legacy data, must be nested 41 | message data { 42 | message NestedData { 43 | required string str = 1; 44 | } 45 | } 46 | 47 | // new data, does not require nesting 48 | message UnnestedData { 49 | required string str = 1; 50 | } 51 | 52 | -------------------------------------------------------------------------------- /compatibility_tests/v3.0.0/debug_test.js: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://protobuf.dev/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | goog.setTestOnly(); 32 | 33 | goog.require('goog.testing.asserts'); 34 | 35 | // CommonJS-LoadFromFile: google-protobuf 36 | goog.require('jspb.debug'); 37 | 38 | // CommonJS-LoadFromFile: test_pb 39 | goog.require('proto.jspb.test.HasExtensions'); 40 | goog.require('proto.jspb.test.IsExtension'); 41 | goog.require('proto.jspb.test.Simple1'); 42 | 43 | 44 | 45 | describe('debugTest', function() { 46 | it('testSimple1', function() { 47 | if (COMPILED) { 48 | return; 49 | } 50 | var message = new proto.jspb.test.Simple1(); 51 | message.setAString('foo'); 52 | assertObjectEquals({ 53 | $name: 'proto.jspb.test.Simple1', 54 | 'aString': 'foo', 55 | 'aRepeatedStringList': [] 56 | }, jspb.debug.dump(message)); 57 | 58 | message.setABoolean(true); 59 | message.setARepeatedStringList(['1', '2']); 60 | 61 | assertObjectEquals({ 62 | $name: 'proto.jspb.test.Simple1', 63 | 'aString': 'foo', 64 | 'aRepeatedStringList': ['1', '2'], 65 | 'aBoolean': true 66 | }, jspb.debug.dump(message)); 67 | 68 | message.setAString(undefined); 69 | 70 | assertObjectEquals({ 71 | $name: 'proto.jspb.test.Simple1', 72 | 'aRepeatedStringList': ['1', '2'], 73 | 'aBoolean': true 74 | }, jspb.debug.dump(message)); 75 | }); 76 | 77 | 78 | it('testExtensions', function() { 79 | if (COMPILED) { 80 | return; 81 | } 82 | var extension = new proto.jspb.test.IsExtension(); 83 | extension.setExt1('ext1field'); 84 | var extendable = new proto.jspb.test.HasExtensions(); 85 | extendable.setStr1('v1'); 86 | extendable.setStr2('v2'); 87 | extendable.setStr3('v3'); 88 | extendable.setExtension(proto.jspb.test.IsExtension.extField, extension); 89 | 90 | assertObjectEquals({ 91 | '$name': 'proto.jspb.test.HasExtensions', 92 | 'str1': 'v1', 93 | 'str2': 'v2', 94 | 'str3': 'v3', 95 | '$extensions': { 96 | 'extField': { 97 | '$name': 'proto.jspb.test.IsExtension', 98 | 'ext1': 'ext1field' 99 | }, 100 | 'repeatedSimpleList': [] 101 | } 102 | }, jspb.debug.dump(extendable)); 103 | }); 104 | 105 | }); 106 | -------------------------------------------------------------------------------- /compatibility_tests/v3.0.0/jasmine1.json: -------------------------------------------------------------------------------- 1 | { 2 | "spec_dir": "", 3 | "spec_files": [ 4 | "*_test.js", 5 | "binary/*_test.js" 6 | ], 7 | "helpers": [ 8 | "../../../js/node_modules/google-closure-library/closure/goog/bootstrap/nodejs.js", 9 | "../../../js/node_loader.js", 10 | "../../../js/deps.js", 11 | "../../../js/google/protobuf/any.js", 12 | "../../../js/google/protobuf/struct.js", 13 | "../../../js/google/protobuf/timestamp.js", 14 | "testproto_libs1.js", 15 | "testproto_libs2.js" 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /compatibility_tests/v3.0.0/jasmine2.json: -------------------------------------------------------------------------------- 1 | { 2 | "spec_dir": "", 3 | "spec_files": [ 4 | "*_test.js", 5 | "binary/*_test.js" 6 | ], 7 | "helpers": [ 8 | "../../../js/node_modules/google-closure-library/closure/goog/bootstrap/nodejs.js", 9 | "../../../js/node_loader.js", 10 | "../../../js/deps.js", 11 | "../../../js/google/protobuf/any.js", 12 | "../../../js/google/protobuf/struct.js", 13 | "../../../js/google/protobuf/timestamp.js", 14 | "testproto_libs1_new.js", 15 | "testproto_libs2.js" 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /compatibility_tests/v3.0.0/jasmine3.json: -------------------------------------------------------------------------------- 1 | { 2 | "spec_dir": "", 3 | "spec_files": [ 4 | "*_test.js", 5 | "binary/*_test.js" 6 | ], 7 | "helpers": [ 8 | "../../../js/node_modules/google-closure-library/closure/goog/bootstrap/nodejs.js", 9 | "../../../js/node_loader.js", 10 | "../../../js/deps.js", 11 | "../../../js/google/protobuf/any.js", 12 | "../../../js/google/protobuf/struct.js", 13 | "../../../js/google/protobuf/timestamp.js", 14 | "testproto_libs1.js", 15 | "testproto_libs2_new.js" 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /compatibility_tests/v3.0.0/proto3_test.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://protobuf.dev/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto3"; 32 | 33 | import "testbinary.proto"; 34 | 35 | package jspb.test; 36 | 37 | message TestProto3 { 38 | int32 optional_int32 = 1; 39 | int64 optional_int64 = 2; 40 | uint32 optional_uint32 = 3; 41 | uint64 optional_uint64 = 4; 42 | sint32 optional_sint32 = 5; 43 | sint64 optional_sint64 = 6; 44 | fixed32 optional_fixed32 = 7; 45 | fixed64 optional_fixed64 = 8; 46 | sfixed32 optional_sfixed32 = 9; 47 | sfixed64 optional_sfixed64 = 10; 48 | float optional_float = 11; 49 | double optional_double = 12; 50 | bool optional_bool = 13; 51 | string optional_string = 14; 52 | bytes optional_bytes = 15; 53 | 54 | ForeignMessage optional_foreign_message = 19; 55 | Proto3Enum optional_foreign_enum = 22; 56 | 57 | repeated int32 repeated_int32 = 31; 58 | repeated int64 repeated_int64 = 32; 59 | repeated uint32 repeated_uint32 = 33; 60 | repeated uint64 repeated_uint64 = 34; 61 | repeated sint32 repeated_sint32 = 35; 62 | repeated sint64 repeated_sint64 = 36; 63 | repeated fixed32 repeated_fixed32 = 37; 64 | repeated fixed64 repeated_fixed64 = 38; 65 | repeated sfixed32 repeated_sfixed32 = 39; 66 | repeated sfixed64 repeated_sfixed64 = 40; 67 | repeated float repeated_float = 41; 68 | repeated double repeated_double = 42; 69 | repeated bool repeated_bool = 43; 70 | repeated string repeated_string = 44; 71 | repeated bytes repeated_bytes = 45; 72 | 73 | repeated ForeignMessage repeated_foreign_message = 49; 74 | repeated Proto3Enum repeated_foreign_enum = 52; 75 | 76 | 77 | oneof oneof_field { 78 | uint32 oneof_uint32 = 111; 79 | ForeignMessage oneof_foreign_message = 112; 80 | string oneof_string = 113; 81 | bytes oneof_bytes = 114; 82 | } 83 | } 84 | 85 | enum Proto3Enum { 86 | PROTO3_FOO = 0; 87 | PROTO3_BAR = 1; 88 | PROTO3_BAZ = 2; 89 | } 90 | -------------------------------------------------------------------------------- /compatibility_tests/v3.0.0/test2.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://protobuf.dev/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto2"; 32 | 33 | option java_package = "com.google.apps.jspb.proto"; 34 | option java_multiple_files = true; 35 | 36 | package jspb.test; 37 | 38 | message TestExtensionsMessage { 39 | optional int32 intfield = 1; 40 | extensions 100 to max; 41 | } 42 | 43 | message ExtensionMessage { 44 | extend TestExtensionsMessage { 45 | optional ExtensionMessage ext_field = 100; 46 | } 47 | optional string ext1 = 1; 48 | } 49 | 50 | // Floating extensions are only supported when generating a _lib.js library. 51 | extend TestExtensionsMessage { 52 | optional ExtensionMessage floating_msg_field = 101; 53 | optional string floating_str_field = 102; 54 | } 55 | -------------------------------------------------------------------------------- /compatibility_tests/v3.0.0/test3.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://protobuf.dev/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto2"; 32 | 33 | option java_package = "com.google.apps.jspb.proto"; 34 | option java_multiple_files = true; 35 | 36 | package jspb.exttest; 37 | 38 | message TestExtensionsMessage { 39 | optional int32 intfield = 1; 40 | extensions 100 to max; 41 | } 42 | 43 | message ExtensionMessage { 44 | extend TestExtensionsMessage { 45 | optional ExtensionMessage ext_field = 100; 46 | } 47 | optional string ext1 = 1; 48 | } 49 | 50 | extend TestExtensionsMessage { 51 | optional ExtensionMessage floating_msg_field = 101; 52 | optional string floating_str_field = 102; 53 | } 54 | -------------------------------------------------------------------------------- /compatibility_tests/v3.0.0/test4.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://protobuf.dev/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto2"; 32 | 33 | option java_package = "com.google.apps.jspb.proto"; 34 | option java_multiple_files = true; 35 | 36 | package jspb.exttest; 37 | 38 | import "test3.proto"; 39 | 40 | extend TestExtensionsMessage { 41 | optional ExtensionMessage floating_msg_field_two = 103; 42 | } 43 | -------------------------------------------------------------------------------- /compatibility_tests/v3.0.0/test5.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://protobuf.dev/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto2"; 32 | 33 | option java_package = "com.google.apps.jspb.proto"; 34 | option java_multiple_files = true; 35 | 36 | package jspb.exttest.beta; 37 | 38 | message TestBetaExtensionsMessage { 39 | extensions 100 to max; 40 | } 41 | 42 | extend TestBetaExtensionsMessage { 43 | optional string floating_str_field = 101; 44 | } 45 | -------------------------------------------------------------------------------- /compatibility_tests/v3.0.0/testempty.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://protobuf.dev/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto2"; 32 | 33 | package javatests.com.google.apps.jspb; 34 | 35 | -------------------------------------------------------------------------------- /compatibility_tests/v3.1.0/commonjs/test6/test6.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2016 Google Inc. All rights reserved. 3 | // https://protobuf.dev/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto3"; 32 | 33 | option java_package = "com.google.apps.jspb.proto"; 34 | option java_multiple_files = true; 35 | 36 | package jspb.test.importing; 37 | 38 | message ImportedMessage { 39 | string string_value = 1; 40 | } 41 | -------------------------------------------------------------------------------- /compatibility_tests/v3.1.0/commonjs/test7/test7.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2016 Google Inc. All rights reserved. 3 | // https://protobuf.dev/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto3"; 32 | 33 | option java_package = "com.google.apps.jspb.proto"; 34 | option java_multiple_files = true; 35 | 36 | package jspb.test.framing; 37 | 38 | import "test6/test6.proto"; 39 | 40 | message FramingMessage { 41 | jspb.test.importing.ImportedMessage imported_message = 1; 42 | } 43 | -------------------------------------------------------------------------------- /compatibility_tests/v3.1.0/data.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://protobuf.dev/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Author: mwr@google.com (Mark Rawling) 32 | 33 | syntax = "proto2"; 34 | 35 | option java_package = "com.google.apps.jspb.proto"; 36 | option java_multiple_files = true; 37 | 38 | package jspb.test; 39 | 40 | // legacy data, must be nested 41 | message data { 42 | message NestedData { 43 | required string str = 1; 44 | } 45 | } 46 | 47 | // new data, does not require nesting 48 | message UnnestedData { 49 | required string str = 1; 50 | } 51 | 52 | -------------------------------------------------------------------------------- /compatibility_tests/v3.1.0/debug_test.js: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://protobuf.dev/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | goog.setTestOnly(); 32 | 33 | goog.require('goog.testing.asserts'); 34 | 35 | // CommonJS-LoadFromFile: google-protobuf 36 | goog.require('jspb.debug'); 37 | 38 | // CommonJS-LoadFromFile: test_pb 39 | goog.require('proto.jspb.test.HasExtensions'); 40 | goog.require('proto.jspb.test.IsExtension'); 41 | goog.require('proto.jspb.test.Simple1'); 42 | 43 | 44 | 45 | describe('debugTest', function() { 46 | it('testSimple1', function() { 47 | if (COMPILED) { 48 | return; 49 | } 50 | var message = new proto.jspb.test.Simple1(); 51 | message.setAString('foo'); 52 | assertObjectEquals({ 53 | $name: 'proto.jspb.test.Simple1', 54 | 'aString': 'foo', 55 | 'aRepeatedStringList': [] 56 | }, jspb.debug.dump(message)); 57 | 58 | message.setABoolean(true); 59 | message.setARepeatedStringList(['1', '2']); 60 | 61 | assertObjectEquals({ 62 | $name: 'proto.jspb.test.Simple1', 63 | 'aString': 'foo', 64 | 'aRepeatedStringList': ['1', '2'], 65 | 'aBoolean': true 66 | }, jspb.debug.dump(message)); 67 | 68 | message.clearAString(); 69 | 70 | assertObjectEquals({ 71 | $name: 'proto.jspb.test.Simple1', 72 | 'aRepeatedStringList': ['1', '2'], 73 | 'aBoolean': true 74 | }, jspb.debug.dump(message)); 75 | }); 76 | 77 | 78 | it('testExtensions', function() { 79 | if (COMPILED) { 80 | return; 81 | } 82 | var extension = new proto.jspb.test.IsExtension(); 83 | extension.setExt1('ext1field'); 84 | var extendable = new proto.jspb.test.HasExtensions(); 85 | extendable.setStr1('v1'); 86 | extendable.setStr2('v2'); 87 | extendable.setStr3('v3'); 88 | extendable.setExtension(proto.jspb.test.IsExtension.extField, extension); 89 | 90 | assertObjectEquals({ 91 | '$name': 'proto.jspb.test.HasExtensions', 92 | 'str1': 'v1', 93 | 'str2': 'v2', 94 | 'str3': 'v3', 95 | '$extensions': { 96 | 'extField': { 97 | '$name': 'proto.jspb.test.IsExtension', 98 | 'ext1': 'ext1field' 99 | }, 100 | 'repeatedSimpleList': [] 101 | } 102 | }, jspb.debug.dump(extendable)); 103 | }); 104 | 105 | }); 106 | -------------------------------------------------------------------------------- /compatibility_tests/v3.1.0/proto3_test.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://protobuf.dev/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto3"; 32 | 33 | import "testbinary.proto"; 34 | 35 | package jspb.test; 36 | 37 | message TestProto3 { 38 | int32 optional_int32 = 1; 39 | int64 optional_int64 = 2; 40 | uint32 optional_uint32 = 3; 41 | uint64 optional_uint64 = 4; 42 | sint32 optional_sint32 = 5; 43 | sint64 optional_sint64 = 6; 44 | fixed32 optional_fixed32 = 7; 45 | fixed64 optional_fixed64 = 8; 46 | sfixed32 optional_sfixed32 = 9; 47 | sfixed64 optional_sfixed64 = 10; 48 | float optional_float = 11; 49 | double optional_double = 12; 50 | bool optional_bool = 13; 51 | string optional_string = 14; 52 | bytes optional_bytes = 15; 53 | 54 | ForeignMessage optional_foreign_message = 19; 55 | Proto3Enum optional_foreign_enum = 22; 56 | 57 | repeated int32 repeated_int32 = 31; 58 | repeated int64 repeated_int64 = 32; 59 | repeated uint32 repeated_uint32 = 33; 60 | repeated uint64 repeated_uint64 = 34; 61 | repeated sint32 repeated_sint32 = 35; 62 | repeated sint64 repeated_sint64 = 36; 63 | repeated fixed32 repeated_fixed32 = 37; 64 | repeated fixed64 repeated_fixed64 = 38; 65 | repeated sfixed32 repeated_sfixed32 = 39; 66 | repeated sfixed64 repeated_sfixed64 = 40; 67 | repeated float repeated_float = 41; 68 | repeated double repeated_double = 42; 69 | repeated bool repeated_bool = 43; 70 | repeated string repeated_string = 44; 71 | repeated bytes repeated_bytes = 45; 72 | 73 | repeated ForeignMessage repeated_foreign_message = 49; 74 | repeated Proto3Enum repeated_foreign_enum = 52; 75 | 76 | 77 | oneof oneof_field { 78 | uint32 oneof_uint32 = 111; 79 | ForeignMessage oneof_foreign_message = 112; 80 | string oneof_string = 113; 81 | bytes oneof_bytes = 114; 82 | } 83 | } 84 | 85 | enum Proto3Enum { 86 | PROTO3_FOO = 0; 87 | PROTO3_BAR = 1; 88 | PROTO3_BAZ = 2; 89 | } 90 | -------------------------------------------------------------------------------- /compatibility_tests/v3.1.0/test2.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://protobuf.dev/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto2"; 32 | 33 | option java_package = "com.google.apps.jspb.proto"; 34 | option java_multiple_files = true; 35 | 36 | package jspb.test; 37 | 38 | message TestExtensionsMessage { 39 | optional int32 intfield = 1; 40 | extensions 100 to max; 41 | } 42 | 43 | message ExtensionMessage { 44 | extend TestExtensionsMessage { 45 | optional ExtensionMessage ext_field = 100; 46 | } 47 | optional string ext1 = 1; 48 | } 49 | 50 | // Floating extensions are only supported when generating a _lib.js library. 51 | extend TestExtensionsMessage { 52 | optional ExtensionMessage floating_msg_field = 101; 53 | optional string floating_str_field = 102; 54 | } 55 | -------------------------------------------------------------------------------- /compatibility_tests/v3.1.0/test3.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://protobuf.dev/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto2"; 32 | 33 | option java_package = "com.google.apps.jspb.proto"; 34 | option java_multiple_files = true; 35 | 36 | package jspb.exttest; 37 | 38 | message TestExtensionsMessage { 39 | optional int32 intfield = 1; 40 | extensions 100 to max; 41 | } 42 | 43 | message ExtensionMessage { 44 | extend TestExtensionsMessage { 45 | optional ExtensionMessage ext_field = 100; 46 | } 47 | optional string ext1 = 1; 48 | } 49 | 50 | extend TestExtensionsMessage { 51 | optional ExtensionMessage floating_msg_field = 101; 52 | optional string floating_str_field = 102; 53 | } 54 | -------------------------------------------------------------------------------- /compatibility_tests/v3.1.0/test4.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://protobuf.dev/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto2"; 32 | 33 | option java_package = "com.google.apps.jspb.proto"; 34 | option java_multiple_files = true; 35 | 36 | package jspb.exttest; 37 | 38 | import "test3.proto"; 39 | 40 | extend TestExtensionsMessage { 41 | optional ExtensionMessage floating_msg_field_two = 103; 42 | } 43 | -------------------------------------------------------------------------------- /compatibility_tests/v3.1.0/test5.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://protobuf.dev/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto2"; 32 | 33 | option java_package = "com.google.apps.jspb.proto"; 34 | option java_multiple_files = true; 35 | 36 | package jspb.exttest.beta; 37 | 38 | message TestBetaExtensionsMessage { 39 | extensions 100 to max; 40 | } 41 | 42 | extend TestBetaExtensionsMessage { 43 | optional string floating_str_field = 101; 44 | } 45 | -------------------------------------------------------------------------------- /compatibility_tests/v3.1.0/testempty.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://protobuf.dev/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto2"; 32 | 33 | package javatests.com.google.apps.jspb; 34 | 35 | -------------------------------------------------------------------------------- /experimental/benchmarks/code_size/apps_jspb/popular_types_proto2.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @fileoverview The code size benchmark of apps JSPB for proto2 popular types. 3 | */ 4 | goog.module('protobuf.benchmark.code_size.apps_jspb.PopularTypesProto2'); 5 | 6 | // const ForeignEnum = goog.require('proto.proto2_unittest.ForeignEnum'); 7 | const ForeignMessage = goog.require('proto.proto2_unittest.ForeignMessage'); 8 | const TestAllTypes = goog.require('proto.proto2_unittest.TestAllTypes'); 9 | const {ensureCommonBaseLine} = goog.require('protobuf.benchmark.codeSize.codeSizeBase'); 10 | 11 | ensureCommonBaseLine(); 12 | 13 | /** 14 | * @return {string} 15 | */ 16 | function accessPopularTypes() { 17 | const msgAllTypes = TestAllTypes.deserialize(''); 18 | msgAllTypes.addRepeatedForeignMessage(ForeignMessage.deserialize(''), 1); 19 | [ForeignMessage.deserialize('')].forEach( 20 | (e) => msgAllTypes.addRepeatedForeignMessage(e)); 21 | 22 | msgAllTypes.setOptionalString(''); 23 | msgAllTypes.setOptionalInt32(1); 24 | msgAllTypes.setOptionalForeignMessage(ForeignMessage.deserialize('')); 25 | msgAllTypes.setOptionalBool(true); 26 | // msgAllTypes.setOptionalForeignEnum(ForeignEnum.FOREIGN_BAR); 27 | msgAllTypes.setOptionalInt64(1); 28 | msgAllTypes.setOptionalDouble(1.0); 29 | msgAllTypes.setRepeatedForeignMessageList([ForeignMessage.deserialize('')]); 30 | let arrayVal = msgAllTypes.getRepeatedForeignMessageList(); 31 | arrayVal[0] = ForeignMessage.deserialize(''); 32 | msgAllTypes.setRepeatedForeignMessageList(arrayVal); 33 | msgAllTypes.setOptionalUint64(1); 34 | 35 | let s = ''; 36 | s += msgAllTypes.getOptionalString(); 37 | s += msgAllTypes.getOptionalInt32(); 38 | s += msgAllTypes.getOptionalForeignMessage(); 39 | s += msgAllTypes.getOptionalBool(); 40 | // s += msgAllTypes.getOptionalForeignEnum(); 41 | s += msgAllTypes.getOptionalInt64(); 42 | s += msgAllTypes.getOptionalDouble(); 43 | s += msgAllTypes.getRepeatedForeignMessageList(); 44 | s += msgAllTypes.getRepeatedForeignMessageList()[0]; 45 | s += msgAllTypes.getRepeatedForeignMessageList().length; 46 | s += msgAllTypes.getOptionalUint64(); 47 | 48 | s += msgAllTypes.serialize(); 49 | 50 | return s; 51 | } 52 | 53 | goog.global['__hiddenTest'] += accessPopularTypes(); 54 | -------------------------------------------------------------------------------- /experimental/benchmarks/code_size/apps_jspb/popular_types_proto3.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @fileoverview The code size benchmark of apps JSPB for proto3 popular types. 3 | */ 4 | goog.module('protobuf.benchmark.code_size.apps_jspb.PopularTypesProto3'); 5 | 6 | // const ForeignEnum = goog.require('proto.proto3_unittest.ForeignEnum'); 7 | const ForeignMessage = goog.require('proto.proto3_unittest.ForeignMessage'); 8 | const TestAllTypes = goog.require('proto.proto3_unittest.TestAllTypes'); 9 | const {ensureCommonBaseLine} = goog.require('protobuf.benchmark.codeSize.codeSizeBase'); 10 | 11 | ensureCommonBaseLine(); 12 | 13 | /** 14 | * @return {string} 15 | */ 16 | function accessPopularTypes() { 17 | const msgAllTypes = TestAllTypes.deserialize(''); 18 | msgAllTypes.addRepeatedForeignMessage(ForeignMessage.deserialize(''), 1); 19 | [ForeignMessage.deserialize('')].forEach( 20 | (e) => msgAllTypes.addRepeatedForeignMessage(e)); 21 | 22 | msgAllTypes.setOptionalString(''); 23 | msgAllTypes.setOptionalInt32(1); 24 | msgAllTypes.setOptionalForeignMessage(ForeignMessage.deserialize('')); 25 | msgAllTypes.setOptionalBool(true); 26 | // msgAllTypes.setOptionalForeignEnum(ForeignEnum.FOREIGN_BAR); 27 | msgAllTypes.setOptionalInt64(1); 28 | msgAllTypes.setOptionalDouble(1.0); 29 | msgAllTypes.setRepeatedForeignMessageList([ForeignMessage.deserialize('')]); 30 | let arrayVal = msgAllTypes.getRepeatedForeignMessageList(); 31 | arrayVal[0] = ForeignMessage.deserialize(''); 32 | msgAllTypes.setRepeatedForeignMessageList(arrayVal); 33 | msgAllTypes.setOptionalUint64(1); 34 | 35 | let s = ''; 36 | s += msgAllTypes.getOptionalString(); 37 | s += msgAllTypes.getOptionalInt32(); 38 | s += msgAllTypes.getOptionalForeignMessage(); 39 | s += msgAllTypes.getOptionalBool(); 40 | // s += msgAllTypes.getOptionalForeignEnum(); 41 | s += msgAllTypes.getOptionalInt64(); 42 | s += msgAllTypes.getOptionalDouble(); 43 | s += msgAllTypes.getRepeatedForeignMessageList(); 44 | s += msgAllTypes.getRepeatedForeignMessageList()[0]; 45 | s += msgAllTypes.getRepeatedForeignMessageList().length; 46 | s += msgAllTypes.getOptionalUint64(); 47 | 48 | s += msgAllTypes.serialize(); 49 | 50 | return s; 51 | } 52 | 53 | goog.global['__hiddenTest'] += accessPopularTypes(); 54 | -------------------------------------------------------------------------------- /experimental/benchmarks/code_size/code_size_base.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @fileoverview Ensures types are live that would be live in a typical g3 3 | * JS program. 4 | * 5 | * Making certain constructs live ensures that we compare against the same 6 | * baseline for all code size benchmarks. This increases the size 7 | * of our benchmarks, but note that this size in a regular app would be 8 | * attributes to other places. 9 | */ 10 | goog.module('protobuf.benchmark.codeSize.codeSizeBase'); 11 | 12 | 13 | /** 14 | * Ensures that the array iterator polyfill is live. 15 | * @return {string} 16 | */ 17 | function useArrayIterator() { 18 | let a = []; 19 | let s = ''; 20 | for (let value of a) { 21 | s += value; 22 | } 23 | return s; 24 | } 25 | 26 | /** 27 | * Ensures that the symbol iterator polyfill is live. 28 | * @return {string} 29 | */ 30 | function useSymbolIterator() { 31 | /** 32 | * @implements {Iterable} 33 | */ 34 | class Foo { 35 | /** @return {!Iterator} */ 36 | [Symbol.iterator]() {} 37 | } 38 | 39 | let foo = new Foo(); 40 | let s = ''; 41 | for (let value of foo) { 42 | s += value; 43 | } 44 | return s; 45 | } 46 | 47 | /** 48 | * Ensures certain base libs are live so we can have an apples to apples 49 | * comparison for code size of different implementations 50 | */ 51 | function ensureCommonBaseLine() { 52 | goog.global['__hiddenTest'] += useArrayIterator(); 53 | goog.global['__hiddenTest'] += useSymbolIterator(); 54 | } 55 | 56 | 57 | exports = {ensureCommonBaseLine}; 58 | -------------------------------------------------------------------------------- /experimental/benchmarks/code_size/kernel/popular_types.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @fileoverview The code size benchmark of binary kernel for accessing all 3 | * popular types setter and getter. 4 | * 5 | * The types are those whose usage are more than 1%: 6 | * 7 | * ('STRING__LABEL_OPTIONAL', '29.7214%') 8 | * ('INT32__LABEL_OPTIONAL', '17.7277%') 9 | * ('MESSAGE__LABEL_OPTIONAL', '15.6462%') 10 | * ('BOOL__LABEL_OPTIONAL', '13.0038%') 11 | * ('ENUM__LABEL_OPTIONAL', '11.4466%') 12 | * ('INT64__LABEL_OPTIONAL', '3.2198%') 13 | * ('DOUBLE__LABEL_OPTIONAL', '1.357%') 14 | * ('MESSAGE__LABEL_REPEATED', '1.2775%') 15 | * ('FIXED32__LABEL_REQUIRED', '1.2%') 16 | * ('UINT64__LABEL_OPTIONAL', '1.1771%') 17 | * ('STRING__LABEL_REQUIRED', '1.0785%') 18 | * 19 | */ 20 | goog.module('protobuf.benchmark.KernelCodeSizeBenchmarkPopularTypes'); 21 | 22 | const Int64 = goog.require('protobuf.Int64'); 23 | const Kernel = goog.require('protobuf.runtime.Kernel'); 24 | const TestMessage = goog.require('protobuf.testing.binary.TestMessage'); 25 | const {ensureCommonBaseLine} = goog.require('protobuf.benchmark.codeSize.codeSizeBase'); 26 | 27 | ensureCommonBaseLine(); 28 | 29 | 30 | /** 31 | * @return {string} 32 | */ 33 | function accessAllTypes() { 34 | const message = new TestMessage(Kernel.createEmpty()); 35 | 36 | message.addRepeatedMessageElement(1, message, TestMessage.instanceCreator); 37 | message.addRepeatedMessageIterable(1, [message], TestMessage.instanceCreator); 38 | 39 | message.setString(1, 'abc'); 40 | message.setInt32(1, 1); 41 | message.setMessage(1, message); 42 | message.setBool(1, true); 43 | message.setInt64(1, Int64.fromBits(0, 1)); 44 | message.setDouble(1, 1.0); 45 | message.setRepeatedMessageElement(1, message, TestMessage.instanceCreator, 0); 46 | message.setRepeatedMessageIterable(1, [message]); 47 | message.setUint64(1, Int64.fromBits(0, 1)); 48 | 49 | 50 | let s = ''; 51 | s += message.getStringWithDefault(1); 52 | s += message.getInt32WithDefault(1); 53 | s += message.getMessage(1, TestMessage.instanceCreator); 54 | s += message.getMessageOrNull(1, TestMessage.instanceCreator); 55 | s += message.getBoolWithDefault(1); 56 | s += message.getInt64WithDefault(1); 57 | s += message.getDoubleWithDefault(1); 58 | s += message.getRepeatedMessageElement(1, TestMessage.instanceCreator, 0); 59 | s += message.getRepeatedMessageIterable(1, TestMessage.instanceCreator); 60 | s += message.getRepeatedMessageSize(1, TestMessage.instanceCreator); 61 | s += message.getUint64WithDefault(1); 62 | 63 | s += message.serialize(); 64 | 65 | return s; 66 | } 67 | 68 | goog.global['__hiddenTest'] += accessAllTypes(); 69 | -------------------------------------------------------------------------------- /experimental/runtime/bytestring_internal.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @fileoverview Exposes internal only functions for ByteString. The 3 | * corresponding BUILD rule restricts access to this file to only the binary 4 | * kernel and APIs directly using the binary kernel. 5 | */ 6 | goog.module('protobuf.byteStringInternal'); 7 | 8 | const ByteString = goog.require('protobuf.ByteString'); 9 | 10 | /** 11 | * Constructs a ByteString from an Uint8Array. DON'T MODIFY the underlying 12 | * ArrayBuffer, since the ByteString directly uses it without making a copy. 13 | * @param {!Uint8Array} bytes 14 | * @return {!ByteString} 15 | */ 16 | function byteStringFromUint8ArrayUnsafe(bytes) { 17 | return ByteString.fromUint8ArrayUnsafe(bytes); 18 | } 19 | 20 | /** 21 | * Returns this ByteString as an Uint8Array. DON'T MODIFY the returned array, 22 | * since the ByteString holds the reference to the same array. 23 | * @param {!ByteString} bytes 24 | * @return {!Uint8Array} 25 | */ 26 | function byteStringToUint8ArrayUnsafe(bytes) { 27 | return bytes.toUint8ArrayUnsafe(); 28 | } 29 | 30 | exports = { 31 | byteStringFromUint8ArrayUnsafe, 32 | byteStringToUint8ArrayUnsafe, 33 | }; 34 | -------------------------------------------------------------------------------- /experimental/runtime/internal/checks_test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @fileoverview Tests for checks.js. 3 | */ 4 | goog.module('protobuf.internal.checksTest'); 5 | 6 | const {CHECK_TYPE, checkDefAndNotNull, checkFunctionExists} = goog.require('protobuf.internal.checks'); 7 | 8 | describe('checkDefAndNotNull', () => { 9 | it('throws if undefined', () => { 10 | let value; 11 | if (CHECK_TYPE) { 12 | expect(() => checkDefAndNotNull(value)).toThrow(); 13 | } else { 14 | expect(checkDefAndNotNull(value)).toBeUndefined(); 15 | } 16 | }); 17 | 18 | it('throws if null', () => { 19 | const value = null; 20 | if (CHECK_TYPE) { 21 | expect(() => checkDefAndNotNull(value)).toThrow(); 22 | } else { 23 | expect(checkDefAndNotNull(value)).toBeNull(); 24 | } 25 | }); 26 | 27 | it('does not throw if empty string', () => { 28 | const value = ''; 29 | expect(checkDefAndNotNull(value)).toEqual(''); 30 | }); 31 | }); 32 | 33 | describe('checkFunctionExists', () => { 34 | it('throws if the function is undefined', () => { 35 | let foo = /** @type {function()} */ (/** @type {*} */ (undefined)); 36 | if (CHECK_TYPE) { 37 | expect(() => checkFunctionExists(foo)).toThrow(); 38 | } else { 39 | checkFunctionExists(foo); 40 | } 41 | }); 42 | 43 | it('throws if the property is defined but not a function', () => { 44 | let foo = /** @type {function()} */ (/** @type {*} */ (1)); 45 | if (CHECK_TYPE) { 46 | expect(() => checkFunctionExists(foo)).toThrow(); 47 | } else { 48 | checkFunctionExists(foo); 49 | } 50 | }); 51 | 52 | it('does not throw if the function is defined', () => { 53 | function foo(x) { 54 | return x; 55 | } 56 | checkFunctionExists(foo); 57 | }); 58 | }); -------------------------------------------------------------------------------- /experimental/runtime/kernel/binary_storage.js: -------------------------------------------------------------------------------- 1 | goog.module('protobuf.runtime.BinaryStorage'); 2 | 3 | const Storage = goog.require('protobuf.runtime.Storage'); 4 | const {checkDefAndNotNull} = goog.require('protobuf.internal.checks'); 5 | 6 | /** 7 | * Class storing all the fields of a binary protobuf message. 8 | * 9 | * @package 10 | * @template FieldType 11 | * @implements {Storage} 12 | */ 13 | class BinaryStorage { 14 | /** 15 | * @param {number=} pivot 16 | */ 17 | constructor(pivot = Storage.DEFAULT_PIVOT) { 18 | /** 19 | * Fields having a field number no greater than the pivot value are stored 20 | * into an array for fast access. A field with field number X is stored into 21 | * the array position X - 1. 22 | * 23 | * @private @const {!Array} 24 | */ 25 | this.array_ = new Array(pivot); 26 | 27 | /** 28 | * Fields having a field number higher than the pivot value are stored into 29 | * the map. We create the map only when it's needed, since even an empty map 30 | * takes up a significant amount of memory. 31 | * 32 | * @private {?Map} 33 | */ 34 | this.map_ = null; 35 | } 36 | 37 | /** 38 | * Fields having a field number no greater than the pivot value are stored 39 | * into an array for fast access. A field with field number X is stored into 40 | * the array position X - 1. 41 | * @return {number} 42 | * @override 43 | */ 44 | getPivot() { 45 | return this.array_.length; 46 | } 47 | 48 | /** 49 | * Sets a field in the specified field number. 50 | * 51 | * @param {number} fieldNumber 52 | * @param {!FieldType} field 53 | * @override 54 | */ 55 | set(fieldNumber, field) { 56 | if (fieldNumber <= this.getPivot()) { 57 | this.array_[fieldNumber - 1] = field; 58 | } else { 59 | if (this.map_) { 60 | this.map_.set(fieldNumber, field); 61 | } else { 62 | this.map_ = new Map([[fieldNumber, field]]); 63 | } 64 | } 65 | } 66 | 67 | /** 68 | * Returns a field at the specified field number. 69 | * 70 | * @param {number} fieldNumber 71 | * @return {!FieldType|undefined} 72 | * @override 73 | */ 74 | get(fieldNumber) { 75 | if (fieldNumber <= this.getPivot()) { 76 | return this.array_[fieldNumber - 1]; 77 | } else { 78 | return this.map_ ? this.map_.get(fieldNumber) : undefined; 79 | } 80 | } 81 | 82 | /** 83 | * Deletes a field from the specified field number. 84 | * 85 | * @param {number} fieldNumber 86 | * @override 87 | */ 88 | delete(fieldNumber) { 89 | if (fieldNumber <= this.getPivot()) { 90 | delete this.array_[fieldNumber - 1]; 91 | } else { 92 | if (this.map_) { 93 | this.map_.delete(fieldNumber); 94 | } 95 | } 96 | } 97 | 98 | /** 99 | * Executes the provided function once for each field. 100 | * 101 | * @param {function(!FieldType, number): void} callback 102 | * @override 103 | */ 104 | forEach(callback) { 105 | this.array_.forEach((field, fieldNumber) => { 106 | if (field) { 107 | callback(checkDefAndNotNull(field), fieldNumber + 1); 108 | } 109 | }); 110 | if (this.map_) { 111 | this.map_.forEach(callback); 112 | } 113 | } 114 | 115 | /** 116 | * Creates a shallow copy of the storage. 117 | * 118 | * @return {!BinaryStorage} 119 | * @override 120 | */ 121 | shallowCopy() { 122 | const copy = new BinaryStorage(this.getPivot()); 123 | this.forEach( 124 | (field, fieldNumber) => 125 | void copy.set(fieldNumber, field.shallowCopy())); 126 | return copy; 127 | } 128 | } 129 | 130 | exports = BinaryStorage; 131 | -------------------------------------------------------------------------------- /experimental/runtime/kernel/bool_test_pairs.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @fileoverview Test data for bool encoding and decoding. 3 | */ 4 | goog.module('protobuf.binary.boolTestPairs'); 5 | 6 | const BufferDecoder = goog.require('protobuf.binary.BufferDecoder'); 7 | const {createBufferDecoder} = goog.require('protobuf.binary.bufferDecoderHelper'); 8 | 9 | /** 10 | * An array of Pairs of boolean values and their bit representation. 11 | * This is used to test encoding and decoding from/to the protobuf wire format. 12 | * @return {!Array<{name: string, boolValue: boolean, bufferDecoder: 13 | * !BufferDecoder, error: ?boolean, skip_writer: ?boolean}>} 14 | */ 15 | function getBoolPairs() { 16 | const boolPairs = [ 17 | { 18 | name: 'true', 19 | boolValue: true, 20 | bufferDecoder: createBufferDecoder(0x01), 21 | }, 22 | { 23 | name: 'false', 24 | boolValue: false, 25 | bufferDecoder: createBufferDecoder(0x00), 26 | }, 27 | { 28 | name: 'two-byte true', 29 | boolValue: true, 30 | bufferDecoder: createBufferDecoder(0x80, 0x01), 31 | skip_writer: true, 32 | }, 33 | { 34 | name: 'two-byte false', 35 | boolValue: false, 36 | bufferDecoder: createBufferDecoder(0x80, 0x00), 37 | skip_writer: true, 38 | }, 39 | { 40 | name: 'minus one', 41 | boolValue: true, 42 | bufferDecoder: createBufferDecoder( 43 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01), 44 | skip_writer: true, 45 | }, 46 | { 47 | name: 'max signed int 2^63 - 1', 48 | boolValue: true, 49 | bufferDecoder: createBufferDecoder( 50 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F), 51 | skip_writer: true, 52 | }, 53 | { 54 | name: 'min signed int -2^63', 55 | boolValue: true, 56 | bufferDecoder: createBufferDecoder( 57 | 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x01), 58 | skip_writer: true, 59 | }, 60 | { 61 | name: 'overflowed but valid varint', 62 | boolValue: false, 63 | bufferDecoder: createBufferDecoder( 64 | 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x02), 65 | skip_writer: true, 66 | }, 67 | { 68 | name: 'errors out for 11 bytes', 69 | boolValue: true, 70 | bufferDecoder: createBufferDecoder( 71 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF), 72 | error: true, 73 | skip_writer: true, 74 | }, 75 | ]; 76 | return [...boolPairs]; 77 | } 78 | 79 | exports = {getBoolPairs}; 80 | -------------------------------------------------------------------------------- /experimental/runtime/kernel/buffer_decoder_helper.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @fileoverview Helper methods to create BufferDecoders. 3 | */ 4 | goog.module('protobuf.binary.bufferDecoderHelper'); 5 | 6 | const BufferDecoder = goog.require('protobuf.binary.BufferDecoder'); 7 | 8 | /** 9 | * @param {...number} bytes 10 | * @return {!BufferDecoder} 11 | */ 12 | function createBufferDecoder(...bytes) { 13 | return BufferDecoder.fromArrayBuffer(new Uint8Array(bytes).buffer); 14 | } 15 | 16 | exports = { 17 | createBufferDecoder, 18 | }; 19 | -------------------------------------------------------------------------------- /experimental/runtime/kernel/conformance/conformance_request.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @fileoverview Handwritten code of ConformanceRequest. 3 | */ 4 | goog.module('proto.conformance.ConformanceRequest'); 5 | 6 | const Kernel = goog.require('protobuf.runtime.Kernel'); 7 | const WireFormat = goog.require('proto.conformance.WireFormat'); 8 | 9 | /** 10 | * Handwritten code of conformance.ConformanceRequest. 11 | * This is used to send request from the conformance test runner to the testee. 12 | * Check //third_party/protobuf/testing/protobuf/conformance/conformance.proto 13 | * for more details. 14 | * @final 15 | */ 16 | class ConformanceRequest { 17 | /** 18 | * @param {!ArrayBuffer} bytes 19 | * @private 20 | */ 21 | constructor(bytes) { 22 | /** @private @const {!Kernel} */ 23 | this.accessor_ = Kernel.fromArrayBuffer(bytes); 24 | } 25 | 26 | /** 27 | * Create a request instance with the given bytes data. 28 | * @param {!ArrayBuffer} bytes 29 | * @return {!ConformanceRequest} 30 | */ 31 | static deserialize(bytes) { 32 | return new ConformanceRequest(bytes); 33 | } 34 | 35 | /** 36 | * Gets the protobuf_payload. 37 | * @return {!ArrayBuffer} 38 | */ 39 | getProtobufPayload() { 40 | return this.accessor_.getBytesWithDefault(1).toArrayBuffer(); 41 | } 42 | 43 | /** 44 | * Gets the requested_output_format. 45 | * @return {!WireFormat} 46 | */ 47 | getRequestedOutputFormat() { 48 | return /** @type {!WireFormat} */ (this.accessor_.getInt32WithDefault(3)); 49 | } 50 | 51 | /** 52 | * Gets the message_type. 53 | * @return {string} 54 | */ 55 | getMessageType() { 56 | return this.accessor_.getStringWithDefault(4); 57 | } 58 | 59 | /** 60 | * Gets the oneof case for payload field. 61 | * This implementation assumes only one field in a oneof group is set. 62 | * @return {!ConformanceRequest.PayloadCase} 63 | */ 64 | getPayloadCase() { 65 | if (this.accessor_.hasFieldNumber(1)) { 66 | return /** @type {!ConformanceRequest.PayloadCase} */ ( 67 | ConformanceRequest.PayloadCase.PROTOBUF_PAYLOAD); 68 | } else if (this.accessor_.hasFieldNumber(2)) { 69 | return /** @type {!ConformanceRequest.PayloadCase} */ ( 70 | ConformanceRequest.PayloadCase.JSON_PAYLOAD); 71 | } else if (this.accessor_.hasFieldNumber(8)) { 72 | return /** @type {!ConformanceRequest.PayloadCase} */ ( 73 | ConformanceRequest.PayloadCase.TEXT_PAYLOAD); 74 | } else { 75 | return /** @type {!ConformanceRequest.PayloadCase} */ ( 76 | ConformanceRequest.PayloadCase.PAYLOAD_NOT_SET); 77 | } 78 | } 79 | } 80 | 81 | /** 82 | * @enum {number} 83 | */ 84 | ConformanceRequest.PayloadCase = { 85 | PAYLOAD_NOT_SET: 0, 86 | PROTOBUF_PAYLOAD: 1, 87 | JSON_PAYLOAD: 2, 88 | TEXT_PAYLOAD: 8, 89 | }; 90 | 91 | exports = ConformanceRequest; 92 | -------------------------------------------------------------------------------- /experimental/runtime/kernel/conformance/conformance_response.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @fileoverview Handwritten code of ConformanceResponse. 3 | */ 4 | goog.module('proto.conformance.ConformanceResponse'); 5 | 6 | const ByteString = goog.require('protobuf.ByteString'); 7 | const Kernel = goog.require('protobuf.runtime.Kernel'); 8 | 9 | /** 10 | * Handwritten code of conformance.ConformanceResponse. 11 | * This is used to send response from the conformance testee to the test runner. 12 | * Check //third_party/protobuf/testing/protobuf/conformance/conformance.proto 13 | * for more details. 14 | * @final 15 | */ 16 | class ConformanceResponse { 17 | /** 18 | * @param {!ArrayBuffer} bytes 19 | * @private 20 | */ 21 | constructor(bytes) { 22 | /** @private @const {!Kernel} */ 23 | this.accessor_ = Kernel.fromArrayBuffer(bytes); 24 | } 25 | 26 | /** 27 | * Create an empty response instance. 28 | * @return {!ConformanceResponse} 29 | */ 30 | static createEmpty() { 31 | return new ConformanceResponse(new ArrayBuffer(0)); 32 | } 33 | 34 | /** 35 | * Sets parse_error field. 36 | * @param {string} value 37 | */ 38 | setParseError(value) { 39 | this.accessor_.setString(1, value); 40 | } 41 | 42 | /** 43 | * Sets runtime_error field. 44 | * @param {string} value 45 | */ 46 | setRuntimeError(value) { 47 | this.accessor_.setString(2, value); 48 | } 49 | 50 | /** 51 | * Sets protobuf_payload field. 52 | * @param {!ArrayBuffer} value 53 | */ 54 | setProtobufPayload(value) { 55 | const bytesString = ByteString.fromArrayBuffer(value); 56 | this.accessor_.setBytes(3, bytesString); 57 | } 58 | 59 | /** 60 | * Sets skipped field. 61 | * @param {string} value 62 | */ 63 | setSkipped(value) { 64 | this.accessor_.setString(5, value); 65 | } 66 | 67 | /** 68 | * Serializes into binary data. 69 | * @return {!ArrayBuffer} 70 | */ 71 | serialize() { 72 | return this.accessor_.serialize(); 73 | } 74 | } 75 | 76 | exports = ConformanceResponse; 77 | -------------------------------------------------------------------------------- /experimental/runtime/kernel/conformance/conformance_testee_runner_node.js: -------------------------------------------------------------------------------- 1 | const ConformanceRequest = goog.require('proto.conformance.ConformanceRequest'); 2 | const {doTest} = goog.require('javascript.protobuf.conformance'); 3 | const fs = require('fs'); 4 | 5 | 6 | /** 7 | * Reads a buffer of N bytes. 8 | * @param {number} bytes Number of bytes to read. 9 | * @return {!Buffer} Buffer which contains data. 10 | */ 11 | function readBuffer(bytes) { 12 | // Linux cannot use process.stdin.fd (which isn't set up as sync) 13 | const buf = new Buffer.alloc(bytes); 14 | const fd = fs.openSync('/dev/stdin', 'r'); 15 | fs.readSync(fd, buf, 0, bytes); 16 | fs.closeSync(fd); 17 | return buf; 18 | } 19 | 20 | /** 21 | * Writes all data in buffer. 22 | * @param {!Buffer} buffer Buffer which contains data. 23 | */ 24 | function writeBuffer(buffer) { 25 | // Under linux, process.stdout.fd is async. Needs to open stdout in a synced 26 | // way for sync write. 27 | const fd = fs.openSync('/dev/stdout', 'w'); 28 | fs.writeSync(fd, buffer, 0, buffer.length); 29 | fs.closeSync(fd); 30 | } 31 | 32 | /** 33 | * Returns true if the test ran successfully, false on legitimate EOF. 34 | * @return {boolean} Whether to continue test. 35 | */ 36 | function runConformanceTest() { 37 | const requestLengthBuf = readBuffer(4); 38 | const requestLength = requestLengthBuf.readInt32LE(0); 39 | if (!requestLength) { 40 | return false; 41 | } 42 | 43 | const serializedRequest = readBuffer(requestLength); 44 | const array = new Uint8Array(serializedRequest); 45 | const request = ConformanceRequest.deserialize(array.buffer); 46 | const response = doTest(request); 47 | 48 | const serializedResponse = response.serialize(); 49 | 50 | const responseLengthBuf = new Buffer.alloc(4); 51 | responseLengthBuf.writeInt32LE(serializedResponse.byteLength, 0); 52 | writeBuffer(responseLengthBuf); 53 | writeBuffer(new Buffer.from(serializedResponse)); 54 | 55 | return true; 56 | } 57 | 58 | while (true) { 59 | if (!runConformanceTest()) { 60 | break; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /experimental/runtime/kernel/conformance/wire_format.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @fileoverview Handwritten code of WireFormat. 3 | */ 4 | goog.module('proto.conformance.WireFormat'); 5 | 6 | /** 7 | * @enum {number} 8 | */ 9 | const WireFormat = { 10 | UNSPECIFIED: 0, 11 | PROTOBUF: 1, 12 | JSON: 2, 13 | TEXT_FORMAT: 4, 14 | }; 15 | 16 | exports = WireFormat; 17 | -------------------------------------------------------------------------------- /experimental/runtime/kernel/double_test_pairs.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @fileoverview Test data for double encoding and decoding. 3 | */ 4 | goog.module('protobuf.binary.doubleTestPairs'); 5 | 6 | const BufferDecoder = goog.require('protobuf.binary.BufferDecoder'); 7 | const {createBufferDecoder} = goog.require('protobuf.binary.bufferDecoderHelper'); 8 | 9 | /** 10 | * An array of Pairs of double values and their bit representation. 11 | * This is used to test encoding and decoding from the protobuf wire format. 12 | * @return {!Array<{name: string, doubleValue:number, bufferDecoder: 13 | * !BufferDecoder}>} 14 | */ 15 | function getDoublePairs() { 16 | const doublePairs = [ 17 | { 18 | name: 'zero', 19 | doubleValue: 0, 20 | bufferDecoder: 21 | createBufferDecoder(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00) 22 | }, 23 | { 24 | name: 'minus zero', 25 | doubleValue: -0, 26 | bufferDecoder: 27 | createBufferDecoder(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80) 28 | }, 29 | { 30 | name: 'one', 31 | doubleValue: 1, 32 | bufferDecoder: 33 | createBufferDecoder(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F) 34 | }, 35 | { 36 | name: 'minus one', 37 | doubleValue: -1, 38 | bufferDecoder: 39 | createBufferDecoder(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xBF) 40 | }, 41 | 42 | { 43 | name: 'PI', 44 | doubleValue: Math.PI, 45 | bufferDecoder: 46 | createBufferDecoder(0x18, 0x2D, 0x44, 0x54, 0xFB, 0x21, 0x09, 0x40) 47 | 48 | }, 49 | { 50 | name: 'max value', 51 | doubleValue: Number.MAX_VALUE, 52 | bufferDecoder: 53 | createBufferDecoder(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xEF, 0x7F) 54 | }, 55 | { 56 | name: 'min value', 57 | doubleValue: Number.MIN_VALUE, 58 | bufferDecoder: 59 | createBufferDecoder(0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00) 60 | }, 61 | { 62 | name: 'Infinity', 63 | doubleValue: Infinity, 64 | bufferDecoder: 65 | createBufferDecoder(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x7F) 66 | }, 67 | { 68 | name: 'minus Infinity', 69 | doubleValue: -Infinity, 70 | bufferDecoder: 71 | createBufferDecoder(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xFF) 72 | }, 73 | { 74 | name: 'Number.MAX_SAFE_INTEGER', 75 | doubleValue: Number.MAX_SAFE_INTEGER, 76 | bufferDecoder: 77 | createBufferDecoder(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x3F, 0x43) 78 | }, 79 | { 80 | name: 'Number.MIN_SAFE_INTEGER', 81 | doubleValue: Number.MIN_SAFE_INTEGER, 82 | bufferDecoder: 83 | createBufferDecoder(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x3F, 0xC3) 84 | }, 85 | ]; 86 | return [...doublePairs]; 87 | } 88 | 89 | exports = {getDoublePairs}; 90 | -------------------------------------------------------------------------------- /experimental/runtime/kernel/fixed32_test_pairs.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @fileoverview Test data for float encoding and decoding. 3 | */ 4 | goog.module('protobuf.binary.fixed32TestPairs'); 5 | 6 | const BufferDecoder = goog.require('protobuf.binary.BufferDecoder'); 7 | const {createBufferDecoder} = goog.require('protobuf.binary.bufferDecoderHelper'); 8 | 9 | /** 10 | * An array of Pairs of float values and their bit representation. 11 | * This is used to test encoding and decoding from/to the protobuf wire format. 12 | * @return {!Array<{name: string, intValue: number, bufferDecoder: 13 | * !BufferDecoder}>} 14 | */ 15 | function getFixed32Pairs() { 16 | const fixed32Pairs = [ 17 | { 18 | name: 'zero', 19 | intValue: 0, 20 | bufferDecoder: createBufferDecoder(0x00, 0x00, 0x00, 0x00), 21 | }, 22 | { 23 | name: 'one ', 24 | intValue: 1, 25 | bufferDecoder: createBufferDecoder(0x01, 0x00, 0x00, 0x00) 26 | }, 27 | { 28 | name: 'max int 2^32 -1', 29 | intValue: Math.pow(2, 32) - 1, 30 | bufferDecoder: createBufferDecoder(0xFF, 0xFF, 0xFF, 0xFF) 31 | }, 32 | ]; 33 | return [...fixed32Pairs]; 34 | } 35 | 36 | exports = {getFixed32Pairs}; 37 | -------------------------------------------------------------------------------- /experimental/runtime/kernel/float_test_pairs.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @fileoverview Test data for float encoding and decoding. 3 | */ 4 | goog.module('protobuf.binary.floatTestPairs'); 5 | 6 | const BufferDecoder = goog.require('protobuf.binary.BufferDecoder'); 7 | const {createBufferDecoder} = goog.require('protobuf.binary.bufferDecoderHelper'); 8 | 9 | /** 10 | * An array of Pairs of float values and their bit representation. 11 | * This is used to test encoding and decoding from/to the protobuf wire format. 12 | * @return {!Array<{name: string, floatValue:number, bufferDecoder: 13 | * !BufferDecoder}>} 14 | */ 15 | function getFloatPairs() { 16 | const floatPairs = [ 17 | { 18 | name: 'zero', 19 | floatValue: 0, 20 | bufferDecoder: createBufferDecoder(0x00, 0x00, 0x00, 0x00), 21 | }, 22 | { 23 | name: 'minus zero', 24 | floatValue: -0, 25 | bufferDecoder: createBufferDecoder(0x00, 0x00, 0x00, 0x80) 26 | }, 27 | { 28 | name: 'one ', 29 | floatValue: 1, 30 | bufferDecoder: createBufferDecoder(0x00, 0x00, 0x80, 0x3F) 31 | }, 32 | { 33 | name: 'minus one', 34 | floatValue: -1, 35 | bufferDecoder: createBufferDecoder(0x00, 0x00, 0x80, 0xBF) 36 | }, 37 | { 38 | name: 'two', 39 | floatValue: 2, 40 | bufferDecoder: createBufferDecoder(0x00, 0x00, 0x00, 0x40) 41 | }, 42 | { 43 | name: 'max float32', 44 | floatValue: Math.pow(2, 127) * (2 - 1 / Math.pow(2, 23)), 45 | bufferDecoder: createBufferDecoder(0xFF, 0xFF, 0x7F, 0x7F) 46 | }, 47 | 48 | { 49 | name: 'min float32', 50 | floatValue: 1 / Math.pow(2, 127 - 1), 51 | bufferDecoder: createBufferDecoder(0x00, 0x00, 0x80, 0x00) 52 | }, 53 | 54 | { 55 | name: 'Infinity', 56 | floatValue: Infinity, 57 | bufferDecoder: createBufferDecoder(0x00, 0x00, 0x80, 0x7F) 58 | }, 59 | { 60 | name: 'minus Infinity', 61 | floatValue: -Infinity, 62 | bufferDecoder: createBufferDecoder(0x00, 0x00, 0x80, 0xFF) 63 | }, 64 | { 65 | name: '1.5', 66 | floatValue: 1.5, 67 | bufferDecoder: createBufferDecoder(0x00, 0x00, 0xC0, 0x3F) 68 | }, 69 | { 70 | name: '1.6', 71 | floatValue: 1.6, 72 | bufferDecoder: createBufferDecoder(0xCD, 0xCC, 0xCC, 0x3F) 73 | }, 74 | ]; 75 | return [...floatPairs]; 76 | } 77 | 78 | exports = {getFloatPairs}; 79 | -------------------------------------------------------------------------------- /experimental/runtime/kernel/indexer.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @fileoverview Utilities to index a binary proto by fieldnumbers without 3 | * relying on strutural proto information. 4 | */ 5 | goog.module('protobuf.binary.indexer'); 6 | 7 | const BinaryStorage = goog.require('protobuf.runtime.BinaryStorage'); 8 | const BufferDecoder = goog.require('protobuf.binary.BufferDecoder'); 9 | const WireType = goog.require('protobuf.binary.WireType'); 10 | const {Field} = goog.require('protobuf.binary.field'); 11 | const {checkCriticalState} = goog.require('protobuf.internal.checks'); 12 | const {skipField, tagToFieldNumber, tagToWireType} = goog.require('protobuf.binary.tag'); 13 | 14 | /** 15 | * Appends a new entry in the index array for the given field number. 16 | * @param {!BinaryStorage} storage 17 | * @param {number} fieldNumber 18 | * @param {!WireType} wireType 19 | * @param {number} startIndex 20 | */ 21 | function addIndexEntry(storage, fieldNumber, wireType, startIndex) { 22 | const field = storage.get(fieldNumber); 23 | if (field !== undefined) { 24 | field.addIndexEntry(wireType, startIndex); 25 | } else { 26 | storage.set(fieldNumber, Field.fromFirstIndexEntry(wireType, startIndex)); 27 | } 28 | } 29 | 30 | /** 31 | * Creates an index of field locations in a given binary protobuf. 32 | * @param {!BufferDecoder} bufferDecoder 33 | * @param {number|undefined} pivot 34 | * @return {!BinaryStorage} 35 | * @package 36 | */ 37 | function buildIndex(bufferDecoder, pivot) { 38 | bufferDecoder.setCursor(bufferDecoder.startIndex()); 39 | 40 | const storage = new BinaryStorage(pivot); 41 | while (bufferDecoder.hasNext()) { 42 | const tag = bufferDecoder.getUnsignedVarint32(); 43 | const wireType = tagToWireType(tag); 44 | const fieldNumber = tagToFieldNumber(tag); 45 | checkCriticalState(fieldNumber > 0, `Invalid field number ${fieldNumber}`); 46 | addIndexEntry(storage, fieldNumber, wireType, bufferDecoder.cursor()); 47 | skipField(bufferDecoder, wireType, fieldNumber); 48 | } 49 | return storage; 50 | } 51 | 52 | exports = { 53 | buildIndex, 54 | tagToWireType, 55 | }; 56 | -------------------------------------------------------------------------------- /experimental/runtime/kernel/int32_test_pairs.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @fileoverview Test data for int32 encoding and decoding. 3 | */ 4 | goog.module('protobuf.binary.int32TestPairs'); 5 | 6 | const BufferDecoder = goog.require('protobuf.binary.BufferDecoder'); 7 | const {createBufferDecoder} = goog.require('protobuf.binary.bufferDecoderHelper'); 8 | 9 | /** 10 | * An array of Pairs of float values and their bit representation. 11 | * This is used to test encoding and decoding from/to the protobuf wire format. 12 | * @return {!Array<{name: string, intValue:number, bufferDecoder: 13 | * !BufferDecoder, error: ?boolean, skip_writer: ?boolean}>} 14 | */ 15 | function getInt32Pairs() { 16 | const int32Pairs = [ 17 | { 18 | name: 'zero', 19 | intValue: 0, 20 | bufferDecoder: createBufferDecoder(0x00), 21 | }, 22 | { 23 | name: 'one ', 24 | intValue: 1, 25 | bufferDecoder: createBufferDecoder(0x01), 26 | }, 27 | { 28 | name: 'minus one', 29 | intValue: -1, 30 | bufferDecoder: createBufferDecoder(0xFF, 0xFF, 0xFF, 0xFF, 0x0F), 31 | // The writer will encode this with 64 bits, see below 32 | skip_writer: true, 33 | }, 34 | { 35 | name: 'minus one (64bits)', 36 | intValue: -1, 37 | bufferDecoder: createBufferDecoder( 38 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01), 39 | }, 40 | { 41 | name: 'max signed int 2^31 - 1', 42 | intValue: Math.pow(2, 31) - 1, 43 | bufferDecoder: createBufferDecoder(0xFF, 0xFF, 0xFF, 0xFF, 0x07), 44 | 45 | }, 46 | { 47 | name: 'min signed int -2^31', 48 | intValue: -Math.pow(2, 31), 49 | bufferDecoder: createBufferDecoder(0x80, 0x80, 0x80, 0x80, 0x08), 50 | // The writer will encode this with 64 bits, see below 51 | skip_writer: true, 52 | }, 53 | { 54 | name: 'value min signed int -2^31 (64 bit)', 55 | intValue: -Math.pow(2, 31), 56 | bufferDecoder: createBufferDecoder( 57 | 0x80, 0x80, 0x80, 0x80, 0xF8, 0xFF, 0xFF, 0xFF, 0xFF, 0x01), 58 | }, 59 | { 60 | name: 'errors out for 11 bytes', 61 | intValue: -1, 62 | bufferDecoder: createBufferDecoder( 63 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF), 64 | error: true, 65 | skip_writer: true, 66 | }, 67 | ]; 68 | return [...int32Pairs]; 69 | } 70 | 71 | exports = {getInt32Pairs}; 72 | -------------------------------------------------------------------------------- /experimental/runtime/kernel/int64_test_pairs.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @fileoverview Test data for int64 encoding and decoding. 3 | */ 4 | goog.module('protobuf.binary.int64TestPairs'); 5 | 6 | const BufferDecoder = goog.require('protobuf.binary.BufferDecoder'); 7 | const Int64 = goog.require('protobuf.Int64'); 8 | const {createBufferDecoder} = goog.require('protobuf.binary.bufferDecoderHelper'); 9 | 10 | /** 11 | * An array of Pairs of float values and their bit representation. 12 | * This is used to test encoding and decoding from/to the protobuf wire format. 13 | * @return {!Array<{name: string, longValue: !Int64, bufferDecoder: 14 | * !BufferDecoder, error: ?boolean, skip_writer: ?boolean}>} 15 | */ 16 | function getInt64Pairs() { 17 | const int64Pairs = [ 18 | { 19 | name: 'zero', 20 | longValue: Int64.fromInt(0), 21 | bufferDecoder: createBufferDecoder(0x00), 22 | }, 23 | { 24 | name: 'one ', 25 | longValue: Int64.fromInt(1), 26 | bufferDecoder: createBufferDecoder(0x01), 27 | }, 28 | { 29 | name: 'minus one', 30 | longValue: Int64.fromInt(-1), 31 | bufferDecoder: createBufferDecoder( 32 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01), 33 | }, 34 | { 35 | name: 'max signed int 2^63 - 1', 36 | longValue: Int64.fromBits(0xFFFFFFFF, 0x7FFFFFFF), 37 | bufferDecoder: createBufferDecoder( 38 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F), 39 | 40 | }, 41 | { 42 | name: 'value min signed int -2^63 (64 bit)', 43 | longValue: Int64.fromBits(0xFFFFFFFF, 0xFFFFFFFF), 44 | bufferDecoder: createBufferDecoder( 45 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01), 46 | }, 47 | { 48 | name: 'errors out for 11 bytes', 49 | longValue: Int64.fromInt(-1), 50 | bufferDecoder: createBufferDecoder( 51 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF), 52 | error: true, 53 | skip_writer: true, 54 | }, 55 | ]; 56 | return [...int64Pairs]; 57 | } 58 | 59 | exports = {getInt64Pairs}; 60 | -------------------------------------------------------------------------------- /experimental/runtime/kernel/internal_message.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @fileoverview Internal interface for messages implemented with the binary 3 | * kernel. 4 | */ 5 | goog.module('protobuf.binary.InternalMessage'); 6 | 7 | const Kernel = goog.requireType('protobuf.runtime.Kernel'); 8 | 9 | /** 10 | * Interface that needs to be implemented by messages implemented with the 11 | * binary kernel. This is an internal only interface and should be used only by 12 | * the classes in binary kernel. 13 | * 14 | * @interface 15 | */ 16 | class InternalMessage { 17 | /** 18 | * @package 19 | * @return {!Kernel} 20 | */ 21 | internalGetKernel() {} 22 | } 23 | 24 | exports = InternalMessage; -------------------------------------------------------------------------------- /experimental/runtime/kernel/packed_bool_test_pairs.js: -------------------------------------------------------------------------------- 1 | goog.module('protobuf.binary.packedBoolTestPairs'); 2 | 3 | const BufferDecoder = goog.require('protobuf.binary.BufferDecoder'); 4 | const {createBufferDecoder} = goog.require('protobuf.binary.bufferDecoderHelper'); 5 | 6 | /** 7 | * An array of Pairs of packed bool values and their bit representation. 8 | * This is used to test encoding and decoding from/to the protobuf wire format. 9 | * @return {!Array<{name: string, boolValues: !Array, 10 | * bufferDecoder: !BufferDecoder, skip_writer: ?boolean}>} 11 | */ 12 | function getPackedBoolPairs() { 13 | return [ 14 | { 15 | name: 'empty value', 16 | boolValues: [], 17 | bufferDecoder: createBufferDecoder(0x00), 18 | skip_writer: true, 19 | }, 20 | { 21 | name: 'single value', 22 | boolValues: [true], 23 | bufferDecoder: createBufferDecoder(0x01, 0x01), 24 | }, 25 | { 26 | name: 'single multi-bytes value', 27 | boolValues: [true], 28 | bufferDecoder: createBufferDecoder(0x02, 0x80, 0x01), 29 | skip_writer: true, 30 | }, 31 | { 32 | name: 'multiple values', 33 | boolValues: [true, false], 34 | bufferDecoder: createBufferDecoder(0x02, 0x01, 0x00), 35 | }, 36 | { 37 | name: 'multiple multi-bytes values', 38 | boolValues: [true, false], 39 | bufferDecoder: createBufferDecoder( 40 | 0x0C, // length 41 | 0x80, 42 | 0x80, 43 | 0x80, 44 | 0x80, 45 | 0x80, 46 | 0x01, // true 47 | 0x80, 48 | 0x80, 49 | 0x80, 50 | 0x80, 51 | 0x80, 52 | 0x00, // false 53 | ), 54 | skip_writer: true, 55 | }, 56 | ]; 57 | } 58 | 59 | exports = {getPackedBoolPairs}; 60 | -------------------------------------------------------------------------------- /experimental/runtime/kernel/packed_double_test_pairs.js: -------------------------------------------------------------------------------- 1 | goog.module('protobuf.binary.packedDoubleTestPairs'); 2 | 3 | const BufferDecoder = goog.require('protobuf.binary.BufferDecoder'); 4 | const {createBufferDecoder} = goog.require('protobuf.binary.bufferDecoderHelper'); 5 | 6 | /** 7 | * An array of Pairs of packed double values and their bit representation. 8 | * This is used to test encoding and decoding from/to the protobuf wire format. 9 | * @return {!Array<{name: string, doubleValues: !Array, 10 | * bufferDecoder: !BufferDecoder, skip_writer: ?boolean}>} 11 | */ 12 | function getPackedDoublePairs() { 13 | return [ 14 | { 15 | name: 'empty value', 16 | doubleValues: [], 17 | bufferDecoder: createBufferDecoder(0x00), 18 | skip_writer: true, 19 | }, 20 | { 21 | name: 'single value', 22 | doubleValues: [1], 23 | bufferDecoder: createBufferDecoder( 24 | 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F), 25 | }, 26 | { 27 | name: 'multiple values', 28 | doubleValues: [1, 0], 29 | bufferDecoder: createBufferDecoder( 30 | 0x10, // length 31 | 0x00, 32 | 0x00, 33 | 0x00, 34 | 0x00, 35 | 0x00, 36 | 0x00, 37 | 0xF0, 38 | 0x3F, // 1 39 | 0x00, 40 | 0x00, 41 | 0x00, 42 | 0x00, 43 | 0x00, 44 | 0x00, 45 | 0x00, 46 | 0x00, // 0 47 | ), 48 | }, 49 | ]; 50 | } 51 | 52 | exports = {getPackedDoublePairs}; 53 | -------------------------------------------------------------------------------- /experimental/runtime/kernel/packed_fixed32_test_pairs.js: -------------------------------------------------------------------------------- 1 | goog.module('protobuf.binary.packedFixed32TestPairs'); 2 | 3 | const BufferDecoder = goog.require('protobuf.binary.BufferDecoder'); 4 | const {createBufferDecoder} = goog.require('protobuf.binary.bufferDecoderHelper'); 5 | 6 | /** 7 | * An array of Pairs of packed fixed32 values and their bit representation. 8 | * This is used to test encoding and decoding from/to the protobuf wire format. 9 | * @return {!Array<{name: string, fixed32Values: !Array, 10 | * bufferDecoder: !BufferDecoder, skip_writer: ?boolean}>} 11 | */ 12 | function getPackedFixed32Pairs() { 13 | return [ 14 | { 15 | name: 'empty value', 16 | fixed32Values: [], 17 | bufferDecoder: createBufferDecoder(0x00), 18 | skip_writer: true, 19 | }, 20 | { 21 | name: 'single value', 22 | fixed32Values: [1], 23 | bufferDecoder: createBufferDecoder(0x04, 0x01, 0x00, 0x00, 0x00), 24 | }, 25 | { 26 | name: 'multiple values', 27 | fixed32Values: [1, 0], 28 | bufferDecoder: createBufferDecoder( 29 | 0x08, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00), 30 | }, 31 | ]; 32 | } 33 | 34 | exports = {getPackedFixed32Pairs}; 35 | -------------------------------------------------------------------------------- /experimental/runtime/kernel/packed_float_test_pairs.js: -------------------------------------------------------------------------------- 1 | goog.module('protobuf.binary.packedFloatTestPairs'); 2 | 3 | const BufferDecoder = goog.require('protobuf.binary.BufferDecoder'); 4 | const {createBufferDecoder} = goog.require('protobuf.binary.bufferDecoderHelper'); 5 | 6 | /** 7 | * An array of Pairs of packed float values and their bit representation. 8 | * This is used to test encoding and decoding from/to the protobuf wire format. 9 | * @return {!Array<{name: string, floatValues: !Array, 10 | * bufferDecoder: !BufferDecoder, skip_writer: ?boolean}>} 11 | */ 12 | function getPackedFloatPairs() { 13 | return [ 14 | { 15 | name: 'empty value', 16 | floatValues: [], 17 | bufferDecoder: createBufferDecoder(0x00), 18 | skip_writer: true, 19 | }, 20 | { 21 | name: 'single value', 22 | floatValues: [1], 23 | bufferDecoder: createBufferDecoder(0x04, 0x00, 0x00, 0x80, 0x3F), 24 | }, 25 | { 26 | name: 'multiple values', 27 | floatValues: [1, 0], 28 | bufferDecoder: createBufferDecoder( 29 | 0x08, 0x00, 0x00, 0x80, 0x3F, 0x00, 0x00, 0x00, 0x00), 30 | }, 31 | ]; 32 | } 33 | 34 | exports = {getPackedFloatPairs}; 35 | -------------------------------------------------------------------------------- /experimental/runtime/kernel/packed_int32_test_pairs.js: -------------------------------------------------------------------------------- 1 | goog.module('protobuf.binary.packedInt32TestPairs'); 2 | 3 | const BufferDecoder = goog.require('protobuf.binary.BufferDecoder'); 4 | const {createBufferDecoder} = goog.require('protobuf.binary.bufferDecoderHelper'); 5 | 6 | /** 7 | * An array of Pairs of packed int32 values and their bit representation. 8 | * This is used to test encoding and decoding from/to the protobuf wire format. 9 | * @return {!Array<{name: string, int32Values: !Array, 10 | * bufferDecoder: !BufferDecoder, skip_writer: ?boolean}>} 11 | */ 12 | function getPackedInt32Pairs() { 13 | return [ 14 | { 15 | name: 'empty value', 16 | int32Values: [], 17 | bufferDecoder: createBufferDecoder(0x00), 18 | skip_writer: true, 19 | }, 20 | { 21 | name: 'single value', 22 | int32Values: [1], 23 | bufferDecoder: createBufferDecoder(0x01, 0x01), 24 | }, 25 | { 26 | name: 'multiple values', 27 | int32Values: [1, 0], 28 | bufferDecoder: createBufferDecoder(0x02, 0x01, 0x00), 29 | }, 30 | ]; 31 | } 32 | 33 | exports = {getPackedInt32Pairs}; 34 | -------------------------------------------------------------------------------- /experimental/runtime/kernel/packed_int64_test_pairs.js: -------------------------------------------------------------------------------- 1 | goog.module('protobuf.binary.packedInt64TestPairs'); 2 | 3 | const BufferDecoder = goog.require('protobuf.binary.BufferDecoder'); 4 | const Int64 = goog.require('protobuf.Int64'); 5 | const {createBufferDecoder} = goog.require('protobuf.binary.bufferDecoderHelper'); 6 | 7 | /** 8 | * An array of Pairs of packed int64 values and their bit representation. 9 | * This is used to test encoding and decoding from/to the protobuf wire format. 10 | * @return {!Array<{name: string, int64Values: !Array, 11 | * bufferDecoder: !BufferDecoder, skip_writer: ?boolean}>} 12 | */ 13 | function getPackedInt64Pairs() { 14 | return [ 15 | { 16 | name: 'empty value', 17 | int64Values: [], 18 | bufferDecoder: createBufferDecoder(0x00), 19 | skip_writer: true, 20 | }, 21 | { 22 | name: 'single value', 23 | int64Values: [Int64.fromInt(1)], 24 | bufferDecoder: createBufferDecoder(0x01, 0x01), 25 | }, 26 | { 27 | name: 'multiple values', 28 | int64Values: [Int64.fromInt(1), Int64.fromInt(0)], 29 | bufferDecoder: createBufferDecoder(0x02, 0x01, 0x00), 30 | }, 31 | ]; 32 | } 33 | 34 | exports = {getPackedInt64Pairs}; 35 | -------------------------------------------------------------------------------- /experimental/runtime/kernel/packed_sfixed32_test_pairs.js: -------------------------------------------------------------------------------- 1 | goog.module('protobuf.binary.packedSfixed32TestPairs'); 2 | 3 | const BufferDecoder = goog.require('protobuf.binary.BufferDecoder'); 4 | const {createBufferDecoder} = goog.require('protobuf.binary.bufferDecoderHelper'); 5 | 6 | /** 7 | * An array of Pairs of packed sfixed32 values and their bit representation. 8 | * This is used to test encoding and decoding from/to the protobuf wire format. 9 | * @return {!Array<{name: string, sfixed32Values: !Array, 10 | * bufferDecoder: !BufferDecoder, skip_writer: ?boolean}>} 11 | */ 12 | function getPackedSfixed32Pairs() { 13 | return [ 14 | { 15 | name: 'empty value', 16 | sfixed32Values: [], 17 | bufferDecoder: createBufferDecoder(0x00), 18 | skip_writer: true, 19 | }, 20 | { 21 | name: 'single value', 22 | sfixed32Values: [1], 23 | bufferDecoder: createBufferDecoder(0x04, 0x01, 0x00, 0x00, 0x00), 24 | }, 25 | { 26 | name: 'multiple values', 27 | sfixed32Values: [1, 0], 28 | bufferDecoder: createBufferDecoder( 29 | 0x08, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00), 30 | }, 31 | ]; 32 | } 33 | 34 | exports = {getPackedSfixed32Pairs}; 35 | -------------------------------------------------------------------------------- /experimental/runtime/kernel/packed_sfixed64_test_pairs.js: -------------------------------------------------------------------------------- 1 | goog.module('protobuf.binary.packedSfixed64TestPairs'); 2 | 3 | const BufferDecoder = goog.require('protobuf.binary.BufferDecoder'); 4 | const Int64 = goog.require('protobuf.Int64'); 5 | const {createBufferDecoder} = goog.require('protobuf.binary.bufferDecoderHelper'); 6 | 7 | /** 8 | * An array of Pairs of packed sfixed64 values and their bit representation. 9 | * This is used to test encoding and decoding from/to the protobuf wire format. 10 | * @return {!Array<{name: string, sfixed64Values: !Array, 11 | * bufferDecoder: !BufferDecoder, skip_writer: ?boolean}>} 12 | */ 13 | function getPackedSfixed64Pairs() { 14 | return [ 15 | { 16 | name: 'empty value', 17 | sfixed64Values: [], 18 | bufferDecoder: createBufferDecoder(0x00), 19 | skip_writer: true, 20 | }, 21 | { 22 | name: 'single value', 23 | sfixed64Values: [Int64.fromInt(1)], 24 | bufferDecoder: createBufferDecoder( 25 | 0x08, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00), 26 | }, 27 | { 28 | name: 'multiple values', 29 | sfixed64Values: [Int64.fromInt(1), Int64.fromInt(0)], 30 | bufferDecoder: createBufferDecoder( 31 | 0x10, // length 32 | 0x01, 33 | 0x00, 34 | 0x00, 35 | 0x00, 36 | 0x00, 37 | 0x00, 38 | 0x00, 39 | 0x00, // 1 40 | 0x00, 41 | 0x00, 42 | 0x00, 43 | 0x00, 44 | 0x00, 45 | 0x00, 46 | 0x00, 47 | 0x00, // 2 48 | ), 49 | }, 50 | ]; 51 | } 52 | 53 | exports = {getPackedSfixed64Pairs}; 54 | -------------------------------------------------------------------------------- /experimental/runtime/kernel/packed_sint32_test_pairs.js: -------------------------------------------------------------------------------- 1 | goog.module('protobuf.binary.packedSint32TestPairs'); 2 | 3 | const BufferDecoder = goog.require('protobuf.binary.BufferDecoder'); 4 | const {createBufferDecoder} = goog.require('protobuf.binary.bufferDecoderHelper'); 5 | 6 | /** 7 | * An array of Pairs of packed sint32 values and their bit representation. 8 | * This is used to test encoding and decoding from/to the protobuf wire format. 9 | * @return {!Array<{name: string, sint32Values: !Array, 10 | * bufferDecoder: !BufferDecoder, skip_writer: ?boolean}>} 11 | */ 12 | function getPackedSint32Pairs() { 13 | return [ 14 | { 15 | name: 'empty value', 16 | sint32Values: [], 17 | bufferDecoder: createBufferDecoder(0x00), 18 | skip_writer: true, 19 | }, 20 | { 21 | name: 'single value', 22 | sint32Values: [-1], 23 | bufferDecoder: createBufferDecoder(0x01, 0x01), 24 | }, 25 | { 26 | name: 'multiple values', 27 | sint32Values: [-1, 0], 28 | bufferDecoder: createBufferDecoder(0x02, 0x01, 0x00), 29 | }, 30 | ]; 31 | } 32 | 33 | exports = {getPackedSint32Pairs}; 34 | -------------------------------------------------------------------------------- /experimental/runtime/kernel/packed_sint64_test_pairs.js: -------------------------------------------------------------------------------- 1 | goog.module('protobuf.binary.packedSint64TestPairs'); 2 | 3 | const BufferDecoder = goog.require('protobuf.binary.BufferDecoder'); 4 | const Int64 = goog.require('protobuf.Int64'); 5 | const {createBufferDecoder} = goog.require('protobuf.binary.bufferDecoderHelper'); 6 | 7 | /** 8 | * An array of Pairs of packed sint64 values and their bit representation. 9 | * This is used to test encoding and decoding from/to the protobuf wire format. 10 | * @return {!Array<{name: string, sint64Values: !Array, 11 | * bufferDecoder: !BufferDecoder, skip_writer: ?boolean}>} 12 | */ 13 | function getPackedSint64Pairs() { 14 | return [ 15 | { 16 | name: 'empty value', 17 | sint64Values: [], 18 | bufferDecoder: createBufferDecoder(0x00), 19 | skip_writer: true, 20 | }, 21 | { 22 | name: 'single value', 23 | sint64Values: [Int64.fromInt(-1)], 24 | bufferDecoder: createBufferDecoder(0x01, 0x01), 25 | }, 26 | { 27 | name: 'multiple values', 28 | sint64Values: [Int64.fromInt(-1), Int64.fromInt(0)], 29 | bufferDecoder: createBufferDecoder(0x02, 0x01, 0x00), 30 | }, 31 | ]; 32 | } 33 | 34 | exports = {getPackedSint64Pairs}; 35 | -------------------------------------------------------------------------------- /experimental/runtime/kernel/packed_uint32_test_pairs.js: -------------------------------------------------------------------------------- 1 | goog.module('protobuf.binary.packedUint32TestPairs'); 2 | 3 | const BufferDecoder = goog.require('protobuf.binary.BufferDecoder'); 4 | const {createBufferDecoder} = goog.require('protobuf.binary.bufferDecoderHelper'); 5 | 6 | /** 7 | * An array of Pairs of packed uint32 values and their bit representation. 8 | * This is used to test encoding and decoding from/to the protobuf wire format. 9 | * @return {!Array<{name: string, uint32Values: !Array, 10 | * bufferDecoder: !BufferDecoder, skip_writer: ?boolean}>} 11 | */ 12 | function getPackedUint32Pairs() { 13 | return [ 14 | { 15 | name: 'empty value', 16 | uint32Values: [], 17 | bufferDecoder: createBufferDecoder(0x00), 18 | skip_writer: true, 19 | }, 20 | { 21 | name: 'single value', 22 | uint32Values: [1], 23 | bufferDecoder: createBufferDecoder(0x01, 0x01), 24 | }, 25 | { 26 | name: 'multiple values', 27 | uint32Values: [1, 0], 28 | bufferDecoder: createBufferDecoder(0x02, 0x01, 0x00), 29 | }, 30 | ]; 31 | } 32 | 33 | exports = {getPackedUint32Pairs}; 34 | -------------------------------------------------------------------------------- /experimental/runtime/kernel/sfixed32_test_pairs.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @fileoverview Test data for sfixed32 encoding and decoding. 3 | */ 4 | goog.module('protobuf.binary.sfixed32TestPairs'); 5 | 6 | const BufferDecoder = goog.require('protobuf.binary.BufferDecoder'); 7 | const {createBufferDecoder} = goog.require('protobuf.binary.bufferDecoderHelper'); 8 | 9 | /** 10 | * An array of Pairs of int values and their bit representation. 11 | * This is used to test encoding and decoding from/to the protobuf wire format. 12 | * @return {!Array<{name: string, intValue: number, bufferDecoder: 13 | * !BufferDecoder}>} 14 | */ 15 | function getSfixed32Pairs() { 16 | const sfixed32Pairs = [ 17 | { 18 | name: 'zero', 19 | intValue: 0, 20 | bufferDecoder: createBufferDecoder(0x00, 0x00, 0x00, 0x00), 21 | }, 22 | { 23 | name: 'one', 24 | intValue: 1, 25 | bufferDecoder: createBufferDecoder(0x01, 0x00, 0x00, 0x00) 26 | }, 27 | { 28 | name: 'minus one', 29 | intValue: -1, 30 | bufferDecoder: createBufferDecoder(0xFF, 0xFF, 0xFF, 0xFF), 31 | }, 32 | { 33 | name: 'max int 2^31 -1', 34 | intValue: Math.pow(2, 31) - 1, 35 | bufferDecoder: createBufferDecoder(0xFF, 0xFF, 0xFF, 0x7F) 36 | }, 37 | { 38 | name: 'min int -2^31', 39 | intValue: -Math.pow(2, 31), 40 | bufferDecoder: createBufferDecoder(0x00, 0x00, 0x00, 0x80) 41 | }, 42 | ]; 43 | return [...sfixed32Pairs]; 44 | } 45 | 46 | exports = {getSfixed32Pairs}; 47 | -------------------------------------------------------------------------------- /experimental/runtime/kernel/sfixed64_test_pairs.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @fileoverview Test data for sfixed32 encoding and decoding. 3 | */ 4 | goog.module('protobuf.binary.sfixed64TestPairs'); 5 | 6 | const BufferDecoder = goog.require('protobuf.binary.BufferDecoder'); 7 | const Int64 = goog.require('protobuf.Int64'); 8 | const {createBufferDecoder} = goog.require('protobuf.binary.bufferDecoderHelper'); 9 | 10 | /** 11 | * An array of Pairs of int values and their bit representation. 12 | * This is used to test encoding and decoding from/to the protobuf wire format. 13 | * @return {!Array<{name: string, longValue: !Int64, bufferDecoder: 14 | * !BufferDecoder}>} 15 | */ 16 | function getSfixed64Pairs() { 17 | const sfixed64Pairs = [ 18 | { 19 | name: 'zero', 20 | longValue: Int64.fromInt(0), 21 | bufferDecoder: 22 | createBufferDecoder(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00), 23 | }, 24 | { 25 | name: 'one', 26 | longValue: Int64.fromInt(1), 27 | bufferDecoder: 28 | createBufferDecoder(0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00) 29 | }, 30 | { 31 | name: 'minus one', 32 | longValue: Int64.fromInt(-1), 33 | bufferDecoder: 34 | createBufferDecoder(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF), 35 | }, 36 | { 37 | name: 'max int 2^63 -1', 38 | longValue: Int64.getMaxValue(), 39 | bufferDecoder: 40 | createBufferDecoder(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F) 41 | }, 42 | { 43 | name: 'min int -2^63', 44 | longValue: Int64.getMinValue(), 45 | bufferDecoder: 46 | createBufferDecoder(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80) 47 | }, 48 | ]; 49 | return [...sfixed64Pairs]; 50 | } 51 | 52 | exports = {getSfixed64Pairs}; 53 | -------------------------------------------------------------------------------- /experimental/runtime/kernel/sint32_test_pairs.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @fileoverview Test data for int32 encoding and decoding. 3 | */ 4 | goog.module('protobuf.binary.sint32TestPairs'); 5 | 6 | const BufferDecoder = goog.require('protobuf.binary.BufferDecoder'); 7 | const {createBufferDecoder} = goog.require('protobuf.binary.bufferDecoderHelper'); 8 | 9 | /** 10 | * An array of Pairs of float values and their bit representation. 11 | * This is used to test encoding and decoding from/to the protobuf wire format. 12 | * @return {!Array<{name: string, intValue:number, bufferDecoder: 13 | * !BufferDecoder, error: ?boolean, skip_writer: ?boolean}>} 14 | */ 15 | function getSint32Pairs() { 16 | const sint32Pairs = [ 17 | { 18 | name: 'zero', 19 | intValue: 0, 20 | bufferDecoder: createBufferDecoder(0x00), 21 | }, 22 | { 23 | name: 'one ', 24 | intValue: 1, 25 | bufferDecoder: createBufferDecoder(0x02), 26 | }, 27 | { 28 | name: 'minus one', 29 | intValue: -1, 30 | bufferDecoder: createBufferDecoder(0x01), 31 | }, 32 | { 33 | name: 'two', 34 | intValue: 2, 35 | bufferDecoder: createBufferDecoder(0x04), 36 | }, 37 | { 38 | name: 'minus two', 39 | intValue: -2, 40 | bufferDecoder: createBufferDecoder(0x03), 41 | }, 42 | { 43 | name: 'int 2^31 - 1', 44 | intValue: Math.pow(2, 31) - 1, 45 | bufferDecoder: createBufferDecoder(0xFE, 0xFF, 0xFF, 0xFF, 0x0F), 46 | 47 | }, 48 | { 49 | name: '-2^31', 50 | intValue: -Math.pow(2, 31), 51 | bufferDecoder: createBufferDecoder(0xFF, 0xFF, 0xFF, 0xFF, 0x0F), 52 | }, 53 | ]; 54 | return [...sint32Pairs]; 55 | } 56 | 57 | exports = {getSint32Pairs}; 58 | -------------------------------------------------------------------------------- /experimental/runtime/kernel/sint64_test_pairs.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @fileoverview Test data for sint64 encoding and decoding. 3 | */ 4 | goog.module('protobuf.binary.sint64TestPairs'); 5 | 6 | const BufferDecoder = goog.require('protobuf.binary.BufferDecoder'); 7 | const Int64 = goog.require('protobuf.Int64'); 8 | const {createBufferDecoder} = goog.require('protobuf.binary.bufferDecoderHelper'); 9 | 10 | /** 11 | * An array of Pairs of float values and their bit representation. 12 | * This is used to test encoding and decoding from/to the protobuf wire format. 13 | * @return {!Array<{name: string, longValue: !Int64, bufferDecoder: 14 | * !BufferDecoder, error: ?boolean, skip_writer: ?boolean}>} 15 | */ 16 | function getSint64Pairs() { 17 | const sint64Pairs = [ 18 | { 19 | name: 'zero', 20 | longValue: Int64.fromInt(0), 21 | bufferDecoder: createBufferDecoder(0x00), 22 | }, 23 | { 24 | name: 'one ', 25 | longValue: Int64.fromInt(1), 26 | bufferDecoder: createBufferDecoder(0x02), 27 | }, 28 | { 29 | name: 'minus one', 30 | longValue: Int64.fromInt(-1), 31 | bufferDecoder: createBufferDecoder(0x01), 32 | }, 33 | { 34 | name: 'two', 35 | longValue: Int64.fromInt(2), 36 | bufferDecoder: createBufferDecoder(0x04), 37 | }, 38 | { 39 | name: 'minus two', 40 | longValue: Int64.fromInt(-2), 41 | bufferDecoder: createBufferDecoder(0x03), 42 | }, 43 | { 44 | name: 'min value', 45 | longValue: Int64.getMinValue(), 46 | bufferDecoder: createBufferDecoder( 47 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01), 48 | }, 49 | 50 | { 51 | name: 'max value', 52 | longValue: Int64.getMaxValue(), 53 | bufferDecoder: createBufferDecoder( 54 | 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01), 55 | }, 56 | ]; 57 | return [...sint64Pairs]; 58 | } 59 | 60 | exports = {getSint64Pairs}; 61 | -------------------------------------------------------------------------------- /experimental/runtime/kernel/storage.js: -------------------------------------------------------------------------------- 1 | goog.module('protobuf.runtime.Storage'); 2 | 3 | /** 4 | * Interface for getting and storing fields of a protobuf message. 5 | * 6 | * @interface 7 | * @package 8 | * @template FieldType 9 | */ 10 | class Storage { 11 | /** 12 | * Returns the pivot value. 13 | * 14 | * @return {number} 15 | */ 16 | getPivot() {} 17 | 18 | /** 19 | * Sets a field in the specified field number. 20 | * 21 | * @param {number} fieldNumber 22 | * @param {!FieldType} field 23 | */ 24 | set(fieldNumber, field) {} 25 | 26 | /** 27 | * Returns a field at the specified field number. 28 | * 29 | * @param {number} fieldNumber 30 | * @return {!FieldType|undefined} 31 | */ 32 | get(fieldNumber) {} 33 | 34 | /** 35 | * Deletes a field from the specified field number. 36 | * 37 | * @param {number} fieldNumber 38 | */ 39 | delete(fieldNumber) {} 40 | 41 | /** 42 | * Executes the provided function once for each field. 43 | * 44 | * @param {function(!FieldType, number): void} callback 45 | */ 46 | forEach(callback) {} 47 | 48 | /** 49 | * Creates a shallow copy of the storage. 50 | * 51 | * @return {!Storage} 52 | */ 53 | shallowCopy() {} 54 | } 55 | 56 | /** 57 | * 85% of the proto fields have a field number <= 24: 58 | * https://plx.corp.google.com/scripts2/script_5d._f02af6_0000_23b1_a15f_001a1139dd02 59 | * 60 | * @type {number} 61 | */ 62 | // LINT.IfChange 63 | Storage.DEFAULT_PIVOT = 24; 64 | // LINT.ThenChange(//depot/google3/third_party/protobuf/javascript/runtime/kernel/binary_storage_test.js, 65 | // //depot/google3/net/proto2/contrib/js_proto/internal/kernel_message_generator.cc) 66 | 67 | exports = Storage; 68 | -------------------------------------------------------------------------------- /experimental/runtime/kernel/textencoding_test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @fileoverview Tests for textdecoder.js. 3 | */ 4 | goog.module('protobuf.binary.TextDecoderTest'); 5 | 6 | goog.setTestOnly(); 7 | 8 | const {decode, encode} = goog.require('protobuf.binary.textencoding'); 9 | 10 | describe('Decode does', () => { 11 | it('return empty string for empty array', () => { 12 | expect(decode(new DataView(new ArrayBuffer(0)))).toEqual(''); 13 | }); 14 | 15 | it('throw on null being passed', () => { 16 | expect(() => decode(/** @type {!DataView} */ (/** @type {*} */ (null)))) 17 | .toThrow(); 18 | }); 19 | }); 20 | 21 | describe('Encode does', () => { 22 | it('return empty array for empty string', () => { 23 | expect(encode('')).toEqual(new Uint8Array(0)); 24 | }); 25 | 26 | it('throw on null being passed', () => { 27 | expect(() => encode(/** @type {string} */ (/** @type {*} */ (null)))) 28 | .toThrow(); 29 | }); 30 | }); 31 | 32 | /** @const {!TextEncoder} */ 33 | const textEncoder = new TextEncoder('utf-8'); 34 | 35 | /** 36 | * A Pair of string and Uint8Array representing the same data. 37 | * Each pair has the string value and its utf-8 bytes. 38 | */ 39 | class Pair { 40 | /** 41 | * Constructs a pair from a given string. 42 | * @param {string} s 43 | * @return {!Pair} 44 | */ 45 | static fromString(s) { 46 | return new Pair(s, textEncoder.encode(s).buffer); 47 | } 48 | /** 49 | * Constructs a pair from a given charCode. 50 | * @param {number} charCode 51 | * @return {!Pair} 52 | */ 53 | static fromCharCode(charCode) { 54 | return Pair.fromString(String.fromCharCode(charCode)); 55 | } 56 | 57 | /** 58 | * @param {string} stringValue 59 | * @param {!ArrayBuffer} bytes 60 | * @private 61 | */ 62 | constructor(stringValue, bytes) { 63 | /** @const @private {string} */ 64 | this.stringValue_ = stringValue; 65 | /** @const @private {!ArrayBuffer} */ 66 | this.bytes_ = bytes; 67 | } 68 | 69 | /** Ensures that a given pair encodes and decodes round trip*/ 70 | expectPairToMatch() { 71 | expect(decode(new DataView(this.bytes_))).toEqual(this.stringValue_); 72 | expect(encode(this.stringValue_)).toEqual(new Uint8Array(this.bytes_)); 73 | } 74 | } 75 | 76 | describe('textencoding does', () => { 77 | it('works for empty string', () => { 78 | Pair.fromString('').expectPairToMatch(); 79 | }); 80 | 81 | it('decode and encode random strings', () => { 82 | // 1 byte strings 83 | Pair.fromString('hello').expectPairToMatch(); 84 | Pair.fromString('HELLO1!'); 85 | 86 | // 2 byte String 87 | Pair.fromString('©').expectPairToMatch(); 88 | 89 | // 3 byte string 90 | Pair.fromString('❄').expectPairToMatch(); 91 | 92 | // 4 byte string 93 | Pair.fromString('😁').expectPairToMatch(); 94 | }); 95 | 96 | it('decode and encode 1 byte strings', () => { 97 | for (let i = 0; i < 0x80; i++) { 98 | Pair.fromCharCode(i).expectPairToMatch(); 99 | } 100 | }); 101 | 102 | it('decode and encode 2 byte strings', () => { 103 | for (let i = 0xC0; i < 0x7FF; i++) { 104 | Pair.fromCharCode(i).expectPairToMatch(); 105 | } 106 | }); 107 | 108 | it('decode and encode 3 byte strings', () => { 109 | for (let i = 0x7FF; i < 0x8FFF; i++) { 110 | Pair.fromCharCode(i).expectPairToMatch(); 111 | } 112 | }); 113 | }); 114 | -------------------------------------------------------------------------------- /experimental/runtime/kernel/typed_arrays.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @fileoverview Helper methods for typed arrays. 3 | */ 4 | goog.module('protobuf.binary.typedArrays'); 5 | 6 | const {assert} = goog.require('goog.asserts'); 7 | 8 | /** 9 | * @param {!ArrayBuffer} buffer1 10 | * @param {!ArrayBuffer} buffer2 11 | * @return {boolean} 12 | */ 13 | function arrayBufferEqual(buffer1, buffer2) { 14 | if (!buffer1 || !buffer2) { 15 | throw new Error('Buffer shouldn\'t be empty'); 16 | } 17 | 18 | const array1 = new Uint8Array(buffer1); 19 | const array2 = new Uint8Array(buffer2); 20 | 21 | return uint8ArrayEqual(array1, array2); 22 | } 23 | 24 | /** 25 | * @param {!Uint8Array} array1 26 | * @param {!Uint8Array} array2 27 | * @return {boolean} 28 | */ 29 | function uint8ArrayEqual(array1, array2) { 30 | if (array1 === array2) { 31 | return true; 32 | } 33 | 34 | if (array1.byteLength !== array2.byteLength) { 35 | return false; 36 | } 37 | 38 | for (let i = 0; i < array1.byteLength; i++) { 39 | if (array1[i] !== array2[i]) { 40 | return false; 41 | } 42 | } 43 | return true; 44 | } 45 | 46 | /** 47 | * ArrayBuffer.prototype.slice, but fallback to manual copy if missing. 48 | * @param {!ArrayBuffer} buffer 49 | * @param {number} start 50 | * @param {number=} end 51 | * @return {!ArrayBuffer} New array buffer with given the contents of `buffer`. 52 | */ 53 | function arrayBufferSlice(buffer, start, end = undefined) { 54 | // The fallback isn't fully compatible with ArrayBuffer.slice, enforce 55 | // strict requirements on start/end. 56 | // Spec: 57 | // https://www.ecma-international.org/ecma-262/6.0/#sec-arraybuffer.prototype.slice 58 | assert(start >= 0); 59 | assert(end === undefined || (end >= 0 && end <= buffer.byteLength)); 60 | assert((end === undefined ? buffer.byteLength : end) >= start); 61 | if (buffer.slice) { 62 | const slicedBuffer = buffer.slice(start, end); 63 | // The ArrayBuffer.prototype.slice function was flawed before iOS 12.2. This 64 | // causes 0-length results when passing undefined or a number greater 65 | // than 32 bits for the optional end value. In these cases, we fall back to 66 | // using our own slice implementation. 67 | // More details: https://bugs.webkit.org/show_bug.cgi?id=185127 68 | if (slicedBuffer.byteLength !== 0 || (start === end)) { 69 | return slicedBuffer; 70 | } 71 | } 72 | const realEnd = end == null ? buffer.byteLength : end; 73 | const length = realEnd - start; 74 | assert(length >= 0); 75 | const view = new Uint8Array(buffer, start, length); 76 | // A TypedArray constructed from another Typed array copies the data. 77 | const clone = new Uint8Array(view); 78 | 79 | return clone.buffer; 80 | } 81 | 82 | /** 83 | * Returns a new Uint8Array with the size and contents of the given 84 | * ArrayBufferView. ArrayBufferView is an interface implemented by DataView, 85 | * Uint8Array and all typed arrays. 86 | * @param {!ArrayBufferView} view 87 | * @return {!Uint8Array} 88 | */ 89 | function cloneArrayBufferView(view) { 90 | return new Uint8Array(arrayBufferSlice( 91 | view.buffer, view.byteOffset, view.byteOffset + view.byteLength)); 92 | } 93 | 94 | /** 95 | * Returns a 32 bit number for the corresponding Uint8Array. 96 | * @param {!Uint8Array} array 97 | * @return {number} 98 | */ 99 | function hashUint8Array(array) { 100 | const prime = 31; 101 | let result = 17; 102 | 103 | for (let i = 0; i < array.length; i++) { 104 | // '| 0' ensures signed 32 bits 105 | result = (result * prime + array[i]) | 0; 106 | } 107 | return result; 108 | } 109 | 110 | exports = { 111 | arrayBufferEqual, 112 | uint8ArrayEqual, 113 | arrayBufferSlice, 114 | cloneArrayBufferView, 115 | hashUint8Array, 116 | }; 117 | -------------------------------------------------------------------------------- /experimental/runtime/kernel/uint32_test_pairs.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @fileoverview Test data for int32 encoding and decoding. 3 | */ 4 | goog.module('protobuf.binary.uint32TestPairs'); 5 | 6 | const BufferDecoder = goog.require('protobuf.binary.BufferDecoder'); 7 | const {createBufferDecoder} = goog.require('protobuf.binary.bufferDecoderHelper'); 8 | 9 | /** 10 | * An array of Pairs of float values and their bit representation. 11 | * This is used to test encoding and decoding from/to the protobuf wire format. 12 | * @return {!Array<{name: string, intValue:number, bufferDecoder: 13 | * !BufferDecoder, error: (boolean|undefined), 14 | * skip_reader: (boolean|undefined), skip_writer: (boolean|undefined)}>} 15 | */ 16 | function getUint32Pairs() { 17 | const uint32Pairs = [ 18 | { 19 | name: 'zero', 20 | intValue: 0, 21 | bufferDecoder: createBufferDecoder(0x00), 22 | }, 23 | { 24 | name: 'one ', 25 | intValue: 1, 26 | bufferDecoder: createBufferDecoder(0x01), 27 | }, 28 | { 29 | name: 'max signed int 2^31 - 1', 30 | intValue: Math.pow(2, 31) - 1, 31 | bufferDecoder: createBufferDecoder(0xFF, 0xFF, 0xFF, 0xFF, 0x07), 32 | }, 33 | { 34 | name: 'max unsigned int 2^32 - 1', 35 | intValue: Math.pow(2, 32) - 1, 36 | bufferDecoder: createBufferDecoder(0xFF, 0xFF, 0xFF, 0xFF, 0x0F), 37 | }, 38 | { 39 | name: 'negative one', 40 | intValue: -1, 41 | bufferDecoder: createBufferDecoder(0xFF, 0xFF, 0xFF, 0xFF, 0x0F), 42 | skip_reader: true, 43 | }, 44 | { 45 | name: 'truncates more than 32 bits', 46 | intValue: Math.pow(2, 32) - 1, 47 | bufferDecoder: createBufferDecoder(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01), 48 | skip_writer: true, 49 | }, 50 | { 51 | name: 'truncates more than 32 bits (bit 33 set)', 52 | intValue: Math.pow(2, 28) - 1, 53 | bufferDecoder: createBufferDecoder(0xFF, 0xFF, 0xFF, 0xFF, 0x10), 54 | skip_writer: true, 55 | }, 56 | { 57 | name: 'errors out for 11 bytes', 58 | intValue: Math.pow(2, 32) - 1, 59 | bufferDecoder: createBufferDecoder( 60 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF), 61 | error: true, 62 | skip_writer: true, 63 | }, 64 | ]; 65 | return [...uint32Pairs]; 66 | } 67 | 68 | exports = {getUint32Pairs}; 69 | -------------------------------------------------------------------------------- /experimental/runtime/kernel/uint8arrays.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @fileoverview Helper methods for Uint8Arrays. 3 | */ 4 | goog.module('protobuf.binary.uint8arrays'); 5 | 6 | /** 7 | * Combines multiple bytes arrays (either Uint8Array or number array whose 8 | * values are bytes) into a single Uint8Array. 9 | * @param {!Array|!Array>} arrays 10 | * @return {!Uint8Array} 11 | */ 12 | function concatenateByteArrays(arrays) { 13 | let totalLength = 0; 14 | for (const array of arrays) { 15 | totalLength += array.length; 16 | } 17 | const result = new Uint8Array(totalLength); 18 | let offset = 0; 19 | for (const array of arrays) { 20 | result.set(array, offset); 21 | offset += array.length; 22 | } 23 | return result; 24 | } 25 | 26 | exports = { 27 | concatenateByteArrays, 28 | }; 29 | -------------------------------------------------------------------------------- /experimental/runtime/kernel/uint8arrays_test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @fileoverview Tests for uint8arrays.js. 3 | */ 4 | goog.module('protobuf.binary.Uint8ArraysTest'); 5 | 6 | goog.setTestOnly(); 7 | 8 | const {concatenateByteArrays} = goog.require('protobuf.binary.uint8arrays'); 9 | 10 | describe('concatenateByteArrays does', () => { 11 | it('concatenate empty array', () => { 12 | const byteArrays = []; 13 | expect(concatenateByteArrays(byteArrays)).toEqual(new Uint8Array(0)); 14 | }); 15 | 16 | it('concatenate Uint8Arrays', () => { 17 | const byteArrays = [new Uint8Array([0x01]), new Uint8Array([0x02])]; 18 | expect(concatenateByteArrays(byteArrays)).toEqual(new Uint8Array([ 19 | 0x01, 0x02 20 | ])); 21 | }); 22 | 23 | it('concatenate array of bytes', () => { 24 | const byteArrays = [[0x01], [0x02]]; 25 | expect(concatenateByteArrays(byteArrays)).toEqual(new Uint8Array([ 26 | 0x01, 0x02 27 | ])); 28 | }); 29 | 30 | it('concatenate array of non-bytes', () => { 31 | // Note in unchecked mode we produce invalid output for invalid inputs. 32 | // This test just documents our behavior in those cases. 33 | // These values might change at any point and are not considered 34 | // what the implementation should be doing here. 35 | const byteArrays = [[40.0], [256]]; 36 | expect(concatenateByteArrays(byteArrays)).toEqual(new Uint8Array([ 37 | 0x28, 0x00 38 | ])); 39 | }); 40 | 41 | it('throw for null array', () => { 42 | expect( 43 | () => concatenateByteArrays( 44 | /** @type {!Array} */ (/** @type {*} */ (null)))) 45 | .toThrow(); 46 | }); 47 | }); 48 | -------------------------------------------------------------------------------- /experimental/runtime/kernel/wire_type.js: -------------------------------------------------------------------------------- 1 | goog.module('protobuf.binary.WireType'); 2 | 3 | /** 4 | * Wire-format type codes, taken from proto2/public/wire_format_lite.h. 5 | * @enum {number} 6 | */ 7 | const WireType = { 8 | VARINT: 0, 9 | FIXED64: 1, 10 | DELIMITED: 2, 11 | START_GROUP: 3, 12 | END_GROUP: 4, 13 | FIXED32: 5, 14 | INVALID: 6 15 | }; 16 | 17 | exports = WireType; 18 | -------------------------------------------------------------------------------- /experimental/runtime/testing/ensure_custom_equality_test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @fileoverview Tests in this file will fail if our custom equality have not 3 | * been installed. 4 | * see b/131864652 5 | */ 6 | 7 | goog.module('protobuf.testing.ensureCustomEqualityTest'); 8 | 9 | const BufferDecoder = goog.require('protobuf.binary.BufferDecoder'); 10 | const ByteString = goog.require('protobuf.ByteString'); 11 | 12 | describe('Custom equality', () => { 13 | it('ensure that custom equality for ArrayBuffer is installed', () => { 14 | const buffer1 = new ArrayBuffer(4); 15 | const buffer2 = new ArrayBuffer(4); 16 | const array = new Uint8Array(buffer1); 17 | array[0] = 1; 18 | expect(buffer1).not.toEqual(buffer2); 19 | }); 20 | 21 | it('ensure that custom equality for ByteString is installed', () => { 22 | const HALLO_IN_BASE64 = 'aGFsbG8='; 23 | const BYTES_WITH_HALLO = new Uint8Array([ 24 | 'h'.charCodeAt(0), 25 | 'a'.charCodeAt(0), 26 | 'l'.charCodeAt(0), 27 | 'l'.charCodeAt(0), 28 | 'o'.charCodeAt(0), 29 | ]); 30 | 31 | const byteString1 = ByteString.fromBase64String(HALLO_IN_BASE64); 32 | const byteString2 = ByteString.fromArrayBufferView(BYTES_WITH_HALLO); 33 | expect(byteString1).toEqual(byteString2); 34 | }); 35 | 36 | it('ensure that custom equality for BufferDecoder is installed', () => { 37 | const arrayBuffer1 = new Uint8Array([0, 1, 2]).buffer; 38 | const arrayBuffer2 = new Uint8Array([0, 1, 2]).buffer; 39 | 40 | const bufferDecoder1 = BufferDecoder.fromArrayBuffer(arrayBuffer1); 41 | const bufferDecoder2 = BufferDecoder.fromArrayBuffer(arrayBuffer2); 42 | expect(bufferDecoder1).toEqual(bufferDecoder2); 43 | }); 44 | }); 45 | -------------------------------------------------------------------------------- /experimental/runtime/testing/jasmine_protobuf.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @fileoverview Installs our custom equality matchers in Jasmine. 3 | */ 4 | goog.module('protobuf.testing.jasmineProtoBuf'); 5 | 6 | const BufferDecoder = goog.require('protobuf.binary.BufferDecoder'); 7 | const ByteString = goog.require('protobuf.ByteString'); 8 | const {arrayBufferEqual} = goog.require('protobuf.binary.typedArrays'); 9 | 10 | /** 11 | * A function that ensures custom equality for ByteStrings. 12 | * Since Jasmine compare structure by default Bytestrings might be equal that 13 | * are not equal since ArrayBuffers still compare content in g3. 14 | * (Jasmine fix upstream: https://github.com/jasmine/jasmine/issues/1687) 15 | * Also ByteStrings that are equal might compare non equal in jasmine of the 16 | * base64 string has been initialized. 17 | * @param {*} first 18 | * @param {*} second 19 | * @return {boolean|undefined} 20 | */ 21 | const byteStringEquality = (first, second) => { 22 | if (second instanceof ByteString) { 23 | return second.equals(first); 24 | } 25 | 26 | // Intentionally not returning anything, this signals to jasmine that we 27 | // did not perform any equality on the given objects. 28 | }; 29 | 30 | /** 31 | * A function that ensures custom equality for ArrayBuffers. 32 | * By default Jasmine does not compare the content of an ArrayBuffer and thus 33 | * will return true for buffers with the same length but different content. 34 | * @param {*} first 35 | * @param {*} second 36 | * @return {boolean|undefined} 37 | */ 38 | const arrayBufferCustomEquality = (first, second) => { 39 | if (first instanceof ArrayBuffer && second instanceof ArrayBuffer) { 40 | return arrayBufferEqual(first, second); 41 | } 42 | // Intentionally not returning anything, this signals to jasmine that we 43 | // did not perform any equality on the given objects. 44 | }; 45 | 46 | /** 47 | * A function that ensures custom equality for ArrayBuffers. 48 | * By default Jasmine does not compare the content of an ArrayBuffer and thus 49 | * will return true for buffers with the same length but different content. 50 | * @param {*} first 51 | * @param {*} second 52 | * @return {boolean|undefined} 53 | */ 54 | const bufferDecoderCustomEquality = (first, second) => { 55 | if (first instanceof BufferDecoder && second instanceof BufferDecoder) { 56 | return first.asByteString().equals(second.asByteString()); 57 | } 58 | // Intentionally not returning anything, this signals to jasmine that we 59 | // did not perform any equality on the given objects. 60 | }; 61 | 62 | /** 63 | * Overrides the default ArrayBuffer toString method ([object ArrayBuffer]) with 64 | * a more readable representation. 65 | */ 66 | function overrideArrayBufferToString() { 67 | /** 68 | * Returns the hex values of the underlying bytes of the ArrayBuffer. 69 | * 70 | * @override 71 | * @return {string} 72 | */ 73 | ArrayBuffer.prototype.toString = function() { 74 | const arr = Array.from(new Uint8Array(this)); 75 | return 'ArrayBuffer[' + 76 | arr.map((b) => '0x' + (b & 0xFF).toString(16).toUpperCase()) 77 | .join(', ') + 78 | ']'; 79 | }; 80 | } 81 | 82 | beforeEach(() => { 83 | jasmine.addCustomEqualityTester(arrayBufferCustomEquality); 84 | jasmine.addCustomEqualityTester(bufferDecoderCustomEquality); 85 | jasmine.addCustomEqualityTester(byteStringEquality); 86 | 87 | overrideArrayBufferToString(); 88 | }); 89 | -------------------------------------------------------------------------------- /generator/BUILD.bazel: -------------------------------------------------------------------------------- 1 | cc_binary( 2 | name = "protoc-gen-js", 3 | srcs = [ 4 | "js_generator.cc", 5 | "js_generator.h", 6 | "protoc-gen-js.cc", 7 | "well_known_types_embed.cc", 8 | "well_known_types_embed.h", 9 | ], 10 | visibility = ["//visibility:public"], 11 | deps = [ 12 | "@com_google_protobuf//:protobuf", 13 | "@com_google_protobuf//src/google/protobuf/compiler:code_generator", 14 | "@com_google_protobuf//src/google/protobuf/io", 15 | "@com_google_protobuf//src/google/protobuf/io:printer", 16 | "@com_google_protobuf//src/google/protobuf/io:tokenizer", 17 | "@com_google_protobuf//:protoc_lib", 18 | "@abseil-cpp//absl/strings", 19 | "@abseil-cpp//absl/strings:str_format", 20 | ], 21 | ) 22 | 23 | 24 | -------------------------------------------------------------------------------- /generator/protoc-gen-js.cc: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://protobuf.dev/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | #include 32 | 33 | #include "generator/js_generator.h" 34 | 35 | int main(int argc, char** argv) { 36 | std::unique_ptr generator( 37 | new google::protobuf::compiler::js::Generator()); 38 | return google::protobuf::compiler::PluginMain(argc, argv, generator.get()); 39 | } 40 | -------------------------------------------------------------------------------- /generator/well_known_types_embed.h: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://protobuf.dev/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | #ifndef GOOGLE_PROTOBUF_COMPILER_JS_WELL_KNOWN_TYPES_EMBED_H__ 32 | #define GOOGLE_PROTOBUF_COMPILER_JS_WELL_KNOWN_TYPES_EMBED_H__ 33 | 34 | #include 35 | 36 | struct FileToc { 37 | const char* name; 38 | const char* data; 39 | }; 40 | 41 | extern struct FileToc well_known_types_js[]; 42 | 43 | #endif // GOOGLE_PROTOBUF_COMPILER_JS_WELL_KNOWN_TYPES_EMBED_H__ 44 | -------------------------------------------------------------------------------- /jasmine.json: -------------------------------------------------------------------------------- 1 | { 2 | "spec_dir": "", 3 | "spec_files": [ 4 | "*_test.js", 5 | "binary/*_test.js" 6 | ], 7 | "helpers": [ 8 | "node_modules/google-closure-library/closure/goog/bootstrap/nodejs.js", 9 | "node_loader.js", 10 | "deps.js", 11 | "google/protobuf/any.js", 12 | "google/protobuf/struct.js", 13 | "google/protobuf/timestamp.js", 14 | "testproto_libs1.js", 15 | "testproto_libs2.js" 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /node_loader.js: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://protobuf.dev/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | /** 32 | * @fileoverview Loader that handles goog.require() for Node.JS. 33 | */ 34 | 35 | var oldLoader = goog.global.CLOSURE_IMPORT_SCRIPT; 36 | 37 | goog.global.CLOSURE_IMPORT_SCRIPT = function(src, opt_sourceText) { 38 | if (opt_sourceText === undefined) { 39 | try { 40 | // Load from the current directory. 41 | require("./" + src); 42 | return true; 43 | } catch (e) { 44 | // Fall back to the Closure loader. 45 | } 46 | } 47 | 48 | return oldLoader(src, opt_sourceText); 49 | }; 50 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "google-protobuf", 3 | "version": "3.21.4", 4 | "description": "Protocol Buffers for JavaScript", 5 | "main": "google-protobuf.js", 6 | "files": [ 7 | "google/protobuf/*_pb.js", 8 | "google/protobuf/compiler/*_pb.js", 9 | "google-protobuf.js", 10 | "LICENSE.md", 11 | "LICENSE-asserts.md", 12 | "package.json", 13 | "README.md" 14 | ], 15 | "dependencies": {}, 16 | "devDependencies": { 17 | "glob": "~7.1.4", 18 | "google-closure-compiler": "~20190819.0.0", 19 | "google-closure-deps": "^20210406.0.0", 20 | "google-closure-library": "~20200315.0.0", 21 | "gulp": "~5.0.0", 22 | "jasmine": "~3.5.0" 23 | }, 24 | "scripts": { 25 | "build": "node ./node_modules/gulp/bin/gulp.js dist", 26 | "test": "node ./node_modules/gulp/bin/gulp.js test", 27 | "clean": "node ./node_modules/gulp/bin/gulp.js clean" 28 | }, 29 | "repository": { 30 | "type": "git", 31 | "url": "https://github.com/protocolbuffers/protobuf-javascript" 32 | }, 33 | "author": "Google Protocol Buffers Team", 34 | "license": "(BSD-3-Clause AND Apache-2.0)" 35 | } 36 | -------------------------------------------------------------------------------- /protobuf_javascript_release.bzl: -------------------------------------------------------------------------------- 1 | """Generates package naming variables for use with rules_pkg.""" 2 | 3 | load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain") 4 | load("@rules_pkg//pkg:providers.bzl", "PackageVariablesInfo") 5 | 6 | _PROTOBUF_JAVASCRIPT_VERSION = "3.21.4" 7 | 8 | def _package_naming_impl(ctx): 9 | values = {} 10 | values["version"] = _PROTOBUF_JAVASCRIPT_VERSION 11 | 12 | if ctx.attr.platform != "": 13 | values["platform"] = ctx.attr.platform 14 | return PackageVariablesInfo(values = values) 15 | 16 | # infer from the current cpp toolchain. 17 | toolchain = find_cpp_toolchain(ctx) 18 | cpu = toolchain.cpu 19 | system_name = toolchain.target_gnu_system_name 20 | 21 | # rename cpus to match what we want artifacts to be 22 | if cpu == "systemz": 23 | cpu = "s390_64" 24 | elif cpu == "aarch64": 25 | cpu = "aarch_64" 26 | elif cpu == "ppc64": 27 | cpu = "ppcle_64" 28 | 29 | # use the system name to determine the os and then create platform names 30 | if "apple" in system_name: 31 | values["platform"] = "osx-" + cpu 32 | elif "linux" in system_name: 33 | values["platform"] = "linux-" + cpu 34 | elif "mingw" in system_name: 35 | if cpu == "x86_64": 36 | values["platform"] = "win64" 37 | else: 38 | values["platform"] = "win32" 39 | else: 40 | values["platform"] = "unknown" 41 | 42 | return PackageVariablesInfo(values = values) 43 | 44 | package_naming = rule( 45 | implementation = _package_naming_impl, 46 | attrs = { 47 | # Necessary data dependency for find_cpp_toolchain. 48 | "_cc_toolchain": attr.label( 49 | default = Label("@bazel_tools//tools/cpp:current_cc_toolchain"), 50 | ), 51 | "platform": attr.string(), 52 | }, 53 | toolchains = ["@bazel_tools//tools/cpp:toolchain_type"], 54 | incompatible_use_toolchain_transition = True, 55 | ) 56 | -------------------------------------------------------------------------------- /protos/data.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://protobuf.dev/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Author: mwr@google.com (Mark Rawling) 32 | 33 | syntax = "proto2"; 34 | 35 | package jspb.test; 36 | 37 | option java_package = "com.google.apps.jspb.proto"; 38 | option java_multiple_files = true; 39 | 40 | // legacy data, must be nested 41 | message data { 42 | message NestedData { 43 | required string str = 1; 44 | } 45 | } 46 | 47 | // new data, does not require nesting 48 | message UnnestedData { 49 | required string str = 1; 50 | } 51 | -------------------------------------------------------------------------------- /protos/test10.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://protobuf.dev/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto3"; 32 | 33 | package jspb.exttest.strict.ten; 34 | 35 | import "protos/test9.proto"; 36 | 37 | message Simple10 { 38 | jspb.exttest.strict.nine.Simple9 a = 1; 39 | } 40 | -------------------------------------------------------------------------------- /protos/test11.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://protobuf.dev/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto2"; 32 | 33 | package jspb.exttest.reverse; 34 | 35 | message TestExtensionReverseOrderMessage1 { 36 | extend TestExtensionReverseOrderMessage2 { 37 | optional int32 a = 1; 38 | } 39 | message TestExtensionReverseOrderNestedMessage1 { 40 | extend TestExtensionReverseOrderMessage2 { 41 | optional int32 b = 2; 42 | } 43 | } 44 | } 45 | 46 | extend TestExtensionReverseOrderMessage2 { 47 | optional int32 c = 3; 48 | } 49 | 50 | message TestExtensionReverseOrderMessage2 { 51 | extensions 1 to 100; 52 | } 53 | -------------------------------------------------------------------------------- /protos/test12.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://protobuf.dev/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto2"; 32 | 33 | 34 | package jspb.circulartest; 35 | 36 | message MessageField1 { 37 | optional int32 a = 1; 38 | optional MessageField2 b = 2; 39 | } 40 | 41 | message MessageField2 { 42 | optional int32 a = 1; 43 | optional MessageField1 b = 2; 44 | } 45 | 46 | 47 | message RepeatedMessageField1 { 48 | optional int32 a = 1; 49 | optional RepeatedMessageField2 b = 2; 50 | } 51 | 52 | message RepeatedMessageField2 { 53 | optional int32 a = 1; 54 | repeated RepeatedMessageField1 b = 2; 55 | } 56 | 57 | message MapField1 { 58 | optional int32 a = 1; 59 | optional MapField2 b = 2; 60 | } 61 | 62 | message MapField2 { 63 | optional int32 a = 1; 64 | map b = 2; 65 | } 66 | 67 | message NestedMessage1 { 68 | optional NestedMessage2 b = 2; 69 | message NestedNestedMessage { 70 | optional int32 a = 1; 71 | } 72 | } 73 | 74 | message NestedMessage2 { 75 | optional int32 a = 1; 76 | optional NestedMessage1.NestedNestedMessage b = 2; 77 | } 78 | 79 | message NestedEnum1 { 80 | optional NestedEnum2 b = 2; 81 | enum NestedNestedEnum { 82 | UNDEFINED = 0; 83 | VALUE_1 = 1; 84 | } 85 | } 86 | 87 | message NestedEnum2 { 88 | optional int32 a = 1; 89 | optional NestedEnum1.NestedNestedEnum b = 2; 90 | } 91 | 92 | message ExtensionContainingType1 { 93 | optional int32 a = 1; 94 | optional ExtensionContainingType2 b = 2; 95 | extensions 99 to 100; 96 | } 97 | 98 | message ExtensionContainingType2 { 99 | optional int32 a = 1; 100 | extend ExtensionContainingType1 { 101 | optional int32 c = 99; 102 | } 103 | } 104 | 105 | message ExtensionField1 { 106 | optional int32 a = 1; 107 | optional ExtensionField2 b = 2; 108 | } 109 | 110 | message ExtensionField2 { 111 | optional int32 a = 1; 112 | extend ExtensionField3 { 113 | optional ExtensionField1 c = 99; 114 | } 115 | } 116 | 117 | message ExtensionField3 { 118 | extensions 99 to 100; 119 | } 120 | -------------------------------------------------------------------------------- /protos/test13.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://protobuf.dev/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto2"; 32 | 33 | package jspb.filenametest.package1; 34 | 35 | message TestMessage { 36 | extensions 1 to 100; 37 | } 38 | 39 | extend TestMessage { 40 | optional int32 a = 1; 41 | } 42 | 43 | enum TestEnum { 44 | VALUE_0 = 0; 45 | VALUE_1 = 1; 46 | } 47 | 48 | message TestLooooooooooooooooooooooooooooooooooooooooooooooooooooooongName1 { 49 | optional TestLooooooooooooooooooooooooooooooooooooooooooooooooooooooongName2 50 | a = 1; 51 | optional int32 b = 2; 52 | } 53 | 54 | message TestLooooooooooooooooooooooooooooooooooooooooooooooooooooooongName2 { 55 | optional TestLooooooooooooooooooooooooooooooooooooooooooooooooooooooongName3 56 | a = 1; 57 | optional int32 b = 2; 58 | } 59 | 60 | message TestLooooooooooooooooooooooooooooooooooooooooooooooooooooooongName3 { 61 | optional TestLooooooooooooooooooooooooooooooooooooooooooooooooooooooongName4 62 | a = 1; 63 | optional int32 b = 2; 64 | } 65 | 66 | message TestLooooooooooooooooooooooooooooooooooooooooooooooooooooooongName4 { 67 | optional TestLooooooooooooooooooooooooooooooooooooooooooooooooooooooongName1 68 | a = 1; 69 | optional int32 b = 2; 70 | } 71 | -------------------------------------------------------------------------------- /protos/test14.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://protobuf.dev/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto2"; 32 | 33 | package jspb.filenametest.package2; 34 | 35 | message TestMessage { 36 | optional int32 a = 1; 37 | } 38 | 39 | enum TestEnum { 40 | VALUE_0 = 0; 41 | VALUE_1 = 1; 42 | VALUE_2 = 2; 43 | } 44 | -------------------------------------------------------------------------------- /protos/test15.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://protobuf.dev/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto2"; 32 | 33 | package jspb.filenametest.package1; 34 | 35 | import "protos/test13.proto"; 36 | 37 | extend TestMessage { 38 | optional int32 b = 2; 39 | } 40 | -------------------------------------------------------------------------------- /protos/test2.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://protobuf.dev/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto2"; 32 | 33 | package jspb.test; 34 | 35 | import "protos/test.proto"; 36 | 37 | option java_package = "com.google.apps.jspb.proto"; 38 | option java_multiple_files = true; 39 | 40 | message TestExtensionsMessage { 41 | optional int32 intfield = 1; 42 | extensions 100 to max; 43 | } 44 | 45 | message ExtensionMessage { 46 | extend TestExtensionsMessage { 47 | optional ExtensionMessage ext_field = 100; 48 | } 49 | optional string ext1 = 1; 50 | } 51 | 52 | // Floating extensions are only supported when generating a _lib.js library. 53 | extend TestExtensionsMessage { 54 | optional ExtensionMessage floating_msg_field = 101; 55 | optional string floating_str_field = 102; 56 | } 57 | 58 | message ForeignNestedFieldMessage { 59 | optional Deeply.Nested.Message deeply_nested_message = 1; 60 | } 61 | -------------------------------------------------------------------------------- /protos/test3.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://protobuf.dev/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto2"; 32 | 33 | package jspb.exttest; 34 | 35 | option java_package = "com.google.apps.jspb.proto"; 36 | option java_multiple_files = true; 37 | 38 | message TestExtensionsMessage { 39 | optional int32 intfield = 1; 40 | extensions 100 to max; 41 | } 42 | 43 | message ExtensionMessage { 44 | extend TestExtensionsMessage { 45 | optional ExtensionMessage ext_field = 100; 46 | } 47 | optional string ext1 = 1; 48 | } 49 | 50 | extend TestExtensionsMessage { 51 | optional ExtensionMessage floating_msg_field = 101; 52 | optional string floating_str_field = 102; 53 | } 54 | -------------------------------------------------------------------------------- /protos/test4.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://protobuf.dev/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto2"; 32 | 33 | package jspb.exttest; 34 | 35 | import "protos/test3.proto"; 36 | 37 | option java_package = "com.google.apps.jspb.proto"; 38 | option java_multiple_files = true; 39 | 40 | extend TestExtensionsMessage { 41 | optional ExtensionMessage floating_msg_field_two = 103; 42 | } 43 | -------------------------------------------------------------------------------- /protos/test5.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://protobuf.dev/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto2"; 32 | 33 | package jspb.exttest.beta; 34 | 35 | option java_package = "com.google.apps.jspb.proto"; 36 | option java_multiple_files = true; 37 | 38 | message TestBetaExtensionsMessage { 39 | extensions 100 to max; 40 | } 41 | 42 | extend TestBetaExtensionsMessage { 43 | optional string floating_str_field = 101; 44 | } 45 | -------------------------------------------------------------------------------- /protos/test8.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://protobuf.dev/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto2"; 32 | 33 | package jspb.exttest.nested; 34 | 35 | option java_package = "com.google.apps.jspb.proto"; 36 | option java_multiple_files = true; 37 | 38 | message TestNestedExtensionsMessage { 39 | optional int32 intfield = 1; 40 | extensions 100 to max; 41 | } 42 | 43 | message TestOuterMessage { 44 | message NestedExtensionMessage { 45 | optional string ext1 = 1; 46 | } 47 | extend TestNestedExtensionsMessage { 48 | optional NestedExtensionMessage inner_extension = 100; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /protos/test9.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://protobuf.dev/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto2"; 32 | 33 | package jspb.exttest.strict.nine; 34 | 35 | message Simple9 { 36 | required string a_string = 1; 37 | repeated string a_repeated_string = 2; 38 | optional bool a_boolean = 3; 39 | } 40 | -------------------------------------------------------------------------------- /protos/testempty.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://protobuf.dev/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto2"; 32 | 33 | package javatests.com.google.apps.jspb; 34 | -------------------------------------------------------------------------------- /protos/testlargenumbers.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://protobuf.dev/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto3"; 32 | 33 | package jspb.test; 34 | 35 | 36 | message MessageWithLargeFieldNumbers { 37 | string a_string = 1; 38 | bool a_boolean = 900; 39 | int32 a_int = 5000; 40 | } 41 | -------------------------------------------------------------------------------- /test_bootstrap.js: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://protobuf.dev/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | /** 32 | * @fileoverview Sets flags for uncompiled JSUnit tests. 33 | */ 34 | 35 | /** 36 | * Set uncompiled flags. 37 | */ 38 | var CLOSURE_DEFINES = { 39 | // Enable the fromObject method on the message class. 40 | 'jspb.Message.GENERATE_FROM_OBJECT': true 41 | }; 42 | --------------------------------------------------------------------------------