reflect/prototype: add NewGoEnum and NewGoMessage constructors

Add constructors for creating protoreflect.{Enum,Message}Type,
which extend the protobuf descriptor with Go type information.

Rationale for API:
* NewGoEnum and NewGoMessage take in a struct instead of multiple
function parameters to provide future flexibility in adding more parameters.
* NewGoEnum and NewGoMessage take in a pointer to a struct so that generated
code can batch allocate these structs and convert them to them to EnumTypes
or MessageTypes efficiently. In other words, allocations are entirely in the
control of the caller.
* The user provides a New function as opposed to a reflect.Type or pointer to
the concrete type to support dynamic protobufs, where a single Go type may be
used to represent multiple protobuf types.
* The New functions take in an EnumType or MessageType since an implementation
for dynamic protobufs would need to close over these types. All statically
generated messages can ignore that argument.

There are no tests added since these are just wrappers;
they will be heavily exercised by other code.

Change-Id: I9fca44e06f3388375be7eaca94f8fd75c17233a3
Reviewed-on: https://go-review.googlesource.com/135356
Reviewed-by: Damien Neil <dneil@google.com>
1 file changed
tree: 1cd515404488825a5cfb04e77994879e278446b6
  1. cmd/
  2. internal/
  3. protogen/
  4. reflect/
  5. .gitignore
  6. .travis.yml
  7. AUTHORS
  8. CONTRIBUTING.md
  9. CONTRIBUTORS
  10. go.mod
  11. go.sum
  12. LICENSE
  13. PATENTS
  14. README.md
  15. regenerate.bash
  16. test.bash
README.md

Next Generation Go Protocol Buffers

WARNING: This repository is in active development. There are no guarantees about API stability. Breaking changes will occur until a stable release is made and announced.

This repository is for the development of the next major Go implementation of protocol buffers. This library makes breaking API changes relative to the existing Go protobuf library. Of particular note, this API aims to make protobuf reflection a first-class feature of the API and implements the protobuf ecosystem in terms of reflection.

Design Documents

List of relevant design documents:

Contributing

We appreciate community contributions. See CONTRIBUTING.md.

Reporting Issues

Issues regarding the new API can be filed at github.com/golang/protobuf. Please use a APIv2: prefix in the title to make it clear that the issue is regarding the new API work.