Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,10 @@ checkgenerate:
@# Used in CI to verify that `make generate` doesn't produce a diff.
git --no-pager diff --exit-code >&2

internal/gen/*/*.pb.go: $(BIN)/buf internal/proto/*/*/*.proto internal/proto/*/*/*/*.proto
internal/gen/*/*.pb.go: $(BIN)/buf internal/proto/*/*/*.proto internal/proto/*/*/*/*.proto internal/gencode/* internal/gencode/generator/*
$(BIN)/buf generate --clean
$(BIN)/buf generate --template buf.gen.vt.yaml
$(BIN)/buf generate --template buf.gen.hyperpb.yaml

.PHONY: $(BIN)/hypertest
$(BIN)/hypertest: generate
Expand Down
12 changes: 12 additions & 0 deletions buf.gen.hyperpb.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: v2
managed:
enabled: true
override:
- file_option: go_package_prefix
value: buf.build/go/hyperpb/internal/gen
plugins:
- local: ["go", "run", "./cmd/protoc-gen-hyperpb"]
out: internal/gen
opt: paths=source_relative
inputs:
- directory: internal/proto/test
43 changes: 43 additions & 0 deletions cmd/protoc-gen-hyperpb/export/export.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright 2025 Buf Technologies, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Package export contains exported types and functions for use by gencode.
//
// Importing this package outside of the gencode voids any API compatibility
// guarantees.
package export

import (
"google.golang.org/protobuf/reflect/protoreflect"

"buf.build/go/hyperpb/internal/gencode"
"buf.build/go/hyperpb/internal/tdp/repeated"
"buf.build/go/hyperpb/internal/xunsafe"
)

type (
DoNotImplement = gencode.DoNotImplement
Type = gencode.Type
UnsafeMessage = gencode.UnsafeMessage
)

func Reflect[P gencode.Message[M], M any](m P) protoreflect.Message { return gencode.Reflect(m) }

func CastRepeatedEnum[E ~int32](r *repeated.Scalars[byte, protoreflect.EnumNumber]) *repeated.Scalars[byte, E] {
return xunsafe.Cast[repeated.Scalars[byte, E]](r)
}

func CastRepeatedMessage[P gencode.Message[M], M any](r *repeated.UntypedMessages) *repeated.Messages[M, P] {
return xunsafe.Cast[repeated.Messages[M, P]](r)
}
34 changes: 34 additions & 0 deletions cmd/protoc-gen-hyperpb/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2025 Buf Technologies, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Binary protoc-gen-hyperpb is a protoc plugin that generates Protobuf APIs for
// working with specific hyperpb-compiled messages without reflection.
//
// The generated API follows, but is not a drop-in replacement for, the opaque
// Go API, particularly returning non-slice values for accessing repeated
// fields.
//
// All message types emitted by this generator export the full interface of
// [hyperpb.Message], which can be used to access optimized operations, such
// as [hyperpb.Message.Unmarshal].
package main

import (
"buf.build/go/hyperpb"
"buf.build/go/hyperpb/internal/gencode/generator"
)

func main() { generator.Main() }

var _ hyperpb.Message // For documentation links.
Loading
Loading