From 6268c403d49828aef2eed5e60afa835ab3b3d4eb Mon Sep 17 00:00:00 2001 From: Michael Delago Date: Sun, 23 Jun 2024 13:55:37 -0400 Subject: [PATCH 01/11] change how asdf runs protoc --- asdf.lisp | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/asdf.lisp b/asdf.lisp index 6dab176d..49669d76 100644 --- a/asdf.lisp +++ b/asdf.lisp @@ -108,6 +108,17 @@ to PARENT-PATH." (resolve-relative-pathname path parent-path)) search-path)))) +(defun get-search-paths (protobuf-source-file) + "For a given protobuf-source-file, generate the default saerch paths that should be used." + (cons + (if (proto-pathname protobuf-source-file) + ;; If there's a pathname specified, just use the absolute directory of the pathname. + (directory-namestring (proto-input protobuf-source-file)) + ;; If there's no pathname, use the directory of the parent component. + (asdf/component:component-parent-pathname protobuf-source-file)) + ;; Attach the other search paths on the back + (resolve-search-path protobuf-source-file))) + (define-condition protobuf-compile-failed (compile-failed-error) () (:documentation "Condition signalled when translating a .proto file into Lisp code fails.")) @@ -117,25 +128,25 @@ to PARENT-PATH." (defmethod perform ((operation proto-to-lisp) (component protobuf-source-file)) (let* ((source-file (first (input-files operation component))) - (source-file-argument (if *protoc-relative-path* + (source-file-argument (if (proto-pathname component) (file-namestring source-file) (namestring source-file))) ;; Around methods on output-file may globally redirect output products, so we must call ;; that method instead of executing (component-pathname component). (output-file (first (output-files operation component))) - (search-path (cons (directory-namestring source-file) (resolve-search-path component))) + (search-path (get-search-paths component)) (command (format nil "protoc --proto_path=~{~A~^:~} --cl-pb_out=output-file=~A:~A ~A ~ --experimental_allow_proto3_optional" search-path (file-namestring output-file) (directory-namestring output-file) - source-file-argument))) + source-file-argument))) (multiple-value-bind (output error-output status) - (uiop:run-program command :output t :error-output :output :ignore-error-status t) - (declare (ignore output error-output)) + (uiop:run-program command :output '(:string :stripped t) :error-output :output :ignore-error-status t) + (declare (ignore error-output)) (unless (zerop status) (error 'protobuf-compile-failed - :description (format nil "Failed to compile proto file. Command: ~S" command) + :description (format nil "Failed to compile proto file. Command: ~S Error: ~S" command output) :context-format "~/asdf-action::format-action/" :context-arguments `((,operation . ,component))))))) From 100beb369171df5330616034b504b8e48c546f46 Mon Sep 17 00:00:00 2001 From: Michael Delago Date: Sun, 23 Jun 2024 13:55:54 -0400 Subject: [PATCH 02/11] add tests --- cl-protobufs.asd | 12 ++++- tests/deep-import-proto.proto | 19 ++++++++ tests/deep-import-test-1.proto | 12 +++++ tests/deep-import-test.lisp | 56 ++++++++++++++++++++++ tests/deep-import/deep-import-test-2.proto | 12 +++++ tests/deep-import/deep-import-test-3.proto | 12 +++++ 6 files changed, 122 insertions(+), 1 deletion(-) create mode 100644 tests/deep-import-proto.proto create mode 100644 tests/deep-import-test-1.proto create mode 100644 tests/deep-import-test.lisp create mode 100644 tests/deep-import/deep-import-test-2.proto create mode 100644 tests/deep-import/deep-import-test-3.proto diff --git a/cl-protobufs.asd b/cl-protobufs.asd index 46b0f7fa..9f1d232a 100644 --- a/cl-protobufs.asd +++ b/cl-protobufs.asd @@ -337,6 +337,16 @@ and functionality for working with them." :serial t :pathname "" :depends-on ("root-suite" "google-tests-proto") - :components ((:file "message-api-test")))) + :components ((:file "message-api-test"))) + (:module "deep-import" + :serial t + :pathname "" + :components ((:protobuf-source-file "deep-import-test-1") + (:protobuf-source-file "deep-import/deep-import-test-2") + (:protobuf-source-file "deep-import-test-3" + :proto-pathname "deep-import/deep-import-test-3.proto") + (:protobuf-source-file "deep-import-proto" + :proto-search-path ("deep-import/")) + (:file "deep-import-test")))) :perform (test-op (o c) (uiop:symbol-call '#:cl-protobufs.test '#:run-all))) diff --git a/tests/deep-import-proto.proto b/tests/deep-import-proto.proto new file mode 100644 index 00000000..437e2203 --- /dev/null +++ b/tests/deep-import-proto.proto @@ -0,0 +1,19 @@ +// Copyright 2020 Google LLC +// +// Use of this source code is governed by an MIT-style +// license that can be found in the LICENSE file or at +// https://opensource.org/licenses/MIT. + +syntax = "proto2"; + +package third_party.lisp.cl_protobufs.tests; + +import "deep-import-test-1.proto"; // Test proto +import "deep-import/deep-import-test-2.proto"; // Test proto +import "deep-import-test-3.proto"; // Test proto + +message DeepImportTest { + optional DeepImport1 import1 = 1; + optional DeepImport2 import2 = 2; + optional DeepImport3 import3 = 3; +} diff --git a/tests/deep-import-test-1.proto b/tests/deep-import-test-1.proto new file mode 100644 index 00000000..ce8a5f99 --- /dev/null +++ b/tests/deep-import-test-1.proto @@ -0,0 +1,12 @@ +// Copyright 2020 Google LLC +// +// Use of this source code is governed by an MIT-style +// license that can be found in the LICENSE file or at +// https://opensource.org/licenses/MIT. + +syntax = "proto2"; + +package third_party.lisp.cl_protobufs.tests; + +message DeepImport1 { +} diff --git a/tests/deep-import-test.lisp b/tests/deep-import-test.lisp new file mode 100644 index 00000000..45546506 --- /dev/null +++ b/tests/deep-import-test.lisp @@ -0,0 +1,56 @@ +;;; Copyright 2020 Google LLC +;;; +;;; Use of this source code is governed by an MIT-style +;;; license that can be found in the LICENSE file or at +;;; https://opensource.org/licenses/MIT. + +(defpackage #:cl-protobufs.test.deep-import + (:use #:cl + #:clunit) + (:local-nicknames (#:pb #:cl-protobufs.third-party.lisp.cl-protobufs.tests) + (#:pi #:cl-protobufs.implementation)) + (:export :run)) + +(in-package #:cl-protobufs.test.deep-import) + + +(defsuite deep-import-suite (cl-protobufs.test:root-suite)) + +(defun run (&key use-debugger) + "Run all tests in the test suite. +Parameters + USE-DEBUGGER: On assert failure bring up the debugger." + (clunit:run-suite 'deep-import-suite :use-debugger use-debugger + :signal-condition-on-fail t)) + +(deftest test-all-imports-are-included (deep-import-suite) + "Ensure file imports of the parent structure are properly read and stored with it's file descriptor." + (let* ((descriptor (cl-protobufs:find-file-descriptor 'pb:deep-import-proto)) + (imports (pi::proto-imports descriptor))) + ;; Confirms there are in-fact 3 imports on the testing deep-import-proto. + (assert-eql 3 (length imports)) + ;; This is defined next to the test proto. + (assert-equal "deep-import-test-1.proto" (first imports)) + ;; this is defined in deep-import as "deep-import/deep-import-test-2". + (assert-equal "deep-import/deep-import-test-2.proto" (second imports)) + ;; this is defined in deep-import as "deep-import-test-3" with the + ;; proto-pathname set relative to the testing directory. deep-import-proto + ;; sets a search path in order to find this file. + (assert-equal "deep-import-test-3.proto" (nth 2 imports)))) + +(deftest test-file-descriptors (deep-import-suite) + "Ensure generated lisp files add their PROTO-SOURCE-FILE to CL-PROTOBUFS.IMPLEMENTATION." + (assert-true + (cl-protobufs:find-file-descriptor #P"deep-import/deep-import-test-2.proto")) + (assert-true + (cl-protobufs:find-file-descriptor #P"deep-import-test-3.proto"))) + +(deftest test-make-sub-structures (deep-import-suite) + "Ensure imported sub-structure can be made." + (assert-true (pb:make-deep-import1)) + (assert-true (pb:make-deep-import2)) + (assert-true (pb:make-deep-import3))) + +(deftest test-make-structure (deep-import-suite) + "Ensure parent structure can be made." + (assert-true (pb:make-deep-import-test :import1 (pb:make-deep-import1)))) diff --git a/tests/deep-import/deep-import-test-2.proto b/tests/deep-import/deep-import-test-2.proto new file mode 100644 index 00000000..e558fd30 --- /dev/null +++ b/tests/deep-import/deep-import-test-2.proto @@ -0,0 +1,12 @@ +// Copyright 2020 Google LLC +// +// Use of this source code is governed by an MIT-style +// license that can be found in the LICENSE file or at +// https://opensource.org/licenses/MIT. + +syntax = "proto2"; + +package third_party.lisp.cl_protobufs.tests; + +message DeepImport2 { +} diff --git a/tests/deep-import/deep-import-test-3.proto b/tests/deep-import/deep-import-test-3.proto new file mode 100644 index 00000000..80fa8a6c --- /dev/null +++ b/tests/deep-import/deep-import-test-3.proto @@ -0,0 +1,12 @@ +// Copyright 2020 Google LLC +// +// Use of this source code is governed by an MIT-style +// license that can be found in the LICENSE file or at +// https://opensource.org/licenses/MIT. + +syntax = "proto2"; + +package third_party.lisp.cl_protobufs.tests; + +message DeepImport3 { +} From 3ef4af894df702a5ed727ceb2857b5471d95996a Mon Sep 17 00:00:00 2001 From: Michael Delago Date: Sun, 23 Jun 2024 13:58:16 -0400 Subject: [PATCH 03/11] typo --- asdf.lisp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/asdf.lisp b/asdf.lisp index 49669d76..81851a1e 100644 --- a/asdf.lisp +++ b/asdf.lisp @@ -109,7 +109,7 @@ to PARENT-PATH." search-path)))) (defun get-search-paths (protobuf-source-file) - "For a given protobuf-source-file, generate the default saerch paths that should be used." + "For a given protobuf-source-file, generate the default search paths that should be used." (cons (if (proto-pathname protobuf-source-file) ;; If there's a pathname specified, just use the absolute directory of the pathname. @@ -140,7 +140,7 @@ to PARENT-PATH." search-path (file-namestring output-file) (directory-namestring output-file) - source-file-argument))) + source-file-argument))) (multiple-value-bind (output error-output status) (uiop:run-program command :output '(:string :stripped t) :error-output :output :ignore-error-status t) (declare (ignore error-output)) From f1f77be87fe4432d93c210f7131058ae1940246b Mon Sep 17 00:00:00 2001 From: Michael Delago Date: Sun, 23 Jun 2024 14:05:07 -0400 Subject: [PATCH 04/11] add comment --- asdf.lisp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/asdf.lisp b/asdf.lisp index 81851a1e..afad1774 100644 --- a/asdf.lisp +++ b/asdf.lisp @@ -129,7 +129,11 @@ to PARENT-PATH." (defmethod perform ((operation proto-to-lisp) (component protobuf-source-file)) (let* ((source-file (first (input-files operation component))) (source-file-argument (if (proto-pathname component) + ;; If a PROTO-PATHNAME is specified in the component, use only the + ;; filename and type as the argument to protoc. (file-namestring source-file) + ;; If a PROTO-PATHNAME is not specified in the component, use the + ;; entire PROTOBUF-SOURCE-FILE + .proto as the argument to protoc. (namestring source-file))) ;; Around methods on output-file may globally redirect output products, so we must call ;; that method instead of executing (component-pathname component). From 65dd2836f6a7cddc3bdf2d1ca11a7b3fe4b280a9 Mon Sep 17 00:00:00 2001 From: Michael Delago Date: Sun, 23 Jun 2024 14:08:54 -0400 Subject: [PATCH 05/11] get-search-paths: better doc string --- asdf.lisp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/asdf.lisp b/asdf.lisp index afad1774..7db391a0 100644 --- a/asdf.lisp +++ b/asdf.lisp @@ -109,10 +109,17 @@ to PARENT-PATH." search-path)))) (defun get-search-paths (protobuf-source-file) - "For a given protobuf-source-file, generate the default search paths that should be used." + "For a given protobuf-source-file, generate the search paths that should be used. +To do this, it generates a search path from the component, as well as the +PROTO-SEACH-PATH specified in the asd component. + +If there's a PROTO-PATHNAME specified in the component, the generated search +path will be the absolute directory of the PROTO-PATHNAME. +If there's not a PROTO-PATHNAME specified in the component, the generated +search path will be the directory of the parent component." (cons (if (proto-pathname protobuf-source-file) - ;; If there's a pathname specified, just use the absolute directory of the pathname. + ;; If there's a pathname specified, use the absolute directory of the pathname. (directory-namestring (proto-input protobuf-source-file)) ;; If there's no pathname, use the directory of the parent component. (asdf/component:component-parent-pathname protobuf-source-file)) From 5d4c4b46e7c1aa1925ca5d0049ad5496682e2782 Mon Sep 17 00:00:00 2001 From: Michael Delago Date: Sun, 23 Jun 2024 14:56:38 -0400 Subject: [PATCH 06/11] update well-known types --- cl-protobufs.asd | 36 +- google/protobuf/any.proto | 19 +- google/protobuf/api.proto | 11 +- google/protobuf/descriptor.proto | 509 +++++++++++++++++++++++---- google/protobuf/duration.proto | 5 +- google/protobuf/empty.proto | 5 +- google/protobuf/field_mask.proto | 4 +- google/protobuf/source_context.proto | 4 +- google/protobuf/struct.proto | 10 +- google/protobuf/timestamp.proto | 16 +- google/protobuf/type.proto | 16 +- google/protobuf/wrappers.proto | 6 +- 12 files changed, 515 insertions(+), 126 deletions(-) diff --git a/cl-protobufs.asd b/cl-protobufs.asd index 9f1d232a..df3eed68 100644 --- a/cl-protobufs.asd +++ b/cl-protobufs.asd @@ -71,36 +71,24 @@ and functionality for working with them." :components ((:file "message-api"))) (:module "well-known-types" - :serial t :pathname "" :depends-on ("models" "misc") :components - ((:protobuf-source-file "descriptor" - :proto-pathname "google/protobuf/descriptor.proto") - (:protobuf-source-file "any" - :proto-pathname "google/protobuf/any.proto") - (:protobuf-source-file "source_context" - :proto-pathname "google/protobuf/source_context.proto") + ((:protobuf-source-file "google/protobuf/descriptor") + (:protobuf-source-file "google/protobuf/any") + (:protobuf-source-file "google/protobuf/source_context") #-ccl - (:protobuf-source-file "type" - :proto-pathname "google/protobuf/type.proto" + (:protobuf-source-file "google/protobuf/type" + :depends-on ("google/protobuf/any" "google/protobuf/source_context") :proto-search-path ("google/protobuf/")) #-ccl - (:protobuf-source-file "api" - :proto-pathname "google/protobuf/api.proto" - :proto-search-path ("google/protobuf/")) - (:protobuf-source-file "duration" - :proto-pathname "google/protobuf/duration.proto") - (:protobuf-source-file "empty" - :proto-pathname "google/protobuf/empty.proto") - (:protobuf-source-file "field_mask" - :proto-pathname "google/protobuf/field_mask.proto") - (:protobuf-source-file "timestamp" - :proto-pathname "google/protobuf/timestamp.proto") - (:protobuf-source-file "wrappers" - :proto-pathname "google/protobuf/wrappers.proto") - (:protobuf-source-file "struct" - :proto-pathname "google/protobuf/struct.proto") + (:protobuf-source-file "google/protobuf/api") + (:protobuf-source-file "google/protobuf/duration") + (:protobuf-source-file "google/protobuf/empty") + (:protobuf-source-file "google/protobuf/field_mask") + (:protobuf-source-file "google/protobuf/timestamp") + (:protobuf-source-file "google/protobuf/wrappers") + (:protobuf-source-file "google/protobuf/struct") (:file "well-known-types"))) (:module "json" :serial t diff --git a/google/protobuf/any.proto b/google/protobuf/any.proto index c9be8541..eff44e50 100644 --- a/google/protobuf/any.proto +++ b/google/protobuf/any.proto @@ -32,12 +32,12 @@ syntax = "proto3"; package google.protobuf; -option csharp_namespace = "Google.Protobuf.WellKnownTypes"; -option go_package = "github.com/golang/protobuf/ptypes/any"; +option go_package = "google.golang.org/protobuf/types/known/anypb"; option java_package = "com.google.protobuf"; option java_outer_classname = "AnyProto"; option java_multiple_files = true; option objc_class_prefix = "GPB"; +option csharp_namespace = "Google.Protobuf.WellKnownTypes"; // `Any` contains an arbitrary serialized protocol buffer message along with a // URL that describes the type of the serialized message. @@ -63,6 +63,10 @@ option objc_class_prefix = "GPB"; // if (any.is(Foo.class)) { // foo = any.unpack(Foo.class); // } +// // or ... +// if (any.isSameTypeAs(Foo.getDefaultInstance())) { +// foo = any.unpack(Foo.getDefaultInstance()); +// } // // Example 3: Pack and unpack a message in Python. // @@ -77,10 +81,13 @@ option objc_class_prefix = "GPB"; // Example 4: Pack and unpack a message in Go // // foo := &pb.Foo{...} -// any, err := ptypes.MarshalAny(foo) +// any, err := anypb.New(foo) +// if err != nil { +// ... +// } // ... // foo := &pb.Foo{} -// if err := ptypes.UnmarshalAny(any, foo); err != nil { +// if err := any.UnmarshalTo(foo); err != nil { // ... // } // @@ -90,7 +97,6 @@ option objc_class_prefix = "GPB"; // in the type URL, for example "foo.bar.com/x/y.z" will yield type // name "y.z". // -// // JSON // ==== // The JSON representation of an `Any` value uses the regular @@ -143,7 +149,8 @@ message Any { // // Note: this functionality is not currently available in the official // protobuf release, and it is not used for type URLs beginning with - // type.googleapis.com. + // type.googleapis.com. As of May 2023, there are no widely used type server + // implementations and no plans to implement one. // // Schemes other than `http`, `https` (or the empty scheme) might be // used with implementation specific semantics. diff --git a/google/protobuf/api.proto b/google/protobuf/api.proto index bb7d9932..42223516 100644 --- a/google/protobuf/api.proto +++ b/google/protobuf/api.proto @@ -32,15 +32,15 @@ syntax = "proto3"; package google.protobuf; -import "source_context.proto"; -import "type.proto"; +import "google/protobuf/source_context.proto"; +import "google/protobuf/type.proto"; -option csharp_namespace = "Google.Protobuf.WellKnownTypes"; option java_package = "com.google.protobuf"; option java_outer_classname = "ApiProto"; option java_multiple_files = true; option objc_class_prefix = "GPB"; -option go_package = "google.golang.org/genproto/protobuf/api;api"; +option csharp_namespace = "Google.Protobuf.WellKnownTypes"; +option go_package = "google.golang.org/protobuf/types/known/apipb"; // Api is a light-weight descriptor for an API Interface. // @@ -52,7 +52,6 @@ option go_package = "google.golang.org/genproto/protobuf/api;api"; // this message itself. See https://cloud.google.com/apis/design/glossary for // detailed terminology. message Api { - // The fully qualified name of this interface, including package name // followed by the interface's simple name. string name = 1; @@ -83,7 +82,6 @@ message Api { // be omitted. Zero major versions must only be used for // experimental, non-GA interfaces. // - // string version = 4; // Source context for the protocol buffer service represented by this @@ -99,7 +97,6 @@ message Api { // Method represents a method of an API interface. message Method { - // The simple name of this method. string name = 1; diff --git a/google/protobuf/descriptor.proto b/google/protobuf/descriptor.proto index d29fdec5..dfabac41 100644 --- a/google/protobuf/descriptor.proto +++ b/google/protobuf/descriptor.proto @@ -36,12 +36,11 @@ // A valid .proto file can be translated directly to a FileDescriptorProto // without any other information (e.g. without reading its imports). - syntax = "proto2"; package google.protobuf; -option go_package = "github.com/golang/protobuf/protoc-gen-go/descriptor;descriptor"; +option go_package = "google.golang.org/protobuf/types/descriptorpb"; option java_package = "com.google.protobuf"; option java_outer_classname = "DescriptorProtos"; option csharp_namespace = "Google.Protobuf.Reflection"; @@ -58,6 +57,42 @@ message FileDescriptorSet { repeated FileDescriptorProto file = 1; } +// The full set of known editions. +enum Edition { + // A placeholder for an unknown edition value. + EDITION_UNKNOWN = 0; + + // A placeholder edition for specifying default behaviors *before* a feature + // was first introduced. This is effectively an "infinite past". + EDITION_LEGACY = 900; + + // Legacy syntax "editions". These pre-date editions, but behave much like + // distinct editions. These can't be used to specify the edition of proto + // files, but feature definitions must supply proto2/proto3 defaults for + // backwards compatibility. + EDITION_PROTO2 = 998; + EDITION_PROTO3 = 999; + + // Editions that have been released. The specific values are arbitrary and + // should not be depended on, but they will always be time-ordered for easy + // comparison. + EDITION_2023 = 1000; + EDITION_2024 = 1001; + + // Placeholder editions for testing feature resolution. These should not be + // used or relyed on outside of tests. + EDITION_1_TEST_ONLY = 1; + EDITION_2_TEST_ONLY = 2; + EDITION_99997_TEST_ONLY = 99997; + EDITION_99998_TEST_ONLY = 99998; + EDITION_99999_TEST_ONLY = 99999; + + // Placeholder for specifying unbounded edition support. This should only + // ever be used by plugins that can expect to never require any changes to + // support a new edition. + EDITION_MAX = 0x7FFFFFFF; +} + // Describes a complete .proto file. message FileDescriptorProto { optional string name = 1; // file name, relative to root of source tree @@ -86,8 +121,13 @@ message FileDescriptorProto { optional SourceCodeInfo source_code_info = 9; // The syntax of the proto file. - // The supported values are "proto2" and "proto3". + // The supported values are "proto2", "proto3", and "editions". + // + // If `edition` is present, this value must be "editions". optional string syntax = 12; + + // The edition of the proto file. + optional Edition edition = 14; } // Describes a message type. @@ -129,6 +169,51 @@ message ExtensionRangeOptions { // The parser stores options it doesn't recognize here. See above. repeated UninterpretedOption uninterpreted_option = 999; + message Declaration { + // The extension number declared within the extension range. + optional int32 number = 1; + + // The fully-qualified name of the extension field. There must be a leading + // dot in front of the full name. + optional string full_name = 2; + + // The fully-qualified type name of the extension field. Unlike + // Metadata.type, Declaration.type must have a leading dot for messages + // and enums. + optional string type = 3; + + // If true, indicates that the number is reserved in the extension range, + // and any extension field with the number will fail to compile. Set this + // when a declared extension field is deleted. + optional bool reserved = 5; + + // If true, indicates that the extension must be defined as repeated. + // Otherwise the extension must be defined as optional. + optional bool repeated = 6; + + reserved 4; // removed is_repeated + } + + // For external users: DO NOT USE. We are in the process of open sourcing + // extension declaration and executing internal cleanups before it can be + // used externally. + repeated Declaration declaration = 2 [retention = RETENTION_SOURCE]; + + // Any features defined in the specific edition. + optional FeatureSet features = 50; + + // The verification state of the extension range. + enum VerificationState { + // All the extensions of the range must be declared. + DECLARATION = 0; + UNVERIFIED = 1; + } + + // The verification state of the range. + // TODO: flip the default to DECLARATION once all empty ranges + // are marked as UNVERIFIED. + optional VerificationState verification = 3 + [default = UNVERIFIED, retention = RETENTION_SOURCE]; // Clients can define custom options in extensions of this message. See above. extensions 1000 to max; @@ -153,9 +238,10 @@ message FieldDescriptorProto { TYPE_BOOL = 8; TYPE_STRING = 9; // Tag-delimited aggregate. - // Group type is deprecated and not supported in proto3. However, Proto3 + // Group type is deprecated and not supported after google.protobuf. However, Proto3 // implementations should still be able to parse the group wire format and - // treat group fields as unknown fields. + // treat group fields as unknown fields. In Editions, the group wire format + // can be enabled via the `message_encoding` feature. TYPE_GROUP = 10; TYPE_MESSAGE = 11; // Length-delimited aggregate. @@ -172,8 +258,11 @@ message FieldDescriptorProto { enum Label { // 0 is reserved for errors LABEL_OPTIONAL = 1; - LABEL_REQUIRED = 2; LABEL_REPEATED = 3; + // The required label is only allowed in google.protobuf. In proto3 and Editions + // it's explicitly prohibited. In Editions, the `field_presence` feature + // can be used to get this behavior. + LABEL_REQUIRED = 2; } optional string name = 1; @@ -199,7 +288,6 @@ message FieldDescriptorProto { // For booleans, "true" or "false". // For strings, contains the default text contents (not escaped in any way). // For bytes, contains the C escaped value. All bytes >= 128 are escaped. - // TODO(kenton): Base-64 encode? optional string default_value = 7; // If set, gives the index of a oneof in the containing type's oneof_decl @@ -217,12 +305,12 @@ message FieldDescriptorProto { // If true, this is a proto3 "optional". When a proto3 field is optional, it // tracks presence regardless of field type. // - // When proto3_optional is true, this field must be belong to a oneof to - // signal to old proto3 clients that presence is tracked for this field. This - // oneof is known as a "synthetic" oneof, and this field must be its sole - // member (each proto3 optional field gets its own synthetic oneof). Synthetic - // oneofs exist in the descriptor only, and do not generate any API. Synthetic - // oneofs must be ordered after all "real" oneofs. + // When proto3_optional is true, this field must belong to a oneof to signal + // to old proto3 clients that presence is tracked for this field. This oneof + // is known as a "synthetic" oneof, and this field must be its sole member + // (each proto3 optional field gets its own synthetic oneof). Synthetic oneofs + // exist in the descriptor only, and do not generate any API. Synthetic oneofs + // must be ordered after all "real" oneofs. // // For message fields, proto3_optional doesn't create any semantic change, // since non-repeated message fields always track presence. However it still @@ -306,7 +394,6 @@ message MethodDescriptorProto { optional bool server_streaming = 6 [default = false]; } - // =================================================================== // Options @@ -347,18 +434,17 @@ message FileOptions { // domain names. optional string java_package = 1; - - // If set, all the classes from the .proto file are wrapped in a single - // outer class with the given name. This applies to both Proto1 - // (equivalent to the old "--one_java_file" option) and Proto2 (where - // a .proto always translates to a single class, but you may want to - // explicitly choose the class name). + // Controls the name of the wrapper Java class generated for the .proto file. + // That class will always contain the .proto file's getDescriptor() method as + // well as any top-level extensions defined in the .proto file. + // If java_multiple_files is disabled, then all the other classes from the + // .proto file will be nested inside the single wrapper outer class. optional string java_outer_classname = 8; - // If set true, then the Java code generator will generate a separate .java + // If enabled, then the Java code generator will generate a separate .java // file for each top-level message, enum, and service defined in the .proto - // file. Thus, these types will *not* be nested inside the outer class - // named by java_outer_classname. However, the outer class will still be + // file. Thus, these types will *not* be nested inside the wrapper class + // named by java_outer_classname. However, the wrapper class will still be // generated to contain the file's getDescriptor() method as well as any // top-level extensions defined in the file. optional bool java_multiple_files = 10 [default = false]; @@ -366,15 +452,18 @@ message FileOptions { // This option does nothing. optional bool java_generate_equals_and_hash = 20 [deprecated=true]; - // If set true, then the Java2 code generator will generate code that - // throws an exception whenever an attempt is made to assign a non-UTF-8 - // byte sequence to a string field. - // Message reflection will do the same. - // However, an extension field still accepts non-UTF-8 byte sequences. - // This option has no effect on when used with the lite runtime. + // A proto2 file can set this to true to opt in to UTF-8 checking for Java, + // which will throw an exception if invalid UTF-8 is parsed from the wire or + // assigned to a string field. + // + // TODO: clarify exactly what kinds of field types this option + // applies to, and update these docs accordingly. + // + // Proto3 files already perform these checks. Setting the option explicitly to + // false has no effect: it cannot be used to opt proto3 files out of UTF-8 + // checks. optional bool java_string_check_utf8 = 27 [default = false]; - // Generated classes can be optimized for speed or code size. enum OptimizeMode { SPEED = 1; // Generate complete code for parsing, serialization, @@ -391,9 +480,6 @@ message FileOptions { // - Otherwise, the basename of the .proto file, without extension. optional string go_package = 11; - - - // Should generic services be generated in each language? "Generic" services // are not specific to any particular RPC system. They are generated by the // main code generators in each language (without additional plugins). @@ -407,7 +493,8 @@ message FileOptions { optional bool cc_generic_services = 16 [default = false]; optional bool java_generic_services = 17 [default = false]; optional bool py_generic_services = 18 [default = false]; - optional bool php_generic_services = 42 [default = false]; + reserved 42; // removed php_generic_services + reserved "php_generic_services"; // Is this file deprecated? // Depending on the target platform, this can emit Deprecated annotations @@ -419,7 +506,6 @@ message FileOptions { // only to generated classes for C++. optional bool cc_enable_arenas = 31 [default = true]; - // Sets the objective c class prefix which is prepended to all objective c // generated classes from this .proto. There is no default. optional string objc_class_prefix = 36; @@ -452,6 +538,8 @@ message FileOptions { // determining the ruby package. optional string ruby_package = 45; + // Any features defined in the specific edition. + optional FeatureSet features = 50; // The parser stores options it doesn't recognize here. // See the documentation for the "Options" section above. @@ -496,6 +584,8 @@ message MessageOptions { // this is a formalization for deprecating messages. optional bool deprecated = 3 [default = false]; + reserved 4, 5, 6; + // Whether the message is an automatically generated map entry type for the // maps field. // @@ -522,6 +612,20 @@ message MessageOptions { reserved 8; // javalite_serializable reserved 9; // javanano_as_lite + // Enable the legacy handling of JSON field name conflicts. This lowercases + // and strips underscored from the fields before comparison in proto3 only. + // The new behavior takes `json_name` into account and applies to proto2 as + // well. + // + // This should only be used as a temporary measure against broken builds due + // to the change in behavior for JSON field name conflicts. + // + // TODO This is legacy behavior we plan to remove once downstream + // teams have had time to migrate. + optional bool deprecated_legacy_json_field_conflicts = 11 [deprecated = true]; + + // Any features defined in the specific edition. + optional FeatureSet features = 12; // The parser stores options it doesn't recognize here. See above. repeated UninterpretedOption uninterpreted_option = 999; @@ -531,15 +635,24 @@ message MessageOptions { } message FieldOptions { + // NOTE: ctype is deprecated. Use `features.(pb.cpp).string_type` instead. // The ctype option instructs the C++ code generator to use a different // representation of the field than it normally would. See the specific - // options below. This option is not yet implemented in the open source - // release -- sorry, we'll try to include it in a future version! - optional CType ctype = 1 [default = STRING]; + // options below. This option is only implemented to support use of + // [ctype=CORD] and [ctype=STRING] (the default) on non-repeated fields of + // type "bytes" in the open source release. + // TODO: make ctype actually deprecated. + optional CType ctype = 1 [/*deprecated = true,*/ default = STRING]; enum CType { // Default mode. STRING = 0; + // The option [ctype=CORD] may be applied to a non-repeated field of type + // "bytes". It indicates that in C++, the data should be stored in a Cord + // instead of a string. For very large strings, this may reduce memory + // fragmentation. It may also allow better performance when parsing from a + // Cord, or when parsing with aliasing enabled, as the parsed Cord may then + // alias the original buffer. CORD = 1; STRING_PIECE = 2; @@ -548,7 +661,9 @@ message FieldOptions { // a more efficient representation on the wire. Rather than repeatedly // writing the tag and type for each element, the entire array is encoded as // a single length-delimited blob. In proto3, only explicit setting it to - // false will avoid using packed encoding. + // false will avoid using packed encoding. This option is prohibited in + // Editions, but the `repeated_field_encoding` feature can be used to control + // the behavior. optional bool packed = 2; // The jstype option determines the JavaScript type used for values of the @@ -591,19 +706,18 @@ message FieldOptions { // call from multiple threads concurrently, while non-const methods continue // to require exclusive access. // - // - // Note that implementations may choose not to check required fields within - // a lazy sub-message. That is, calling IsInitialized() on the outer message - // may return true even if the inner message has missing required fields. - // This is necessary because otherwise the inner message would have to be - // parsed in order to perform the check, defeating the purpose of lazy - // parsing. An implementation which chooses not to check required fields - // must be consistent about it. That is, for any particular sub-message, the - // implementation must either *always* check its required fields, or *never* - // check its required fields, regardless of whether or not the message has - // been parsed. + // Note that lazy message fields are still eagerly verified to check + // ill-formed wireformat or missing required fields. Calling IsInitialized() + // on the outer message would fail if the inner message has missing required + // fields. Failed verification would result in parsing failure (except when + // uninitialized messages are acceptable). optional bool lazy = 5 [default = false]; + // unverified_lazy does no correctness checks on the byte stream. This should + // only be used where lazy with verification is prohibitive for performance + // reasons. + optional bool unverified_lazy = 15 [default = false]; + // Is this field deprecated? // Depending on the target platform, this can emit Deprecated annotations // for accessors, or it will be completely ignored; in the very least, this @@ -613,6 +727,70 @@ message FieldOptions { // For Google-internal migration only. Do not use. optional bool weak = 10 [default = false]; + // Indicate that the field value should not be printed out when using debug + // formats, e.g. when the field contains sensitive credentials. + optional bool debug_redact = 16 [default = false]; + + // If set to RETENTION_SOURCE, the option will be omitted from the binary. + // Note: as of January 2023, support for this is in progress and does not yet + // have an effect (b/264593489). + enum OptionRetention { + RETENTION_UNKNOWN = 0; + RETENTION_RUNTIME = 1; + RETENTION_SOURCE = 2; + } + + optional OptionRetention retention = 17; + + // This indicates the types of entities that the field may apply to when used + // as an option. If it is unset, then the field may be freely used as an + // option on any kind of entity. Note: as of January 2023, support for this is + // in progress and does not yet have an effect (b/264593489). + enum OptionTargetType { + TARGET_TYPE_UNKNOWN = 0; + TARGET_TYPE_FILE = 1; + TARGET_TYPE_EXTENSION_RANGE = 2; + TARGET_TYPE_MESSAGE = 3; + TARGET_TYPE_FIELD = 4; + TARGET_TYPE_ONEOF = 5; + TARGET_TYPE_ENUM = 6; + TARGET_TYPE_ENUM_ENTRY = 7; + TARGET_TYPE_SERVICE = 8; + TARGET_TYPE_METHOD = 9; + } + + repeated OptionTargetType targets = 19; + + message EditionDefault { + optional Edition edition = 3; + optional string value = 2; // Textproto value. + } + repeated EditionDefault edition_defaults = 20; + + // Any features defined in the specific edition. + optional FeatureSet features = 21; + + // Information about the support window of a feature. + message FeatureSupport { + // The edition that this feature was first available in. In editions + // earlier than this one, the default assigned to EDITION_LEGACY will be + // used, and proto files will not be able to override it. + optional Edition edition_introduced = 1; + + // The edition this feature becomes deprecated in. Using this after this + // edition may trigger warnings. + optional Edition edition_deprecated = 2; + + // The deprecation warning text if this feature is used after the edition it + // was marked deprecated in. + optional string deprecation_warning = 3; + + // The edition this feature is no longer available in. In editions after + // this one, the last default assigned will be used, and proto files will + // not be able to override it. + optional Edition edition_removed = 4; + } + optional FeatureSupport feature_support = 22; // The parser stores options it doesn't recognize here. See above. repeated UninterpretedOption uninterpreted_option = 999; @@ -620,10 +798,14 @@ message FieldOptions { // Clients can define custom options in extensions of this message. See above. extensions 1000 to max; - reserved 4; // removed jtype + reserved 4; // removed jtype + reserved 18; // reserve target, target_obsolete_do_not_use } message OneofOptions { + // Any features defined in the specific edition. + optional FeatureSet features = 1; + // The parser stores options it doesn't recognize here. See above. repeated UninterpretedOption uninterpreted_option = 999; @@ -645,6 +827,17 @@ message EnumOptions { reserved 5; // javanano_as_lite + // Enable the legacy handling of JSON field name conflicts. This lowercases + // and strips underscored from the fields before comparison in proto3 only. + // The new behavior takes `json_name` into account and applies to proto2 as + // well. + // TODO Remove this legacy behavior once downstream teams have + // had time to migrate. + optional bool deprecated_legacy_json_field_conflicts = 6 [deprecated = true]; + + // Any features defined in the specific edition. + optional FeatureSet features = 7; + // The parser stores options it doesn't recognize here. See above. repeated UninterpretedOption uninterpreted_option = 999; @@ -659,6 +852,17 @@ message EnumValueOptions { // this is a formalization for deprecating enum values. optional bool deprecated = 1 [default = false]; + // Any features defined in the specific edition. + optional FeatureSet features = 2; + + // Indicate that fields annotated with this enum value should not be printed + // out when using debug formats, e.g. when the field contains sensitive + // credentials. + optional bool debug_redact = 3 [default = false]; + + // Information about the support window of a feature value. + optional FieldOptions.FeatureSupport feature_support = 4; + // The parser stores options it doesn't recognize here. See above. repeated UninterpretedOption uninterpreted_option = 999; @@ -668,6 +872,9 @@ message EnumValueOptions { message ServiceOptions { + // Any features defined in the specific edition. + optional FeatureSet features = 34; + // Note: Field numbers 1 through 32 are reserved for Google's internal RPC // framework. We apologize for hoarding these numbers to ourselves, but // we were already using them long before we decided to release Protocol @@ -710,6 +917,9 @@ message MethodOptions { optional IdempotencyLevel idempotency_level = 34 [default = IDEMPOTENCY_UNKNOWN]; + // Any features defined in the specific edition. + optional FeatureSet features = 35; + // The parser stores options it doesn't recognize here. See above. repeated UninterpretedOption uninterpreted_option = 999; @@ -717,7 +927,6 @@ message MethodOptions { extensions 1000 to max; } - // A message representing a option the parser does not recognize. This only // appears in options protos created by the compiler::Parser class. // DescriptorPool resolves these when building Descriptor objects. Therefore, @@ -728,8 +937,8 @@ message UninterpretedOption { // The name of the uninterpreted option. Each string represents a segment in // a dot-separated name. is_extension is true iff a segment represents an // extension (denoted with parentheses in options specs in .proto files). - // E.g.,{ ["foo", false], ["bar.baz", true], ["qux", false] } represents - // "foo.(bar.baz).qux". + // E.g.,{ ["foo", false], ["bar.baz", true], ["moo", false] } represents + // "foo.(bar.baz).moo". message NamePart { required string name_part = 1; required bool is_extension = 2; @@ -746,6 +955,172 @@ message UninterpretedOption { optional string aggregate_value = 8; } +// =================================================================== +// Features + +// TODO Enums in C++ gencode (and potentially other languages) are +// not well scoped. This means that each of the feature enums below can clash +// with each other. The short names we've chosen maximize call-site +// readability, but leave us very open to this scenario. A future feature will +// be designed and implemented to handle this, hopefully before we ever hit a +// conflict here. +message FeatureSet { + enum FieldPresence { + FIELD_PRESENCE_UNKNOWN = 0; + EXPLICIT = 1; + IMPLICIT = 2; + LEGACY_REQUIRED = 3; + } + optional FieldPresence field_presence = 1 [ + retention = RETENTION_RUNTIME, + targets = TARGET_TYPE_FIELD, + targets = TARGET_TYPE_FILE, + feature_support = { + edition_introduced: EDITION_2023, + }, + edition_defaults = { edition: EDITION_LEGACY, value: "EXPLICIT" }, + edition_defaults = { edition: EDITION_PROTO3, value: "IMPLICIT" }, + edition_defaults = { edition: EDITION_2023, value: "EXPLICIT" } + ]; + + enum EnumType { + ENUM_TYPE_UNKNOWN = 0; + OPEN = 1; + CLOSED = 2; + } + optional EnumType enum_type = 2 [ + retention = RETENTION_RUNTIME, + targets = TARGET_TYPE_ENUM, + targets = TARGET_TYPE_FILE, + feature_support = { + edition_introduced: EDITION_2023, + }, + edition_defaults = { edition: EDITION_LEGACY, value: "CLOSED" }, + edition_defaults = { edition: EDITION_PROTO3, value: "OPEN" } + ]; + + enum RepeatedFieldEncoding { + REPEATED_FIELD_ENCODING_UNKNOWN = 0; + PACKED = 1; + EXPANDED = 2; + } + optional RepeatedFieldEncoding repeated_field_encoding = 3 [ + retention = RETENTION_RUNTIME, + targets = TARGET_TYPE_FIELD, + targets = TARGET_TYPE_FILE, + feature_support = { + edition_introduced: EDITION_2023, + }, + edition_defaults = { edition: EDITION_LEGACY, value: "EXPANDED" }, + edition_defaults = { edition: EDITION_PROTO3, value: "PACKED" } + ]; + + enum Utf8Validation { + UTF8_VALIDATION_UNKNOWN = 0; + VERIFY = 2; + NONE = 3; + reserved 1; + } + optional Utf8Validation utf8_validation = 4 [ + retention = RETENTION_RUNTIME, + targets = TARGET_TYPE_FIELD, + targets = TARGET_TYPE_FILE, + feature_support = { + edition_introduced: EDITION_2023, + }, + edition_defaults = { edition: EDITION_LEGACY, value: "NONE" }, + edition_defaults = { edition: EDITION_PROTO3, value: "VERIFY" } + ]; + + enum MessageEncoding { + MESSAGE_ENCODING_UNKNOWN = 0; + LENGTH_PREFIXED = 1; + DELIMITED = 2; + } + optional MessageEncoding message_encoding = 5 [ + retention = RETENTION_RUNTIME, + targets = TARGET_TYPE_FIELD, + targets = TARGET_TYPE_FILE, + feature_support = { + edition_introduced: EDITION_2023, + }, + edition_defaults = { edition: EDITION_LEGACY, value: "LENGTH_PREFIXED" } + ]; + + enum JsonFormat { + JSON_FORMAT_UNKNOWN = 0; + ALLOW = 1; + LEGACY_BEST_EFFORT = 2; + } + optional JsonFormat json_format = 6 [ + retention = RETENTION_RUNTIME, + targets = TARGET_TYPE_MESSAGE, + targets = TARGET_TYPE_ENUM, + targets = TARGET_TYPE_FILE, + feature_support = { + edition_introduced: EDITION_2023, + }, + edition_defaults = { edition: EDITION_LEGACY, value: "LEGACY_BEST_EFFORT" }, + edition_defaults = { edition: EDITION_PROTO3, value: "ALLOW" } + ]; + + reserved 999; + + extensions 1000 to 9994 [ + declaration = { + number: 1000, + full_name: ".pb.cpp", + type: ".pb.CppFeatures" + }, + declaration = { + number: 1001, + full_name: ".pb.java", + type: ".pb.JavaFeatures" + }, + declaration = { number: 1002, full_name: ".pb.go", type: ".pb.GoFeatures" }, + declaration = { + number: 9990, + full_name: ".pb.proto1", + type: ".pb.Proto1Features" + } + ]; + + extensions 9995 to 9999; // For internal testing + extensions 10000; // for https://github.com/bufbuild/protobuf-es +} + +// A compiled specification for the defaults of a set of features. These +// messages are generated from FeatureSet extensions and can be used to seed +// feature resolution. The resolution with this object becomes a simple search +// for the closest matching edition, followed by proto merges. +message FeatureSetDefaults { + // A map from every known edition with a unique set of defaults to its + // defaults. Not all editions may be contained here. For a given edition, + // the defaults at the closest matching edition ordered at or before it should + // be used. This field must be in strict ascending order by edition. + message FeatureSetEditionDefault { + optional Edition edition = 3; + + // Defaults of features that can be overridden in this edition. + optional FeatureSet overridable_features = 4; + + // Defaults of features that can't be overridden in this edition. + optional FeatureSet fixed_features = 5; + + reserved 1, 2; + reserved "features"; + } + repeated FeatureSetEditionDefault defaults = 1; + + // The minimum supported edition (inclusive) when this was constructed. + // Editions before this will not have defaults. + optional Edition minimum_edition = 4; + + // The maximum known edition (inclusive) when this was constructed. Editions + // after this will not have reliable defaults. + optional Edition maximum_edition = 5; +} + // =================================================================== // Optional source code info @@ -801,8 +1176,8 @@ message SourceCodeInfo { // location. // // Each element is a field number or an index. They form a path from - // the root FileDescriptorProto to the place where the definition. For - // example, this path: + // the root FileDescriptorProto to the place where the definition appears. + // For example, this path: // [ 4, 3, 2, 7, 1 ] // refers to: // file.message_type(3) // 4, 3 @@ -856,13 +1231,13 @@ message SourceCodeInfo { // // Comment attached to baz. // // Another line attached to baz. // - // // Comment attached to qux. + // // Comment attached to moo. // // - // // Another line attached to qux. - // optional double qux = 4; + // // Another line attached to moo. + // optional double moo = 4; // // // Detached comment for corge. This is not leading or trailing comments - // // to qux or corge because there are blank lines separating it from + // // to moo or corge because there are blank lines separating it from // // both. // // // Detached comment for corge paragraph 2. @@ -902,8 +1277,20 @@ message GeneratedCodeInfo { optional int32 begin = 3; // Identifies the ending offset in bytes in the generated code that - // relates to the identified offset. The end offset should be one past + // relates to the identified object. The end offset should be one past // the last relevant byte (so the length of the text = end - begin). optional int32 end = 4; + + // Represents the identified object's effect on the element in the original + // .proto file. + enum Semantic { + // There is no effect or the effect is indescribable. + NONE = 0; + // The element is set or otherwise mutated. + SET = 1; + // An alias to the element is returned. + ALIAS = 2; + } + optional Semantic semantic = 5; } } diff --git a/google/protobuf/duration.proto b/google/protobuf/duration.proto index 99cb102c..41f40c22 100644 --- a/google/protobuf/duration.proto +++ b/google/protobuf/duration.proto @@ -32,13 +32,13 @@ syntax = "proto3"; package google.protobuf; -option csharp_namespace = "Google.Protobuf.WellKnownTypes"; option cc_enable_arenas = true; -option go_package = "github.com/golang/protobuf/ptypes/duration"; +option go_package = "google.golang.org/protobuf/types/known/durationpb"; option java_package = "com.google.protobuf"; option java_outer_classname = "DurationProto"; option java_multiple_files = true; option objc_class_prefix = "GPB"; +option csharp_namespace = "Google.Protobuf.WellKnownTypes"; // A Duration represents a signed, fixed-length span of time represented // as a count of seconds and fractions of seconds at nanosecond @@ -99,7 +99,6 @@ option objc_class_prefix = "GPB"; // be expressed in JSON format as "3.000000001s", and 3 seconds and 1 // microsecond should be expressed in JSON format as "3.000001s". // -// message Duration { // Signed seconds of the span of time. Must be from -315,576,000,000 // to +315,576,000,000 inclusive. Note: these bounds are computed from: diff --git a/google/protobuf/empty.proto b/google/protobuf/empty.proto index 03cacd23..b87c89dc 100644 --- a/google/protobuf/empty.proto +++ b/google/protobuf/empty.proto @@ -32,12 +32,12 @@ syntax = "proto3"; package google.protobuf; -option csharp_namespace = "Google.Protobuf.WellKnownTypes"; -option go_package = "github.com/golang/protobuf/ptypes/empty"; +option go_package = "google.golang.org/protobuf/types/known/emptypb"; option java_package = "com.google.protobuf"; option java_outer_classname = "EmptyProto"; option java_multiple_files = true; option objc_class_prefix = "GPB"; +option csharp_namespace = "Google.Protobuf.WellKnownTypes"; option cc_enable_arenas = true; // A generic empty message that you can re-use to avoid defining duplicated @@ -48,5 +48,4 @@ option cc_enable_arenas = true; // rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty); // } // -// The JSON representation for `Empty` is empty JSON object `{}`. message Empty {} diff --git a/google/protobuf/field_mask.proto b/google/protobuf/field_mask.proto index baac8744..b28334b9 100644 --- a/google/protobuf/field_mask.proto +++ b/google/protobuf/field_mask.proto @@ -32,12 +32,12 @@ syntax = "proto3"; package google.protobuf; -option csharp_namespace = "Google.Protobuf.WellKnownTypes"; option java_package = "com.google.protobuf"; option java_outer_classname = "FieldMaskProto"; option java_multiple_files = true; option objc_class_prefix = "GPB"; -option go_package = "google.golang.org/genproto/protobuf/field_mask;field_mask"; +option csharp_namespace = "Google.Protobuf.WellKnownTypes"; +option go_package = "google.golang.org/protobuf/types/known/fieldmaskpb"; option cc_enable_arenas = true; // `FieldMask` represents a set of symbolic field paths, for example: diff --git a/google/protobuf/source_context.proto b/google/protobuf/source_context.proto index f3b2c966..135f50fe 100644 --- a/google/protobuf/source_context.proto +++ b/google/protobuf/source_context.proto @@ -32,12 +32,12 @@ syntax = "proto3"; package google.protobuf; -option csharp_namespace = "Google.Protobuf.WellKnownTypes"; option java_package = "com.google.protobuf"; option java_outer_classname = "SourceContextProto"; option java_multiple_files = true; option objc_class_prefix = "GPB"; -option go_package = "google.golang.org/genproto/protobuf/source_context;source_context"; +option csharp_namespace = "Google.Protobuf.WellKnownTypes"; +option go_package = "google.golang.org/protobuf/types/known/sourcecontextpb"; // `SourceContext` represents information about the source of a // protobuf element, like the file in which it is defined. diff --git a/google/protobuf/struct.proto b/google/protobuf/struct.proto index 5bd4c8c7..1bf0c1ad 100644 --- a/google/protobuf/struct.proto +++ b/google/protobuf/struct.proto @@ -32,13 +32,13 @@ syntax = "proto3"; package google.protobuf; -option csharp_namespace = "Google.Protobuf.WellKnownTypes"; option cc_enable_arenas = true; option go_package = "google.golang.org/protobuf/types/known/structpb"; option java_package = "com.google.protobuf"; option java_outer_classname = "StructProto"; option java_multiple_files = true; option objc_class_prefix = "GPB"; +option csharp_namespace = "Google.Protobuf.WellKnownTypes"; // `Struct` represents a structured data value, consisting of fields // which map to dynamically typed values. In some languages, `Struct` @@ -55,8 +55,8 @@ message Struct { // `Value` represents a dynamically typed value which can be either // null, a number, a string, a boolean, a recursive struct value, or a -// list of values. A producer of value is expected to set one of that -// variants, absence of any variant indicates an error. +// list of values. A producer of value is expected to set one of these +// variants. Absence of any variant indicates an error. // // The JSON representation for `Value` is JSON value. message Value { @@ -80,7 +80,7 @@ message Value { // `NullValue` is a singleton enumeration to represent the null value for the // `Value` type union. // -// The JSON representation for `NullValue` is JSON `null`. +// The JSON representation for `NullValue` is JSON `null`. enum NullValue { // Null value. NULL_VALUE = 0; @@ -92,4 +92,4 @@ enum NullValue { message ListValue { // Repeated field of dynamically typed values. repeated Value values = 1; -} \ No newline at end of file +} diff --git a/google/protobuf/timestamp.proto b/google/protobuf/timestamp.proto index cd357864..fd0bc07d 100644 --- a/google/protobuf/timestamp.proto +++ b/google/protobuf/timestamp.proto @@ -32,13 +32,13 @@ syntax = "proto3"; package google.protobuf; -option csharp_namespace = "Google.Protobuf.WellKnownTypes"; option cc_enable_arenas = true; -option go_package = "github.com/golang/protobuf/ptypes/timestamp"; +option go_package = "google.golang.org/protobuf/types/known/timestamppb"; option java_package = "com.google.protobuf"; option java_outer_classname = "TimestampProto"; option java_multiple_files = true; option objc_class_prefix = "GPB"; +option csharp_namespace = "Google.Protobuf.WellKnownTypes"; // A Timestamp represents a point in time independent of any time zone or local // calendar, encoded as a count of seconds and fractions of seconds at @@ -90,8 +90,15 @@ option objc_class_prefix = "GPB"; // Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000) // .setNanos((int) ((millis % 1000) * 1000000)).build(); // +// Example 5: Compute Timestamp from Java `Instant.now()`. +// +// Instant now = Instant.now(); // -// Example 5: Compute Timestamp from current time in Python. +// Timestamp timestamp = +// Timestamp.newBuilder().setSeconds(now.getEpochSecond()) +// .setNanos(now.getNano()).build(); +// +// Example 6: Compute Timestamp from current time in Python. // // timestamp = Timestamp() // timestamp.GetCurrentTime() @@ -120,10 +127,9 @@ option objc_class_prefix = "GPB"; // [`strftime`](https://docs.python.org/2/library/time.html#time.strftime) with // the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one can use // the Joda Time's [`ISODateTimeFormat.dateTime()`]( -// http://www.joda.org/joda-time/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime%2D%2D +// http://joda-time.sourceforge.net/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime() // ) to obtain a formatter capable of generating timestamps in this format. // -// message Timestamp { // Represents seconds of UTC time since Unix epoch // 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to diff --git a/google/protobuf/type.proto b/google/protobuf/type.proto index 40d701ff..48cb11e7 100644 --- a/google/protobuf/type.proto +++ b/google/protobuf/type.proto @@ -32,16 +32,16 @@ syntax = "proto3"; package google.protobuf; -import "any.proto"; -import "source_context.proto"; +import "google/protobuf/any.proto"; +import "google/protobuf/source_context.proto"; -option csharp_namespace = "Google.Protobuf.WellKnownTypes"; option cc_enable_arenas = true; option java_package = "com.google.protobuf"; option java_outer_classname = "TypeProto"; option java_multiple_files = true; option objc_class_prefix = "GPB"; -option go_package = "google.golang.org/genproto/protobuf/ptype;ptype"; +option csharp_namespace = "Google.Protobuf.WellKnownTypes"; +option go_package = "google.golang.org/protobuf/types/known/typepb"; // A protocol buffer message type. message Type { @@ -57,6 +57,8 @@ message Type { SourceContext source_context = 5; // The source syntax. Syntax syntax = 6; + // The source edition string, only valid when syntax is SYNTAX_EDITIONS. + string edition = 7; } // A single field of a message type. @@ -113,7 +115,7 @@ message Field { CARDINALITY_REQUIRED = 2; // For repeated fields. CARDINALITY_REPEATED = 3; - }; + } // The field type. Kind kind = 1; @@ -151,6 +153,8 @@ message Enum { SourceContext source_context = 4; // The source syntax. Syntax syntax = 5; + // The source edition string, only valid when syntax is SYNTAX_EDITIONS. + string edition = 6; } // Enum value definition. @@ -184,4 +188,6 @@ enum Syntax { SYNTAX_PROTO2 = 0; // Syntax `proto3`. SYNTAX_PROTO3 = 1; + // Syntax `editions`. + SYNTAX_EDITIONS = 2; } diff --git a/google/protobuf/wrappers.proto b/google/protobuf/wrappers.proto index 9ee41e38..1959fa55 100644 --- a/google/protobuf/wrappers.proto +++ b/google/protobuf/wrappers.proto @@ -27,7 +27,7 @@ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - +// // Wrappers for primitive (non-message) types. These types are useful // for embedding primitives in the `google.protobuf.Any` type and for places // where we need to distinguish between the absence of a primitive @@ -42,13 +42,13 @@ syntax = "proto3"; package google.protobuf; -option csharp_namespace = "Google.Protobuf.WellKnownTypes"; option cc_enable_arenas = true; -option go_package = "github.com/golang/protobuf/ptypes/wrappers"; +option go_package = "google.golang.org/protobuf/types/known/wrapperspb"; option java_package = "com.google.protobuf"; option java_outer_classname = "WrappersProto"; option java_multiple_files = true; option objc_class_prefix = "GPB"; +option csharp_namespace = "Google.Protobuf.WellKnownTypes"; // Wrapper message for `double`. // From 25acbbfca4a98db2c65231c35bc82c879aaa55b0 Mon Sep 17 00:00:00 2001 From: Michael Delago Date: Sun, 23 Jun 2024 15:07:42 -0400 Subject: [PATCH 07/11] remove unnecessary search path --- cl-protobufs.asd | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cl-protobufs.asd b/cl-protobufs.asd index df3eed68..8fbab4f8 100644 --- a/cl-protobufs.asd +++ b/cl-protobufs.asd @@ -79,8 +79,7 @@ and functionality for working with them." (:protobuf-source-file "google/protobuf/source_context") #-ccl (:protobuf-source-file "google/protobuf/type" - :depends-on ("google/protobuf/any" "google/protobuf/source_context") - :proto-search-path ("google/protobuf/")) + :depends-on ("google/protobuf/any" "google/protobuf/source_context")) #-ccl (:protobuf-source-file "google/protobuf/api") (:protobuf-source-file "google/protobuf/duration") From 5279a7915f2edb287e28bc07e0720774dab8af25 Mon Sep 17 00:00:00 2001 From: Mike Delago Date: Wed, 3 Jul 2024 09:07:43 -0400 Subject: [PATCH 08/11] Address style review --- asdf.lisp | 26 +++++++++++++------------- tests/deep-import-test.lisp | 8 ++++---- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/asdf.lisp b/asdf.lisp index 7db391a0..5c81c785 100644 --- a/asdf.lisp +++ b/asdf.lisp @@ -109,22 +109,22 @@ to PARENT-PATH." search-path)))) (defun get-search-paths (protobuf-source-file) - "For a given protobuf-source-file, generate the search paths that should be used. -To do this, it generates a search path from the component, as well as the -PROTO-SEACH-PATH specified in the asd component. + "For a given PROTOBUF-SOURCE-FILE, generate the search paths that should be used. +To do this, it creates a search path from the component, as well as the +:proto-search-path specified in the asd component. -If there's a PROTO-PATHNAME specified in the component, the generated search -path will be the absolute directory of the PROTO-PATHNAME. -If there's not a PROTO-PATHNAME specified in the component, the generated +If there's a :proto-pathname specified in the component, the generated search +path will be the absolute directory of the :proto-pathname. +If there's not a :proto-pathname specified in the component, the generated search path will be the directory of the parent component." (cons - (if (proto-pathname protobuf-source-file) - ;; If there's a pathname specified, use the absolute directory of the pathname. - (directory-namestring (proto-input protobuf-source-file)) - ;; If there's no pathname, use the directory of the parent component. - (asdf/component:component-parent-pathname protobuf-source-file)) - ;; Attach the other search paths on the back - (resolve-search-path protobuf-source-file))) + (if (proto-pathname protobuf-source-file) + ;; If there's a pathname specified, use the absolute directory of the pathname. + (directory-namestring (proto-input protobuf-source-file)) + ;; If there's no pathname, use the directory of the parent component. + (asdf/component:component-parent-pathname protobuf-source-file)) + ;; Attach the other search paths on the back + (resolve-search-path protobuf-source-file))) (define-condition protobuf-compile-failed (compile-failed-error) () diff --git a/tests/deep-import-test.lisp b/tests/deep-import-test.lisp index 45546506..726c020d 100644 --- a/tests/deep-import-test.lisp +++ b/tests/deep-import-test.lisp @@ -24,7 +24,7 @@ Parameters :signal-condition-on-fail t)) (deftest test-all-imports-are-included (deep-import-suite) - "Ensure file imports of the parent structure are properly read and stored with it's file descriptor." + "Ensure file imports of the parent structure are properly read and stored with its file descriptor." (let* ((descriptor (cl-protobufs:find-file-descriptor 'pb:deep-import-proto)) (imports (pi::proto-imports descriptor))) ;; Confirms there are in-fact 3 imports on the testing deep-import-proto. @@ -41,9 +41,9 @@ Parameters (deftest test-file-descriptors (deep-import-suite) "Ensure generated lisp files add their PROTO-SOURCE-FILE to CL-PROTOBUFS.IMPLEMENTATION." (assert-true - (cl-protobufs:find-file-descriptor #P"deep-import/deep-import-test-2.proto")) - (assert-true - (cl-protobufs:find-file-descriptor #P"deep-import-test-3.proto"))) + (cl-protobufs:find-file-descriptor #P"deep-import/deep-import-test-2.proto")) + (assert-true + (cl-protobufs:find-file-descriptor #P"deep-import-test-3.proto"))) (deftest test-make-sub-structures (deep-import-suite) "Ensure imported sub-structure can be made." From 3e9fc7fca215506ebbb8f5430bfd6ca11cd3fb9f Mon Sep 17 00:00:00 2001 From: Mike Delago Date: Wed, 3 Jul 2024 09:44:34 -0400 Subject: [PATCH 09/11] revert "update well-known types" --- cl-protobufs.asd | 37 +- google/protobuf/any.proto | 19 +- google/protobuf/api.proto | 11 +- google/protobuf/descriptor.proto | 509 ++++----------------------- google/protobuf/duration.proto | 5 +- google/protobuf/empty.proto | 5 +- google/protobuf/field_mask.proto | 4 +- google/protobuf/source_context.proto | 4 +- google/protobuf/struct.proto | 10 +- google/protobuf/timestamp.proto | 16 +- google/protobuf/type.proto | 16 +- google/protobuf/wrappers.proto | 6 +- 12 files changed, 127 insertions(+), 515 deletions(-) diff --git a/cl-protobufs.asd b/cl-protobufs.asd index 8fbab4f8..9f1d232a 100644 --- a/cl-protobufs.asd +++ b/cl-protobufs.asd @@ -71,23 +71,36 @@ and functionality for working with them." :components ((:file "message-api"))) (:module "well-known-types" + :serial t :pathname "" :depends-on ("models" "misc") :components - ((:protobuf-source-file "google/protobuf/descriptor") - (:protobuf-source-file "google/protobuf/any") - (:protobuf-source-file "google/protobuf/source_context") + ((:protobuf-source-file "descriptor" + :proto-pathname "google/protobuf/descriptor.proto") + (:protobuf-source-file "any" + :proto-pathname "google/protobuf/any.proto") + (:protobuf-source-file "source_context" + :proto-pathname "google/protobuf/source_context.proto") #-ccl - (:protobuf-source-file "google/protobuf/type" - :depends-on ("google/protobuf/any" "google/protobuf/source_context")) + (:protobuf-source-file "type" + :proto-pathname "google/protobuf/type.proto" + :proto-search-path ("google/protobuf/")) #-ccl - (:protobuf-source-file "google/protobuf/api") - (:protobuf-source-file "google/protobuf/duration") - (:protobuf-source-file "google/protobuf/empty") - (:protobuf-source-file "google/protobuf/field_mask") - (:protobuf-source-file "google/protobuf/timestamp") - (:protobuf-source-file "google/protobuf/wrappers") - (:protobuf-source-file "google/protobuf/struct") + (:protobuf-source-file "api" + :proto-pathname "google/protobuf/api.proto" + :proto-search-path ("google/protobuf/")) + (:protobuf-source-file "duration" + :proto-pathname "google/protobuf/duration.proto") + (:protobuf-source-file "empty" + :proto-pathname "google/protobuf/empty.proto") + (:protobuf-source-file "field_mask" + :proto-pathname "google/protobuf/field_mask.proto") + (:protobuf-source-file "timestamp" + :proto-pathname "google/protobuf/timestamp.proto") + (:protobuf-source-file "wrappers" + :proto-pathname "google/protobuf/wrappers.proto") + (:protobuf-source-file "struct" + :proto-pathname "google/protobuf/struct.proto") (:file "well-known-types"))) (:module "json" :serial t diff --git a/google/protobuf/any.proto b/google/protobuf/any.proto index eff44e50..c9be8541 100644 --- a/google/protobuf/any.proto +++ b/google/protobuf/any.proto @@ -32,12 +32,12 @@ syntax = "proto3"; package google.protobuf; -option go_package = "google.golang.org/protobuf/types/known/anypb"; +option csharp_namespace = "Google.Protobuf.WellKnownTypes"; +option go_package = "github.com/golang/protobuf/ptypes/any"; option java_package = "com.google.protobuf"; option java_outer_classname = "AnyProto"; option java_multiple_files = true; option objc_class_prefix = "GPB"; -option csharp_namespace = "Google.Protobuf.WellKnownTypes"; // `Any` contains an arbitrary serialized protocol buffer message along with a // URL that describes the type of the serialized message. @@ -63,10 +63,6 @@ option csharp_namespace = "Google.Protobuf.WellKnownTypes"; // if (any.is(Foo.class)) { // foo = any.unpack(Foo.class); // } -// // or ... -// if (any.isSameTypeAs(Foo.getDefaultInstance())) { -// foo = any.unpack(Foo.getDefaultInstance()); -// } // // Example 3: Pack and unpack a message in Python. // @@ -81,13 +77,10 @@ option csharp_namespace = "Google.Protobuf.WellKnownTypes"; // Example 4: Pack and unpack a message in Go // // foo := &pb.Foo{...} -// any, err := anypb.New(foo) -// if err != nil { -// ... -// } +// any, err := ptypes.MarshalAny(foo) // ... // foo := &pb.Foo{} -// if err := any.UnmarshalTo(foo); err != nil { +// if err := ptypes.UnmarshalAny(any, foo); err != nil { // ... // } // @@ -97,6 +90,7 @@ option csharp_namespace = "Google.Protobuf.WellKnownTypes"; // in the type URL, for example "foo.bar.com/x/y.z" will yield type // name "y.z". // +// // JSON // ==== // The JSON representation of an `Any` value uses the regular @@ -149,8 +143,7 @@ message Any { // // Note: this functionality is not currently available in the official // protobuf release, and it is not used for type URLs beginning with - // type.googleapis.com. As of May 2023, there are no widely used type server - // implementations and no plans to implement one. + // type.googleapis.com. // // Schemes other than `http`, `https` (or the empty scheme) might be // used with implementation specific semantics. diff --git a/google/protobuf/api.proto b/google/protobuf/api.proto index 42223516..bb7d9932 100644 --- a/google/protobuf/api.proto +++ b/google/protobuf/api.proto @@ -32,15 +32,15 @@ syntax = "proto3"; package google.protobuf; -import "google/protobuf/source_context.proto"; -import "google/protobuf/type.proto"; +import "source_context.proto"; +import "type.proto"; +option csharp_namespace = "Google.Protobuf.WellKnownTypes"; option java_package = "com.google.protobuf"; option java_outer_classname = "ApiProto"; option java_multiple_files = true; option objc_class_prefix = "GPB"; -option csharp_namespace = "Google.Protobuf.WellKnownTypes"; -option go_package = "google.golang.org/protobuf/types/known/apipb"; +option go_package = "google.golang.org/genproto/protobuf/api;api"; // Api is a light-weight descriptor for an API Interface. // @@ -52,6 +52,7 @@ option go_package = "google.golang.org/protobuf/types/known/apipb"; // this message itself. See https://cloud.google.com/apis/design/glossary for // detailed terminology. message Api { + // The fully qualified name of this interface, including package name // followed by the interface's simple name. string name = 1; @@ -82,6 +83,7 @@ message Api { // be omitted. Zero major versions must only be used for // experimental, non-GA interfaces. // + // string version = 4; // Source context for the protocol buffer service represented by this @@ -97,6 +99,7 @@ message Api { // Method represents a method of an API interface. message Method { + // The simple name of this method. string name = 1; diff --git a/google/protobuf/descriptor.proto b/google/protobuf/descriptor.proto index dfabac41..d29fdec5 100644 --- a/google/protobuf/descriptor.proto +++ b/google/protobuf/descriptor.proto @@ -36,11 +36,12 @@ // A valid .proto file can be translated directly to a FileDescriptorProto // without any other information (e.g. without reading its imports). + syntax = "proto2"; package google.protobuf; -option go_package = "google.golang.org/protobuf/types/descriptorpb"; +option go_package = "github.com/golang/protobuf/protoc-gen-go/descriptor;descriptor"; option java_package = "com.google.protobuf"; option java_outer_classname = "DescriptorProtos"; option csharp_namespace = "Google.Protobuf.Reflection"; @@ -57,42 +58,6 @@ message FileDescriptorSet { repeated FileDescriptorProto file = 1; } -// The full set of known editions. -enum Edition { - // A placeholder for an unknown edition value. - EDITION_UNKNOWN = 0; - - // A placeholder edition for specifying default behaviors *before* a feature - // was first introduced. This is effectively an "infinite past". - EDITION_LEGACY = 900; - - // Legacy syntax "editions". These pre-date editions, but behave much like - // distinct editions. These can't be used to specify the edition of proto - // files, but feature definitions must supply proto2/proto3 defaults for - // backwards compatibility. - EDITION_PROTO2 = 998; - EDITION_PROTO3 = 999; - - // Editions that have been released. The specific values are arbitrary and - // should not be depended on, but they will always be time-ordered for easy - // comparison. - EDITION_2023 = 1000; - EDITION_2024 = 1001; - - // Placeholder editions for testing feature resolution. These should not be - // used or relyed on outside of tests. - EDITION_1_TEST_ONLY = 1; - EDITION_2_TEST_ONLY = 2; - EDITION_99997_TEST_ONLY = 99997; - EDITION_99998_TEST_ONLY = 99998; - EDITION_99999_TEST_ONLY = 99999; - - // Placeholder for specifying unbounded edition support. This should only - // ever be used by plugins that can expect to never require any changes to - // support a new edition. - EDITION_MAX = 0x7FFFFFFF; -} - // Describes a complete .proto file. message FileDescriptorProto { optional string name = 1; // file name, relative to root of source tree @@ -121,13 +86,8 @@ message FileDescriptorProto { optional SourceCodeInfo source_code_info = 9; // The syntax of the proto file. - // The supported values are "proto2", "proto3", and "editions". - // - // If `edition` is present, this value must be "editions". + // The supported values are "proto2" and "proto3". optional string syntax = 12; - - // The edition of the proto file. - optional Edition edition = 14; } // Describes a message type. @@ -169,51 +129,6 @@ message ExtensionRangeOptions { // The parser stores options it doesn't recognize here. See above. repeated UninterpretedOption uninterpreted_option = 999; - message Declaration { - // The extension number declared within the extension range. - optional int32 number = 1; - - // The fully-qualified name of the extension field. There must be a leading - // dot in front of the full name. - optional string full_name = 2; - - // The fully-qualified type name of the extension field. Unlike - // Metadata.type, Declaration.type must have a leading dot for messages - // and enums. - optional string type = 3; - - // If true, indicates that the number is reserved in the extension range, - // and any extension field with the number will fail to compile. Set this - // when a declared extension field is deleted. - optional bool reserved = 5; - - // If true, indicates that the extension must be defined as repeated. - // Otherwise the extension must be defined as optional. - optional bool repeated = 6; - - reserved 4; // removed is_repeated - } - - // For external users: DO NOT USE. We are in the process of open sourcing - // extension declaration and executing internal cleanups before it can be - // used externally. - repeated Declaration declaration = 2 [retention = RETENTION_SOURCE]; - - // Any features defined in the specific edition. - optional FeatureSet features = 50; - - // The verification state of the extension range. - enum VerificationState { - // All the extensions of the range must be declared. - DECLARATION = 0; - UNVERIFIED = 1; - } - - // The verification state of the range. - // TODO: flip the default to DECLARATION once all empty ranges - // are marked as UNVERIFIED. - optional VerificationState verification = 3 - [default = UNVERIFIED, retention = RETENTION_SOURCE]; // Clients can define custom options in extensions of this message. See above. extensions 1000 to max; @@ -238,10 +153,9 @@ message FieldDescriptorProto { TYPE_BOOL = 8; TYPE_STRING = 9; // Tag-delimited aggregate. - // Group type is deprecated and not supported after google.protobuf. However, Proto3 + // Group type is deprecated and not supported in proto3. However, Proto3 // implementations should still be able to parse the group wire format and - // treat group fields as unknown fields. In Editions, the group wire format - // can be enabled via the `message_encoding` feature. + // treat group fields as unknown fields. TYPE_GROUP = 10; TYPE_MESSAGE = 11; // Length-delimited aggregate. @@ -258,11 +172,8 @@ message FieldDescriptorProto { enum Label { // 0 is reserved for errors LABEL_OPTIONAL = 1; - LABEL_REPEATED = 3; - // The required label is only allowed in google.protobuf. In proto3 and Editions - // it's explicitly prohibited. In Editions, the `field_presence` feature - // can be used to get this behavior. LABEL_REQUIRED = 2; + LABEL_REPEATED = 3; } optional string name = 1; @@ -288,6 +199,7 @@ message FieldDescriptorProto { // For booleans, "true" or "false". // For strings, contains the default text contents (not escaped in any way). // For bytes, contains the C escaped value. All bytes >= 128 are escaped. + // TODO(kenton): Base-64 encode? optional string default_value = 7; // If set, gives the index of a oneof in the containing type's oneof_decl @@ -305,12 +217,12 @@ message FieldDescriptorProto { // If true, this is a proto3 "optional". When a proto3 field is optional, it // tracks presence regardless of field type. // - // When proto3_optional is true, this field must belong to a oneof to signal - // to old proto3 clients that presence is tracked for this field. This oneof - // is known as a "synthetic" oneof, and this field must be its sole member - // (each proto3 optional field gets its own synthetic oneof). Synthetic oneofs - // exist in the descriptor only, and do not generate any API. Synthetic oneofs - // must be ordered after all "real" oneofs. + // When proto3_optional is true, this field must be belong to a oneof to + // signal to old proto3 clients that presence is tracked for this field. This + // oneof is known as a "synthetic" oneof, and this field must be its sole + // member (each proto3 optional field gets its own synthetic oneof). Synthetic + // oneofs exist in the descriptor only, and do not generate any API. Synthetic + // oneofs must be ordered after all "real" oneofs. // // For message fields, proto3_optional doesn't create any semantic change, // since non-repeated message fields always track presence. However it still @@ -394,6 +306,7 @@ message MethodDescriptorProto { optional bool server_streaming = 6 [default = false]; } + // =================================================================== // Options @@ -434,17 +347,18 @@ message FileOptions { // domain names. optional string java_package = 1; - // Controls the name of the wrapper Java class generated for the .proto file. - // That class will always contain the .proto file's getDescriptor() method as - // well as any top-level extensions defined in the .proto file. - // If java_multiple_files is disabled, then all the other classes from the - // .proto file will be nested inside the single wrapper outer class. + + // If set, all the classes from the .proto file are wrapped in a single + // outer class with the given name. This applies to both Proto1 + // (equivalent to the old "--one_java_file" option) and Proto2 (where + // a .proto always translates to a single class, but you may want to + // explicitly choose the class name). optional string java_outer_classname = 8; - // If enabled, then the Java code generator will generate a separate .java + // If set true, then the Java code generator will generate a separate .java // file for each top-level message, enum, and service defined in the .proto - // file. Thus, these types will *not* be nested inside the wrapper class - // named by java_outer_classname. However, the wrapper class will still be + // file. Thus, these types will *not* be nested inside the outer class + // named by java_outer_classname. However, the outer class will still be // generated to contain the file's getDescriptor() method as well as any // top-level extensions defined in the file. optional bool java_multiple_files = 10 [default = false]; @@ -452,18 +366,15 @@ message FileOptions { // This option does nothing. optional bool java_generate_equals_and_hash = 20 [deprecated=true]; - // A proto2 file can set this to true to opt in to UTF-8 checking for Java, - // which will throw an exception if invalid UTF-8 is parsed from the wire or - // assigned to a string field. - // - // TODO: clarify exactly what kinds of field types this option - // applies to, and update these docs accordingly. - // - // Proto3 files already perform these checks. Setting the option explicitly to - // false has no effect: it cannot be used to opt proto3 files out of UTF-8 - // checks. + // If set true, then the Java2 code generator will generate code that + // throws an exception whenever an attempt is made to assign a non-UTF-8 + // byte sequence to a string field. + // Message reflection will do the same. + // However, an extension field still accepts non-UTF-8 byte sequences. + // This option has no effect on when used with the lite runtime. optional bool java_string_check_utf8 = 27 [default = false]; + // Generated classes can be optimized for speed or code size. enum OptimizeMode { SPEED = 1; // Generate complete code for parsing, serialization, @@ -480,6 +391,9 @@ message FileOptions { // - Otherwise, the basename of the .proto file, without extension. optional string go_package = 11; + + + // Should generic services be generated in each language? "Generic" services // are not specific to any particular RPC system. They are generated by the // main code generators in each language (without additional plugins). @@ -493,8 +407,7 @@ message FileOptions { optional bool cc_generic_services = 16 [default = false]; optional bool java_generic_services = 17 [default = false]; optional bool py_generic_services = 18 [default = false]; - reserved 42; // removed php_generic_services - reserved "php_generic_services"; + optional bool php_generic_services = 42 [default = false]; // Is this file deprecated? // Depending on the target platform, this can emit Deprecated annotations @@ -506,6 +419,7 @@ message FileOptions { // only to generated classes for C++. optional bool cc_enable_arenas = 31 [default = true]; + // Sets the objective c class prefix which is prepended to all objective c // generated classes from this .proto. There is no default. optional string objc_class_prefix = 36; @@ -538,8 +452,6 @@ message FileOptions { // determining the ruby package. optional string ruby_package = 45; - // Any features defined in the specific edition. - optional FeatureSet features = 50; // The parser stores options it doesn't recognize here. // See the documentation for the "Options" section above. @@ -584,8 +496,6 @@ message MessageOptions { // this is a formalization for deprecating messages. optional bool deprecated = 3 [default = false]; - reserved 4, 5, 6; - // Whether the message is an automatically generated map entry type for the // maps field. // @@ -612,20 +522,6 @@ message MessageOptions { reserved 8; // javalite_serializable reserved 9; // javanano_as_lite - // Enable the legacy handling of JSON field name conflicts. This lowercases - // and strips underscored from the fields before comparison in proto3 only. - // The new behavior takes `json_name` into account and applies to proto2 as - // well. - // - // This should only be used as a temporary measure against broken builds due - // to the change in behavior for JSON field name conflicts. - // - // TODO This is legacy behavior we plan to remove once downstream - // teams have had time to migrate. - optional bool deprecated_legacy_json_field_conflicts = 11 [deprecated = true]; - - // Any features defined in the specific edition. - optional FeatureSet features = 12; // The parser stores options it doesn't recognize here. See above. repeated UninterpretedOption uninterpreted_option = 999; @@ -635,24 +531,15 @@ message MessageOptions { } message FieldOptions { - // NOTE: ctype is deprecated. Use `features.(pb.cpp).string_type` instead. // The ctype option instructs the C++ code generator to use a different // representation of the field than it normally would. See the specific - // options below. This option is only implemented to support use of - // [ctype=CORD] and [ctype=STRING] (the default) on non-repeated fields of - // type "bytes" in the open source release. - // TODO: make ctype actually deprecated. - optional CType ctype = 1 [/*deprecated = true,*/ default = STRING]; + // options below. This option is not yet implemented in the open source + // release -- sorry, we'll try to include it in a future version! + optional CType ctype = 1 [default = STRING]; enum CType { // Default mode. STRING = 0; - // The option [ctype=CORD] may be applied to a non-repeated field of type - // "bytes". It indicates that in C++, the data should be stored in a Cord - // instead of a string. For very large strings, this may reduce memory - // fragmentation. It may also allow better performance when parsing from a - // Cord, or when parsing with aliasing enabled, as the parsed Cord may then - // alias the original buffer. CORD = 1; STRING_PIECE = 2; @@ -661,9 +548,7 @@ message FieldOptions { // a more efficient representation on the wire. Rather than repeatedly // writing the tag and type for each element, the entire array is encoded as // a single length-delimited blob. In proto3, only explicit setting it to - // false will avoid using packed encoding. This option is prohibited in - // Editions, but the `repeated_field_encoding` feature can be used to control - // the behavior. + // false will avoid using packed encoding. optional bool packed = 2; // The jstype option determines the JavaScript type used for values of the @@ -706,18 +591,19 @@ message FieldOptions { // call from multiple threads concurrently, while non-const methods continue // to require exclusive access. // - // Note that lazy message fields are still eagerly verified to check - // ill-formed wireformat or missing required fields. Calling IsInitialized() - // on the outer message would fail if the inner message has missing required - // fields. Failed verification would result in parsing failure (except when - // uninitialized messages are acceptable). + // + // Note that implementations may choose not to check required fields within + // a lazy sub-message. That is, calling IsInitialized() on the outer message + // may return true even if the inner message has missing required fields. + // This is necessary because otherwise the inner message would have to be + // parsed in order to perform the check, defeating the purpose of lazy + // parsing. An implementation which chooses not to check required fields + // must be consistent about it. That is, for any particular sub-message, the + // implementation must either *always* check its required fields, or *never* + // check its required fields, regardless of whether or not the message has + // been parsed. optional bool lazy = 5 [default = false]; - // unverified_lazy does no correctness checks on the byte stream. This should - // only be used where lazy with verification is prohibitive for performance - // reasons. - optional bool unverified_lazy = 15 [default = false]; - // Is this field deprecated? // Depending on the target platform, this can emit Deprecated annotations // for accessors, or it will be completely ignored; in the very least, this @@ -727,70 +613,6 @@ message FieldOptions { // For Google-internal migration only. Do not use. optional bool weak = 10 [default = false]; - // Indicate that the field value should not be printed out when using debug - // formats, e.g. when the field contains sensitive credentials. - optional bool debug_redact = 16 [default = false]; - - // If set to RETENTION_SOURCE, the option will be omitted from the binary. - // Note: as of January 2023, support for this is in progress and does not yet - // have an effect (b/264593489). - enum OptionRetention { - RETENTION_UNKNOWN = 0; - RETENTION_RUNTIME = 1; - RETENTION_SOURCE = 2; - } - - optional OptionRetention retention = 17; - - // This indicates the types of entities that the field may apply to when used - // as an option. If it is unset, then the field may be freely used as an - // option on any kind of entity. Note: as of January 2023, support for this is - // in progress and does not yet have an effect (b/264593489). - enum OptionTargetType { - TARGET_TYPE_UNKNOWN = 0; - TARGET_TYPE_FILE = 1; - TARGET_TYPE_EXTENSION_RANGE = 2; - TARGET_TYPE_MESSAGE = 3; - TARGET_TYPE_FIELD = 4; - TARGET_TYPE_ONEOF = 5; - TARGET_TYPE_ENUM = 6; - TARGET_TYPE_ENUM_ENTRY = 7; - TARGET_TYPE_SERVICE = 8; - TARGET_TYPE_METHOD = 9; - } - - repeated OptionTargetType targets = 19; - - message EditionDefault { - optional Edition edition = 3; - optional string value = 2; // Textproto value. - } - repeated EditionDefault edition_defaults = 20; - - // Any features defined in the specific edition. - optional FeatureSet features = 21; - - // Information about the support window of a feature. - message FeatureSupport { - // The edition that this feature was first available in. In editions - // earlier than this one, the default assigned to EDITION_LEGACY will be - // used, and proto files will not be able to override it. - optional Edition edition_introduced = 1; - - // The edition this feature becomes deprecated in. Using this after this - // edition may trigger warnings. - optional Edition edition_deprecated = 2; - - // The deprecation warning text if this feature is used after the edition it - // was marked deprecated in. - optional string deprecation_warning = 3; - - // The edition this feature is no longer available in. In editions after - // this one, the last default assigned will be used, and proto files will - // not be able to override it. - optional Edition edition_removed = 4; - } - optional FeatureSupport feature_support = 22; // The parser stores options it doesn't recognize here. See above. repeated UninterpretedOption uninterpreted_option = 999; @@ -798,14 +620,10 @@ message FieldOptions { // Clients can define custom options in extensions of this message. See above. extensions 1000 to max; - reserved 4; // removed jtype - reserved 18; // reserve target, target_obsolete_do_not_use + reserved 4; // removed jtype } message OneofOptions { - // Any features defined in the specific edition. - optional FeatureSet features = 1; - // The parser stores options it doesn't recognize here. See above. repeated UninterpretedOption uninterpreted_option = 999; @@ -827,17 +645,6 @@ message EnumOptions { reserved 5; // javanano_as_lite - // Enable the legacy handling of JSON field name conflicts. This lowercases - // and strips underscored from the fields before comparison in proto3 only. - // The new behavior takes `json_name` into account and applies to proto2 as - // well. - // TODO Remove this legacy behavior once downstream teams have - // had time to migrate. - optional bool deprecated_legacy_json_field_conflicts = 6 [deprecated = true]; - - // Any features defined in the specific edition. - optional FeatureSet features = 7; - // The parser stores options it doesn't recognize here. See above. repeated UninterpretedOption uninterpreted_option = 999; @@ -852,17 +659,6 @@ message EnumValueOptions { // this is a formalization for deprecating enum values. optional bool deprecated = 1 [default = false]; - // Any features defined in the specific edition. - optional FeatureSet features = 2; - - // Indicate that fields annotated with this enum value should not be printed - // out when using debug formats, e.g. when the field contains sensitive - // credentials. - optional bool debug_redact = 3 [default = false]; - - // Information about the support window of a feature value. - optional FieldOptions.FeatureSupport feature_support = 4; - // The parser stores options it doesn't recognize here. See above. repeated UninterpretedOption uninterpreted_option = 999; @@ -872,9 +668,6 @@ message EnumValueOptions { message ServiceOptions { - // Any features defined in the specific edition. - optional FeatureSet features = 34; - // Note: Field numbers 1 through 32 are reserved for Google's internal RPC // framework. We apologize for hoarding these numbers to ourselves, but // we were already using them long before we decided to release Protocol @@ -917,9 +710,6 @@ message MethodOptions { optional IdempotencyLevel idempotency_level = 34 [default = IDEMPOTENCY_UNKNOWN]; - // Any features defined in the specific edition. - optional FeatureSet features = 35; - // The parser stores options it doesn't recognize here. See above. repeated UninterpretedOption uninterpreted_option = 999; @@ -927,6 +717,7 @@ message MethodOptions { extensions 1000 to max; } + // A message representing a option the parser does not recognize. This only // appears in options protos created by the compiler::Parser class. // DescriptorPool resolves these when building Descriptor objects. Therefore, @@ -937,8 +728,8 @@ message UninterpretedOption { // The name of the uninterpreted option. Each string represents a segment in // a dot-separated name. is_extension is true iff a segment represents an // extension (denoted with parentheses in options specs in .proto files). - // E.g.,{ ["foo", false], ["bar.baz", true], ["moo", false] } represents - // "foo.(bar.baz).moo". + // E.g.,{ ["foo", false], ["bar.baz", true], ["qux", false] } represents + // "foo.(bar.baz).qux". message NamePart { required string name_part = 1; required bool is_extension = 2; @@ -955,172 +746,6 @@ message UninterpretedOption { optional string aggregate_value = 8; } -// =================================================================== -// Features - -// TODO Enums in C++ gencode (and potentially other languages) are -// not well scoped. This means that each of the feature enums below can clash -// with each other. The short names we've chosen maximize call-site -// readability, but leave us very open to this scenario. A future feature will -// be designed and implemented to handle this, hopefully before we ever hit a -// conflict here. -message FeatureSet { - enum FieldPresence { - FIELD_PRESENCE_UNKNOWN = 0; - EXPLICIT = 1; - IMPLICIT = 2; - LEGACY_REQUIRED = 3; - } - optional FieldPresence field_presence = 1 [ - retention = RETENTION_RUNTIME, - targets = TARGET_TYPE_FIELD, - targets = TARGET_TYPE_FILE, - feature_support = { - edition_introduced: EDITION_2023, - }, - edition_defaults = { edition: EDITION_LEGACY, value: "EXPLICIT" }, - edition_defaults = { edition: EDITION_PROTO3, value: "IMPLICIT" }, - edition_defaults = { edition: EDITION_2023, value: "EXPLICIT" } - ]; - - enum EnumType { - ENUM_TYPE_UNKNOWN = 0; - OPEN = 1; - CLOSED = 2; - } - optional EnumType enum_type = 2 [ - retention = RETENTION_RUNTIME, - targets = TARGET_TYPE_ENUM, - targets = TARGET_TYPE_FILE, - feature_support = { - edition_introduced: EDITION_2023, - }, - edition_defaults = { edition: EDITION_LEGACY, value: "CLOSED" }, - edition_defaults = { edition: EDITION_PROTO3, value: "OPEN" } - ]; - - enum RepeatedFieldEncoding { - REPEATED_FIELD_ENCODING_UNKNOWN = 0; - PACKED = 1; - EXPANDED = 2; - } - optional RepeatedFieldEncoding repeated_field_encoding = 3 [ - retention = RETENTION_RUNTIME, - targets = TARGET_TYPE_FIELD, - targets = TARGET_TYPE_FILE, - feature_support = { - edition_introduced: EDITION_2023, - }, - edition_defaults = { edition: EDITION_LEGACY, value: "EXPANDED" }, - edition_defaults = { edition: EDITION_PROTO3, value: "PACKED" } - ]; - - enum Utf8Validation { - UTF8_VALIDATION_UNKNOWN = 0; - VERIFY = 2; - NONE = 3; - reserved 1; - } - optional Utf8Validation utf8_validation = 4 [ - retention = RETENTION_RUNTIME, - targets = TARGET_TYPE_FIELD, - targets = TARGET_TYPE_FILE, - feature_support = { - edition_introduced: EDITION_2023, - }, - edition_defaults = { edition: EDITION_LEGACY, value: "NONE" }, - edition_defaults = { edition: EDITION_PROTO3, value: "VERIFY" } - ]; - - enum MessageEncoding { - MESSAGE_ENCODING_UNKNOWN = 0; - LENGTH_PREFIXED = 1; - DELIMITED = 2; - } - optional MessageEncoding message_encoding = 5 [ - retention = RETENTION_RUNTIME, - targets = TARGET_TYPE_FIELD, - targets = TARGET_TYPE_FILE, - feature_support = { - edition_introduced: EDITION_2023, - }, - edition_defaults = { edition: EDITION_LEGACY, value: "LENGTH_PREFIXED" } - ]; - - enum JsonFormat { - JSON_FORMAT_UNKNOWN = 0; - ALLOW = 1; - LEGACY_BEST_EFFORT = 2; - } - optional JsonFormat json_format = 6 [ - retention = RETENTION_RUNTIME, - targets = TARGET_TYPE_MESSAGE, - targets = TARGET_TYPE_ENUM, - targets = TARGET_TYPE_FILE, - feature_support = { - edition_introduced: EDITION_2023, - }, - edition_defaults = { edition: EDITION_LEGACY, value: "LEGACY_BEST_EFFORT" }, - edition_defaults = { edition: EDITION_PROTO3, value: "ALLOW" } - ]; - - reserved 999; - - extensions 1000 to 9994 [ - declaration = { - number: 1000, - full_name: ".pb.cpp", - type: ".pb.CppFeatures" - }, - declaration = { - number: 1001, - full_name: ".pb.java", - type: ".pb.JavaFeatures" - }, - declaration = { number: 1002, full_name: ".pb.go", type: ".pb.GoFeatures" }, - declaration = { - number: 9990, - full_name: ".pb.proto1", - type: ".pb.Proto1Features" - } - ]; - - extensions 9995 to 9999; // For internal testing - extensions 10000; // for https://github.com/bufbuild/protobuf-es -} - -// A compiled specification for the defaults of a set of features. These -// messages are generated from FeatureSet extensions and can be used to seed -// feature resolution. The resolution with this object becomes a simple search -// for the closest matching edition, followed by proto merges. -message FeatureSetDefaults { - // A map from every known edition with a unique set of defaults to its - // defaults. Not all editions may be contained here. For a given edition, - // the defaults at the closest matching edition ordered at or before it should - // be used. This field must be in strict ascending order by edition. - message FeatureSetEditionDefault { - optional Edition edition = 3; - - // Defaults of features that can be overridden in this edition. - optional FeatureSet overridable_features = 4; - - // Defaults of features that can't be overridden in this edition. - optional FeatureSet fixed_features = 5; - - reserved 1, 2; - reserved "features"; - } - repeated FeatureSetEditionDefault defaults = 1; - - // The minimum supported edition (inclusive) when this was constructed. - // Editions before this will not have defaults. - optional Edition minimum_edition = 4; - - // The maximum known edition (inclusive) when this was constructed. Editions - // after this will not have reliable defaults. - optional Edition maximum_edition = 5; -} - // =================================================================== // Optional source code info @@ -1176,8 +801,8 @@ message SourceCodeInfo { // location. // // Each element is a field number or an index. They form a path from - // the root FileDescriptorProto to the place where the definition appears. - // For example, this path: + // the root FileDescriptorProto to the place where the definition. For + // example, this path: // [ 4, 3, 2, 7, 1 ] // refers to: // file.message_type(3) // 4, 3 @@ -1231,13 +856,13 @@ message SourceCodeInfo { // // Comment attached to baz. // // Another line attached to baz. // - // // Comment attached to moo. + // // Comment attached to qux. // // - // // Another line attached to moo. - // optional double moo = 4; + // // Another line attached to qux. + // optional double qux = 4; // // // Detached comment for corge. This is not leading or trailing comments - // // to moo or corge because there are blank lines separating it from + // // to qux or corge because there are blank lines separating it from // // both. // // // Detached comment for corge paragraph 2. @@ -1277,20 +902,8 @@ message GeneratedCodeInfo { optional int32 begin = 3; // Identifies the ending offset in bytes in the generated code that - // relates to the identified object. The end offset should be one past + // relates to the identified offset. The end offset should be one past // the last relevant byte (so the length of the text = end - begin). optional int32 end = 4; - - // Represents the identified object's effect on the element in the original - // .proto file. - enum Semantic { - // There is no effect or the effect is indescribable. - NONE = 0; - // The element is set or otherwise mutated. - SET = 1; - // An alias to the element is returned. - ALIAS = 2; - } - optional Semantic semantic = 5; } } diff --git a/google/protobuf/duration.proto b/google/protobuf/duration.proto index 41f40c22..99cb102c 100644 --- a/google/protobuf/duration.proto +++ b/google/protobuf/duration.proto @@ -32,13 +32,13 @@ syntax = "proto3"; package google.protobuf; +option csharp_namespace = "Google.Protobuf.WellKnownTypes"; option cc_enable_arenas = true; -option go_package = "google.golang.org/protobuf/types/known/durationpb"; +option go_package = "github.com/golang/protobuf/ptypes/duration"; option java_package = "com.google.protobuf"; option java_outer_classname = "DurationProto"; option java_multiple_files = true; option objc_class_prefix = "GPB"; -option csharp_namespace = "Google.Protobuf.WellKnownTypes"; // A Duration represents a signed, fixed-length span of time represented // as a count of seconds and fractions of seconds at nanosecond @@ -99,6 +99,7 @@ option csharp_namespace = "Google.Protobuf.WellKnownTypes"; // be expressed in JSON format as "3.000000001s", and 3 seconds and 1 // microsecond should be expressed in JSON format as "3.000001s". // +// message Duration { // Signed seconds of the span of time. Must be from -315,576,000,000 // to +315,576,000,000 inclusive. Note: these bounds are computed from: diff --git a/google/protobuf/empty.proto b/google/protobuf/empty.proto index b87c89dc..03cacd23 100644 --- a/google/protobuf/empty.proto +++ b/google/protobuf/empty.proto @@ -32,12 +32,12 @@ syntax = "proto3"; package google.protobuf; -option go_package = "google.golang.org/protobuf/types/known/emptypb"; +option csharp_namespace = "Google.Protobuf.WellKnownTypes"; +option go_package = "github.com/golang/protobuf/ptypes/empty"; option java_package = "com.google.protobuf"; option java_outer_classname = "EmptyProto"; option java_multiple_files = true; option objc_class_prefix = "GPB"; -option csharp_namespace = "Google.Protobuf.WellKnownTypes"; option cc_enable_arenas = true; // A generic empty message that you can re-use to avoid defining duplicated @@ -48,4 +48,5 @@ option cc_enable_arenas = true; // rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty); // } // +// The JSON representation for `Empty` is empty JSON object `{}`. message Empty {} diff --git a/google/protobuf/field_mask.proto b/google/protobuf/field_mask.proto index b28334b9..baac8744 100644 --- a/google/protobuf/field_mask.proto +++ b/google/protobuf/field_mask.proto @@ -32,12 +32,12 @@ syntax = "proto3"; package google.protobuf; +option csharp_namespace = "Google.Protobuf.WellKnownTypes"; option java_package = "com.google.protobuf"; option java_outer_classname = "FieldMaskProto"; option java_multiple_files = true; option objc_class_prefix = "GPB"; -option csharp_namespace = "Google.Protobuf.WellKnownTypes"; -option go_package = "google.golang.org/protobuf/types/known/fieldmaskpb"; +option go_package = "google.golang.org/genproto/protobuf/field_mask;field_mask"; option cc_enable_arenas = true; // `FieldMask` represents a set of symbolic field paths, for example: diff --git a/google/protobuf/source_context.proto b/google/protobuf/source_context.proto index 135f50fe..f3b2c966 100644 --- a/google/protobuf/source_context.proto +++ b/google/protobuf/source_context.proto @@ -32,12 +32,12 @@ syntax = "proto3"; package google.protobuf; +option csharp_namespace = "Google.Protobuf.WellKnownTypes"; option java_package = "com.google.protobuf"; option java_outer_classname = "SourceContextProto"; option java_multiple_files = true; option objc_class_prefix = "GPB"; -option csharp_namespace = "Google.Protobuf.WellKnownTypes"; -option go_package = "google.golang.org/protobuf/types/known/sourcecontextpb"; +option go_package = "google.golang.org/genproto/protobuf/source_context;source_context"; // `SourceContext` represents information about the source of a // protobuf element, like the file in which it is defined. diff --git a/google/protobuf/struct.proto b/google/protobuf/struct.proto index 1bf0c1ad..5bd4c8c7 100644 --- a/google/protobuf/struct.proto +++ b/google/protobuf/struct.proto @@ -32,13 +32,13 @@ syntax = "proto3"; package google.protobuf; +option csharp_namespace = "Google.Protobuf.WellKnownTypes"; option cc_enable_arenas = true; option go_package = "google.golang.org/protobuf/types/known/structpb"; option java_package = "com.google.protobuf"; option java_outer_classname = "StructProto"; option java_multiple_files = true; option objc_class_prefix = "GPB"; -option csharp_namespace = "Google.Protobuf.WellKnownTypes"; // `Struct` represents a structured data value, consisting of fields // which map to dynamically typed values. In some languages, `Struct` @@ -55,8 +55,8 @@ message Struct { // `Value` represents a dynamically typed value which can be either // null, a number, a string, a boolean, a recursive struct value, or a -// list of values. A producer of value is expected to set one of these -// variants. Absence of any variant indicates an error. +// list of values. A producer of value is expected to set one of that +// variants, absence of any variant indicates an error. // // The JSON representation for `Value` is JSON value. message Value { @@ -80,7 +80,7 @@ message Value { // `NullValue` is a singleton enumeration to represent the null value for the // `Value` type union. // -// The JSON representation for `NullValue` is JSON `null`. +// The JSON representation for `NullValue` is JSON `null`. enum NullValue { // Null value. NULL_VALUE = 0; @@ -92,4 +92,4 @@ enum NullValue { message ListValue { // Repeated field of dynamically typed values. repeated Value values = 1; -} +} \ No newline at end of file diff --git a/google/protobuf/timestamp.proto b/google/protobuf/timestamp.proto index fd0bc07d..cd357864 100644 --- a/google/protobuf/timestamp.proto +++ b/google/protobuf/timestamp.proto @@ -32,13 +32,13 @@ syntax = "proto3"; package google.protobuf; +option csharp_namespace = "Google.Protobuf.WellKnownTypes"; option cc_enable_arenas = true; -option go_package = "google.golang.org/protobuf/types/known/timestamppb"; +option go_package = "github.com/golang/protobuf/ptypes/timestamp"; option java_package = "com.google.protobuf"; option java_outer_classname = "TimestampProto"; option java_multiple_files = true; option objc_class_prefix = "GPB"; -option csharp_namespace = "Google.Protobuf.WellKnownTypes"; // A Timestamp represents a point in time independent of any time zone or local // calendar, encoded as a count of seconds and fractions of seconds at @@ -90,15 +90,8 @@ option csharp_namespace = "Google.Protobuf.WellKnownTypes"; // Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000) // .setNanos((int) ((millis % 1000) * 1000000)).build(); // -// Example 5: Compute Timestamp from Java `Instant.now()`. -// -// Instant now = Instant.now(); // -// Timestamp timestamp = -// Timestamp.newBuilder().setSeconds(now.getEpochSecond()) -// .setNanos(now.getNano()).build(); -// -// Example 6: Compute Timestamp from current time in Python. +// Example 5: Compute Timestamp from current time in Python. // // timestamp = Timestamp() // timestamp.GetCurrentTime() @@ -127,9 +120,10 @@ option csharp_namespace = "Google.Protobuf.WellKnownTypes"; // [`strftime`](https://docs.python.org/2/library/time.html#time.strftime) with // the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one can use // the Joda Time's [`ISODateTimeFormat.dateTime()`]( -// http://joda-time.sourceforge.net/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime() +// http://www.joda.org/joda-time/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime%2D%2D // ) to obtain a formatter capable of generating timestamps in this format. // +// message Timestamp { // Represents seconds of UTC time since Unix epoch // 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to diff --git a/google/protobuf/type.proto b/google/protobuf/type.proto index 48cb11e7..40d701ff 100644 --- a/google/protobuf/type.proto +++ b/google/protobuf/type.proto @@ -32,16 +32,16 @@ syntax = "proto3"; package google.protobuf; -import "google/protobuf/any.proto"; -import "google/protobuf/source_context.proto"; +import "any.proto"; +import "source_context.proto"; +option csharp_namespace = "Google.Protobuf.WellKnownTypes"; option cc_enable_arenas = true; option java_package = "com.google.protobuf"; option java_outer_classname = "TypeProto"; option java_multiple_files = true; option objc_class_prefix = "GPB"; -option csharp_namespace = "Google.Protobuf.WellKnownTypes"; -option go_package = "google.golang.org/protobuf/types/known/typepb"; +option go_package = "google.golang.org/genproto/protobuf/ptype;ptype"; // A protocol buffer message type. message Type { @@ -57,8 +57,6 @@ message Type { SourceContext source_context = 5; // The source syntax. Syntax syntax = 6; - // The source edition string, only valid when syntax is SYNTAX_EDITIONS. - string edition = 7; } // A single field of a message type. @@ -115,7 +113,7 @@ message Field { CARDINALITY_REQUIRED = 2; // For repeated fields. CARDINALITY_REPEATED = 3; - } + }; // The field type. Kind kind = 1; @@ -153,8 +151,6 @@ message Enum { SourceContext source_context = 4; // The source syntax. Syntax syntax = 5; - // The source edition string, only valid when syntax is SYNTAX_EDITIONS. - string edition = 6; } // Enum value definition. @@ -188,6 +184,4 @@ enum Syntax { SYNTAX_PROTO2 = 0; // Syntax `proto3`. SYNTAX_PROTO3 = 1; - // Syntax `editions`. - SYNTAX_EDITIONS = 2; } diff --git a/google/protobuf/wrappers.proto b/google/protobuf/wrappers.proto index 1959fa55..9ee41e38 100644 --- a/google/protobuf/wrappers.proto +++ b/google/protobuf/wrappers.proto @@ -27,7 +27,7 @@ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// + // Wrappers for primitive (non-message) types. These types are useful // for embedding primitives in the `google.protobuf.Any` type and for places // where we need to distinguish between the absence of a primitive @@ -42,13 +42,13 @@ syntax = "proto3"; package google.protobuf; +option csharp_namespace = "Google.Protobuf.WellKnownTypes"; option cc_enable_arenas = true; -option go_package = "google.golang.org/protobuf/types/known/wrapperspb"; +option go_package = "github.com/golang/protobuf/ptypes/wrappers"; option java_package = "com.google.protobuf"; option java_outer_classname = "WrappersProto"; option java_multiple_files = true; option objc_class_prefix = "GPB"; -option csharp_namespace = "Google.Protobuf.WellKnownTypes"; // Wrapper message for `double`. // From e6b6b6cf6e00549e4ca50e2d31c845bdd5286623 Mon Sep 17 00:00:00 2001 From: Mike Delago Date: Wed, 3 Jul 2024 09:56:42 -0400 Subject: [PATCH 10/11] add todo to update well-known types --- cl-protobufs.asd | 1 + 1 file changed, 1 insertion(+) diff --git a/cl-protobufs.asd b/cl-protobufs.asd index 9f1d232a..14a0b3fd 100644 --- a/cl-protobufs.asd +++ b/cl-protobufs.asd @@ -70,6 +70,7 @@ and functionality for working with them." :depends-on ("models" "parsing" "schema" "serialization") :components ((:file "message-api"))) + ;; TODO(michaeldelago) Update well-known types to use their full path (ie google/protobuf/descriptor). (:module "well-known-types" :serial t :pathname "" From 2c5b637e32d6561c7971faec81524980f380d2b1 Mon Sep 17 00:00:00 2001 From: Michael Delago Date: Wed, 25 Sep 2024 08:44:51 -0400 Subject: [PATCH 11/11] asdf.lisp: shorten line length --- asdf.lisp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/asdf.lisp b/asdf.lisp index 5c81c785..1aaf853e 100644 --- a/asdf.lisp +++ b/asdf.lisp @@ -136,11 +136,12 @@ search path will be the directory of the parent component." (defmethod perform ((operation proto-to-lisp) (component protobuf-source-file)) (let* ((source-file (first (input-files operation component))) (source-file-argument (if (proto-pathname component) - ;; If a PROTO-PATHNAME is specified in the component, use only the - ;; filename and type as the argument to protoc. + ;; If a PROTO-PATHNAME is specified in the component, use + ;; only the filename and type as the argument to protoc. (file-namestring source-file) - ;; If a PROTO-PATHNAME is not specified in the component, use the - ;; entire PROTOBUF-SOURCE-FILE + .proto as the argument to protoc. + ;; If a PROTO-PATHNAME is not specified in the component, + ;; use the entire PROTOBUF-SOURCE-FILE + .proto as the + ;; argument to protoc. (namestring source-file))) ;; Around methods on output-file may globally redirect output products, so we must call ;; that method instead of executing (component-pathname component). @@ -153,11 +154,14 @@ search path will be the directory of the parent component." (directory-namestring output-file) source-file-argument))) (multiple-value-bind (output error-output status) - (uiop:run-program command :output '(:string :stripped t) :error-output :output :ignore-error-status t) + (uiop:run-program command :output '(:string :stripped t) + :error-output :output + :ignore-error-status t) (declare (ignore error-output)) (unless (zerop status) (error 'protobuf-compile-failed - :description (format nil "Failed to compile proto file. Command: ~S Error: ~S" command output) + :description (format nil "Failed to compile proto file. Command: ~S Error: ~S" + command output) :context-format "~/asdf-action::format-action/" :context-arguments `((,operation . ,component)))))))