Documentation
¶
Overview ¶
Package protoscope lets protobuf-go build a descriptor from a file that protobuf-java accepts and protoc refuses: one whose enums share a value name.
protobuf-java scopes an enum value under its enum type (its full name is the enum's full name plus the value), so two enums of one scope may both declare Y. protoc and protobuf-go scope a value BESIDE its enum, in the enum's enclosing scope, so the two Ys collide and protodesc.NewFile refuses the file ("descriptor Y already declared"). Java's relational DDL stores exactly such files (`create type as enum e1('X','Y') create type as enum e2('Y','Z')`), so Go could neither open a store Java created that way nor create one.
The fix is confined to the IN-MEMORY descriptor. ScopeEnumValuesAsJava rewrites a clone the caller builds from: each enum whose values collide in its scope moves into a synthetic message of its own, and every reference to it follows. The stored bytes never pass through it (the record layer re-emits the retained source proto, the relational builder emits its own proto), and JavaFullName answers an enum's full name as Java reads it, so nothing a query or an error names shows the synthetic scope.
Where it applies: files Java synthesizes (the relational records file) and files Go synthesizes (the planner's type file). A file protoc compiled cannot carry such a collision, so a dependency file never needs it.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func JavaFullName ¶
func JavaFullName(ed protoreflect.EnumDescriptor) protoreflect.FullName
JavaFullName is an enum's full name as protobuf-java reads it: its full name without the synthetic scope ScopeEnumValuesAsJava may have given it.
func JavaName ¶
func JavaName(ed protoreflect.EnumDescriptor) protoreflect.Name
JavaName is an enum's name as protobuf-java reads it. An enum scoped into a holder keeps its name there unless it was renamed (selfScopedName); either way the holder's name, `<scopePrefix><index>_<name>`, carries the original.
func ScopeEnumValuesAsJava ¶
func ScopeEnumValuesAsJava(fdp *descriptorpb.FileDescriptorProto)
ScopeEnumValuesAsJava rewrites fdp IN PLACE, so a caller passes the clone it builds the in-memory descriptor from. Type names must already be absolute (the callers absolutize first). A file with no colliding enum value is left exactly as it was, and a nil file is the caller's to refuse: a metadata with no records file reaches here before its build fails.
Types ¶
This section is empty.