protoopts

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 1, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package protoopts reads the sync custom options — (syncplane.v1.entity), (syncplane.v1.reference) and (syncplane.v1.field_behavior) — off proto descriptors.

Reading them with proto.GetExtension alone ties the result to the Go type identity of the extension: it resolves only when the descriptor's options were parsed against this module's syncplane/v1/options.proto. An app that vendors options.proto and generates its own Go package for it produces descriptors whose options carry the same field numbers but a foreign extension type, and GetExtension reads nothing — the message looks unannotated even though the .proto is correct.

The wire bytes are identical in both cases, so when the fast path finds nothing this package re-parses the descriptor's uninterpreted option bytes against a private registry holding only this module's extensions. That binds field 50100/50101 to the types the engine compiled against, whatever produced the descriptor.

Recovery is a backstop, not the intended setup: an app whose generated code registers a second syncplane/v1/options.proto trips protobuf-go's global registry and panics at init long before it reaches here. See the README section "Defining entities in your own module" for the codegen configuration that keeps a vendored options.proto pointing at this module's Go package.

Index

Constants

This section is empty.

Variables

View Source
var OptionsGoPackage = func() string {
	opts, _ := syncplanev1.File_syncplane_v1_options_proto.Options().(*descriptorpb.FileOptions)

	path, _, _ := strings.Cut(opts.GetGoPackage(), ";")
	return path
}()

OptionsGoPackage is the Go import path a vendored syncplane/v1/options.proto must keep as its go_package so an app's generated code shares this module's extension types instead of registering a second copy. Derived from the compiled descriptor so it stays correct if the package ever moves.

Functions

func Entity

Entity returns the (syncplane.v1.entity) options declared on md, or nil when md is not an entity.

func FieldBehavior

FieldBehavior returns the (syncplane.v1.field_behavior) options declared on fd, or nil when the field carries none. Callers can use the getters on a nil value.

func HasUninterpretedOptions

func HasUninterpretedOptions(md protoreflect.MessageDescriptor) bool

HasUninterpretedOptions reports whether md carries option bytes no extension in this process could interpret. On a message that should be an entity but reads as unannotated, that is the signature of a divergent syncplane/v1/options.proto — it distinguishes "never annotated" from "annotated against a different extension type", which Entity alone cannot.

Unrelated third-party message options also land here, so this is a hint for an error message, not a verdict.

func Reference

Reference returns the (syncplane.v1.reference) options declared on md, or nil when md is not a reference message. The options carry no fields; a non-nil result is the declaration itself.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL