Migrate the binary->JSON legs of the map and merge conformance tests to gtest.
This adds the binary->JSON leg of the ValidDataMap.<KEY>.<VALUE>.{Default,MissingDefault,NonDefault,Unordered,DuplicateKey,DuplicateKeyInMapEntry,DuplicateValueInMapEntry} tests (binary_valid_data_map_test.cc) and of RepeatedScalarMessageMerge, ValidDataMap.STRING.MESSAGE.MergeValue and ValidDataOneof.MESSAGE.Merge (binary_merge_test.cc) to the gtest-based `binary` suite, next to the binary->binary legs that migrated earlier, and deletes the legacy BinaryAndJsonConformanceSuiteImpl<M>::TestValidDataForMapType(), TestOverwriteMessageValueMap(), TestValidDataForRepeatedScalarMessage() and TestMergeOneofMessage() that still sent them. 488 requests under --maximum_edition 2023 (244 under the default edition) move: 476 [238] map legs (17 key/value types x 7 cases x 4 [2] message types) and 12 [6] merge legs; the test names ("<S>.<E>.ProtobufInput.<name>.JsonOutput"), the request bytes, the BINARY_TEST category, the priorities and the sets of message types are identical to the legacy ones, so the request goldens (//third_party/protobuf/conformance/migration) are unchanged.
Shape of the tests: one TEST_P per leg, the binary test followed by its JSON twin (<Name>Json), each an explicit EXPECT_THAT in the TEST_P body (go/totw/206, go/tott/788). The JSON twin is the binary leg's expression with `.SerializeBinary()` replaced by `.SerializeJson()` and the same matcher and expected message: `Testee(TestName("<Case>")).ParseBinary(message(), input).SerializeJson()` -> `Yields(ParsedPayload(EqualsBinaryProto(input)))` (the second entry for DuplicateKey) for the map tests, `EqualsBinaryProto(data.expected)` for the two merge tests built from MergeTestData and the same EqualsTextProto() text for RepeatedScalarMessageMerge. ParsedPayload() decodes the JSON response with the same JsonStringToMessage call and reports the same "JSON output we received from test was unparseable." / "Output was not equivalent to reference message: ..." texts as the legacy ParseJsonResponse()/differencer did. The RECOMMENDED byte-exact ValidDataOneofBinary.MESSAGE.Merge and the map wire-type mismatch tests were binary-only in the legacy suite and get no twin.
The merge inputs lose their last legacy caller, so, as the TODO in binary_test_util.h said, MergeTestData and its three builders (RepeatedScalarMessageMergeInput, MapMessageValueMergeData, OneofMessageMergeData, with the NestedMessageWithCorecursive helper and the field-number constants only they used) move from binary_test_util.{h,cc} into the anonymous namespace of binary_merge_test.cc, their unit tests leave binary_test_util_test.cc (the builders are now private to the alwayslink suite library, where a plain TEST() would run, and be counted, as part of every conformance run; the conformance tests exercise every path of them against the C++ testee), and the ValidDataMapTypes() comment no longer mentions the legacy suite. The four legacy functions, their declarations and their calls in RunAllTests() (the ValidDataMapTypes() loop and the three direct calls) are deleted from binary_json_conformance_suite.{h,cc}; the oneof functions (TestValidDataForOneofType(), TestOneofMessage()) stay for the next CL. The two test files' header comments now describe both legs and drop their TODOs.
Failure lists: no changes. The 71 ProtobufInput.*.JsonOutput entries of these tests in //net/proto2/util/converter/internal/conformance/esf_conformance_failures.txt (69 ValidDataMap.* incl. MergeValue, ValidDataOneof.MESSAGE.Merge, RepeatedScalarMessageMerge) keep matching byte-for-byte (36 x "JSON output we received from test was unparseable.", 34 x the MessageDifferencer "Output was not equivalent to reference message: ..." diffs and one message-less line; :esf_conformance_test reports no unexpected failure or success for them), as do the message-less failure_list_php.txt RepeatedScalarMessageMerge / ValidDataOneof.MESSAGE.Merge lines; no other list names these tests, and failure_lists/cpp_binary.txt needs no entry (the C++ testee passes them all).
PiperOrigin-RevId: 984337012
Copyright 2008 Google LLC
Protocol Buffers (a.k.a., protobuf) are Google's language-neutral, platform-neutral, extensible mechanism for serializing structured data. You can learn more about it in protobuf's documentation.
This README file contains protobuf installation instructions. To install protobuf, you need to install the protocol compiler (used to compile .proto files) and the protobuf runtime for your chosen programming language.
Most users will find working from supported releases to be the easiest path.
If you choose to work from the head revision of the main branch your build will occasionally be broken by source-incompatible changes and insufficiently-tested (and therefore broken) behavior.
If you are using C++ or otherwise need to build protobuf from source as a part of your project, you should pin to a release commit on a release branch.
This is because even release branches can experience some instability in between release commits.
Protobuf supports Bzlmod with Bazel 8 +. Users should specify a dependency on protobuf in their MODULE.bazel file as follows.
bazel_dep(name = "protobuf", version = <VERSION>)
Users can optionally override the repo name, such as for compatibility with WORKSPACE.
bazel_dep(name = "protobuf", version = <VERSION>, repo_name = "com_google_protobuf")
Users can also add the following to their legacy WORKSPACE file.
Note that with the release of 30.x there are a few more load statements to properly set up rules_java and rules_python.
http_archive(
name = "com_google_protobuf",
strip_prefix = "protobuf-VERSION",
sha256 = ...,
url = ...,
)
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
protobuf_deps()
load("@rules_java//java:rules_java_deps.bzl", "rules_java_dependencies")
rules_java_dependencies()
load("@rules_java//java:repositories.bzl", "rules_java_toolchains")
rules_java_toolchains()
load("@rules_python//python:repositories.bzl", "py_repositories")
py_repositories()
The protobuf compiler is written in C++. If you are using C++, please follow the C++ Installation Instructions to install protoc along with the C++ runtime.
For non-C++ users, the simplest way to install the protocol compiler is to download a pre-built binary from our GitHub release page.
In the downloads section of each release, you can find pre-built binaries in zip packages: protoc-$VERSION-$PLATFORM.zip. It contains the protoc binary as well as a set of standard .proto files distributed along with protobuf.
If you are looking for an old version that is not available in the release page, check out the Maven repository.
These pre-built binaries are only provided for released versions. If you want to use the github main version at HEAD, or you need to modify protobuf code, or you are using C++, it's recommended to build your own protoc binary from source.
If you would like to build protoc binary from source, see the C++ Installation Instructions.
Protobuf supports several different programming languages. For each programming language, you can find instructions in the corresponding source directory about how to install protobuf runtime for that specific language:
| Language | Source |
|---|---|
| C++ (include C++ runtime and protoc) | src |
| Java | java |
| Python | python |
| Objective-C | objectivec |
| C# | csharp |
| Ruby | ruby |
| Go | protocolbuffers/protobuf-go |
| PHP | php |
| Dart | dart-lang/protobuf |
| JavaScript | protocolbuffers/protobuf-javascript |
The best way to learn how to use protobuf is to follow the tutorials in our developer guide.
If you want to learn from code examples, take a look at the examples in the examples directory.
The complete documentation is available at the Protocol Buffers doc site.
Read about our version support policy to stay current on support timeframes for the language libraries.
To be alerted to upcoming changes in Protocol Buffers and connect with protobuf developers and users, join the Google Group.