From c7628e3b6ad3dcd17d1a875390bf4261deb870c9 Mon Sep 17 00:00:00 2001
From: Julian Figueroa <jfigueroa@buf.build>
Date: Tue, 14 Jan 2025 12:56:59 -0500
Subject: [PATCH] Move to `OPAQUE` (#811)

Fixes https://github.com/bufbuild/modules/issues/813
---
 Makefile                                      |   1 -
 buf.gen.yaml                                  |   2 +-
 cmd/release/main_test.go                      |  66 +--
 go.mod                                        |   3 +
 go.sum                                        |   6 +
 internal/githubutil/githubutil.go             |  10 +-
 private/bufpkg/bufstate/global_state.go       |  22 +-
 private/bufpkg/bufstate/global_state_test.go  |  46 +-
 private/bufpkg/bufstate/module_state.go       |  19 +-
 private/bufpkg/bufstate/module_state_test.go  |  50 +--
 private/bufpkg/bufstate/state.go              |  12 +-
 .../gen/modules/state/v1alpha1/state.pb.go    |  78 ++--
 .../state/v1alpha1/state_protoopaque.pb.go    | 423 ------------------
 13 files changed, 170 insertions(+), 568 deletions(-)
 delete mode 100644 private/gen/modules/state/v1alpha1/state_protoopaque.pb.go

diff --git a/Makefile b/Makefile
index e869924f..5628530b 100644
--- a/Makefile
+++ b/Makefile
@@ -43,7 +43,6 @@ install: ## Install all binaries
 .PHONY: lint
 lint: $(BIN)/golangci-lint $(BIN)/buf ## Lint Go and protobuf
 	test -z "$$($(BIN)/buf format -d . | tee /dev/stderr)"
-	$(GO) vet ./...
 	$(BIN)/golangci-lint run
 	$(BIN)/buf format -d --exit-code
 
diff --git a/buf.gen.yaml b/buf.gen.yaml
index 5863bd2f..ac5dd68a 100644
--- a/buf.gen.yaml
+++ b/buf.gen.yaml
@@ -4,4 +4,4 @@ plugins:
     out: private/gen/modules
     opt:
       - paths=source_relative
-      - default_api_level=API_HYBRID
+      - default_api_level=API_OPAQUE
diff --git a/cmd/release/main_test.go b/cmd/release/main_test.go
index bab85f53..8f00fe4d 100644
--- a/cmd/release/main_test.go
+++ b/cmd/release/main_test.go
@@ -44,10 +44,10 @@ func TestCalculateNewReleaseModules(t *testing.T) {
 		assertModuleStates(t, map[string]releaseModuleState{
 			"envoyproxy/envoy": {
 				status: modules.New,
-				references: []*statev1alpha1.ModuleReference{{
+				references: []*statev1alpha1.ModuleReference{statev1alpha1.ModuleReference_builder{
 					Name:   "bb554f53ad8d3a2a2ae4cbd7102a3e20ae00b558",
 					Digest: "dummyManifestDigestEnvoy",
-				}},
+				}.Build()},
 			}}, got)
 		assert.True(t, shouldRelease(got))
 	})
@@ -65,10 +65,10 @@ func TestCalculateNewReleaseModules(t *testing.T) {
 		assertModuleStates(t, map[string]releaseModuleState{
 			"envoyproxy/envoy": {
 				status: modules.Updated,
-				references: []*statev1alpha1.ModuleReference{{
+				references: []*statev1alpha1.ModuleReference{statev1alpha1.ModuleReference_builder{
 					Name:   "7850b6bb6494e3bfc093b1aff20282ab30b67940",
 					Digest: "updatedDummyManifestDigestEnvoy",
-				}},
+				}.Build()},
 			}}, got)
 		assert.True(t, shouldRelease(got))
 	})
@@ -109,17 +109,17 @@ func TestCalculateNewReleaseModules(t *testing.T) {
 			},
 			"envoyproxy/envoy": {
 				status: modules.Updated,
-				references: []*statev1alpha1.ModuleReference{{
+				references: []*statev1alpha1.ModuleReference{statev1alpha1.ModuleReference_builder{
 					Name:   "7850b6bb6494e3bfc093b1aff20282ab30b67940",
 					Digest: "updatedDummyManifestDigestEnvoy",
-				}},
+				}.Build()},
 			},
 			"gogo/protobuf": {
 				status: modules.New,
-				references: []*statev1alpha1.ModuleReference{{
+				references: []*statev1alpha1.ModuleReference{statev1alpha1.ModuleReference_builder{
 					Name:   "8892e00f944642b7dc8d81b419879fd4be12f056",
 					Digest: "newDummyManifestDigestGogoProtobuf",
-				}},
+				}.Build()},
 			}}, got)
 		assert.True(t, shouldRelease(got))
 	})
@@ -143,14 +143,14 @@ func TestCalculateNewReleaseModules(t *testing.T) {
 			"envoyproxy/envoy": {
 				status: modules.Updated,
 				references: []*statev1alpha1.ModuleReference{
-					{
+					statev1alpha1.ModuleReference_builder{
 						Name:   "v0.1.0",
 						Digest: "dummyManifestDigestEnvoy",
-					},
-					{
+					}.Build(),
+					statev1alpha1.ModuleReference_builder{
 						Name:   "v0.2.0",
 						Digest: "updatedDummyManifestDigestEnvoy",
-					},
+					}.Build(),
 				},
 			}}, got)
 		assert.True(t, shouldRelease(got))
@@ -177,17 +177,17 @@ func TestCalculateNewReleaseModules(t *testing.T) {
 			},
 			"new/foo": {
 				status: modules.New,
-				references: []*statev1alpha1.ModuleReference{{
+				references: []*statev1alpha1.ModuleReference{statev1alpha1.ModuleReference_builder{
 					Name:   "ref3",
 					Digest: "dummyManifestDigestNewFoo",
-				}},
+				}.Build()},
 			},
 			"new/bar": {
 				status: modules.New,
-				references: []*statev1alpha1.ModuleReference{{
+				references: []*statev1alpha1.ModuleReference{statev1alpha1.ModuleReference_builder{
 					Name:   "ref4",
 					Digest: "dummyManifestDigestNewBar",
-				}},
+				}.Build()},
 			}}, got)
 		assert.True(t, shouldRelease(got))
 	})
@@ -205,17 +205,17 @@ func TestMapGlobalStateReferences(t *testing.T) {
 	t.Run("not_nil_state", func(t *testing.T) {
 		t.Parallel()
 
-		globalState := &statev1alpha1.GlobalState{
+		globalState := statev1alpha1.GlobalState_builder{
 			Modules: []*statev1alpha1.GlobalStateReference{
-				{
+				statev1alpha1.GlobalStateReference_builder{
 					ModuleName:      "test-org/test-repo",
 					LatestReference: "v1.0.0",
-				}, {
+				}.Build(), statev1alpha1.GlobalStateReference_builder{
 					ModuleName:      "other-org/other-repo",
 					LatestReference: "v1.0.0",
-				},
+				}.Build(),
 			},
-		}
+		}.Build()
 		got := mapGlobalStateReferences(globalState)
 		require.Equal(t, map[string]string{
 			"test-org/test-repo":   "v1.0.0",
@@ -232,13 +232,13 @@ func TestCreateReleaseBody(t *testing.T) {
 			"test-org/test-repo": {
 				status: modules.New,
 				references: []*statev1alpha1.ModuleReference{
-					{
+					statev1alpha1.ModuleReference_builder{
 						Name:   "v1.0.0",
 						Digest: "fakedigest",
-					}, {
+					}.Build(), statev1alpha1.ModuleReference_builder{
 						Name:   "v1.1.0",
 						Digest: "fakedigest",
-					},
+					}.Build(),
 				},
 			},
 		}
@@ -267,25 +267,25 @@ func TestCreateReleaseBody(t *testing.T) {
 			"test-org/new-repo": {
 				status: modules.New,
 				references: []*statev1alpha1.ModuleReference{
-					{
+					statev1alpha1.ModuleReference_builder{
 						Name:   "v1.0.0",
 						Digest: "fakedigest",
-					}, {
+					}.Build(), statev1alpha1.ModuleReference_builder{
 						Name:   "v1.1.0",
 						Digest: "fakedigest",
-					},
+					}.Build(),
 				},
 			},
 			"test-org/updated-repo": {
 				status: modules.Updated,
 				references: []*statev1alpha1.ModuleReference{
-					{
+					statev1alpha1.ModuleReference_builder{
 						Name:   "v1.0.0",
 						Digest: "fakedigest",
-					}, {
+					}.Build(), statev1alpha1.ModuleReference_builder{
 						Name:   "v1.1.0",
 						Digest: "fakedigest",
-					},
+					}.Build(),
 				},
 			},
 		}
@@ -341,7 +341,7 @@ func TestCreateReleaseBody(t *testing.T) {
 			//nolint:exhaustive // other module states should not have any reference
 			switch state {
 			case modules.New, modules.Updated:
-				references = []*statev1alpha1.ModuleReference{{Name: "v1.0.0", Digest: "fakedigest"}}
+				references = []*statev1alpha1.ModuleReference{statev1alpha1.ModuleReference_builder{Name: "v1.0.0", Digest: "fakedigest"}.Build()}
 			}
 			// map order is not guaranteed
 			mods[modName] = releaseModuleState{
@@ -437,10 +437,10 @@ func TestWriteReferencesTable(t *testing.T) {
 	populateReferences := func(refsCount int) []*statev1alpha1.ModuleReference {
 		refs := make([]*statev1alpha1.ModuleReference, refsCount)
 		for i := range refsCount {
-			refs[i] = &statev1alpha1.ModuleReference{
+			refs[i] = statev1alpha1.ModuleReference_builder{
 				Name:   fmt.Sprintf("commit%03d", i),
 				Digest: fmt.Sprintf("digest%03d", i),
-			}
+			}.Build()
 		}
 		return refs
 	}
diff --git a/go.mod b/go.mod
index 9ba98747..a50d81e2 100644
--- a/go.mod
+++ b/go.mod
@@ -17,8 +17,10 @@ require (
 )
 
 require (
+	buf.build/go/protoyaml v0.3.1 // indirect
 	cel.dev/expr v0.19.1 // indirect
 	github.com/antlr4-go/antlr/v4 v4.13.1 // indirect
+	github.com/bufbuild/protocompile v0.14.1 // indirect
 	github.com/davecgh/go-spew v1.1.1 // indirect
 	github.com/google/cel-go v0.22.1 // indirect
 	github.com/google/go-querystring v1.1.0 // indirect
@@ -27,6 +29,7 @@ require (
 	github.com/stoewer/go-strcase v1.3.0 // indirect
 	golang.org/x/crypto v0.31.0 // indirect
 	golang.org/x/exp v0.0.0-20250103183323-7d7fa50e5329 // indirect
+	golang.org/x/sync v0.10.0 // indirect
 	golang.org/x/sys v0.29.0 // indirect
 	golang.org/x/text v0.21.0 // indirect
 	google.golang.org/genproto/googleapis/api v0.0.0-20250102185135-69823020774d // indirect
diff --git a/go.sum b/go.sum
index 15373335..a5ed1628 100644
--- a/go.sum
+++ b/go.sum
@@ -1,11 +1,15 @@
 buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.2-20241127180247-a33202765966.1 h1:BICM6du/XzvEgeorNo4xgohK3nMTmEPViGyd5t7xVqk=
 buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.2-20241127180247-a33202765966.1/go.mod h1:JnMVLi3qrNYPODVpEKG7UjHLl/d2zR221e66YCSmP2Q=
+buf.build/go/protoyaml v0.3.1 h1:ucyzE7DRnjX+mQ6AH4JzN0Kg50ByHHu+yrSKbgQn2D4=
+buf.build/go/protoyaml v0.3.1/go.mod h1:0TzNpFQDXhwbkXb/ajLvxIijqbve+vMQvWY/b3/Dzxg=
 cel.dev/expr v0.19.1 h1:NciYrtDRIR0lNCnH1LFJegdjspNx9fI59O7TWcua/W4=
 cel.dev/expr v0.19.1/go.mod h1:MrpN08Q+lEBs+bGYdLxxHkZoUSsCp0nSKTs0nTymJgw=
 github.com/antlr4-go/antlr/v4 v4.13.1 h1:SqQKkuVZ+zWkMMNkjy5FZe5mr5WURWnlpmOuzYWrPrQ=
 github.com/antlr4-go/antlr/v4 v4.13.1/go.mod h1:GKmUxMtwp6ZgGwZSva4eWPC5mS6vUAmOABFgjdkM7Nw=
 github.com/bufbuild/buf v1.49.0 h1:KFSyea50xgvfnqGfK7Z4UCPTYhoCoUYAK2IoRd8/oUA=
 github.com/bufbuild/buf v1.49.0/go.mod h1:PssF/YByu7WU6K3FxRmoRxi4ZViugL7rjAaoVvxknso=
+github.com/bufbuild/protocompile v0.14.1 h1:iA73zAf/fyljNjQKwYzUHD6AD4R8KMasmwa/FBatYVw=
+github.com/bufbuild/protocompile v0.14.1/go.mod h1:ppVdAIhbr2H8asPk6k4pY7t9zB1OU5DoEw9xY/FUi1c=
 github.com/bufbuild/protovalidate-go v0.8.2 h1:sgzXHkHYP6HnAsL2Rd3I1JxkYUyEQUv9awU1PduMxbM=
 github.com/bufbuild/protovalidate-go v0.8.2/go.mod h1:K6w8iPNAXBoIivVueSELbUeUl+MmeTQfCDSug85pn3M=
 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -64,6 +68,8 @@ golang.org/x/mod v0.22.0 h1:D4nJWe9zXqHOmWqj4VMOJhvzj7bEZg4wEYa759z1pH4=
 golang.org/x/mod v0.22.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
 golang.org/x/oauth2 v0.25.0 h1:CY4y7XT9v0cRI9oupztF8AgiIu99L/ksR/Xp/6jrZ70=
 golang.org/x/oauth2 v0.25.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
+golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
+golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
 golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
 golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
 golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
diff --git a/internal/githubutil/githubutil.go b/internal/githubutil/githubutil.go
index b28fd69f..af8514d1 100644
--- a/internal/githubutil/githubutil.go
+++ b/internal/githubutil/githubutil.go
@@ -16,7 +16,6 @@ package githubutil
 
 import (
 	"context"
-	"encoding/json"
 	"errors"
 	"fmt"
 	"io"
@@ -26,6 +25,7 @@ import (
 	"strings"
 	"time"
 
+	"github.com/bufbuild/buf/private/pkg/protoencoding"
 	"github.com/bufbuild/modules/private/bufpkg/bufstate"
 	statev1alpha1 "github.com/bufbuild/modules/private/gen/modules/state/v1alpha1"
 	"github.com/google/go-github/v64/github"
@@ -191,15 +191,15 @@ func (c *Client) DownloadReleaseState(
 	ctx context.Context,
 	release *github.RepositoryRelease,
 ) (*statev1alpha1.GlobalState, error) {
-	manifestBytes, _, err := c.downloadAsset(ctx, release, bufstate.ModStateFileName)
+	data, _, err := c.downloadAsset(ctx, release, bufstate.ModStateFileName)
 	if err != nil {
 		return nil, err
 	}
-	var moduleReleases statev1alpha1.GlobalState
-	if err := json.Unmarshal(manifestBytes, &moduleReleases); err != nil {
+	var globalState statev1alpha1.GlobalState
+	if err := protoencoding.NewJSONUnmarshaler(protoencoding.EmptyResolver).Unmarshal(data, &globalState); err != nil {
 		return nil, err
 	}
-	return &moduleReleases, nil
+	return &globalState, nil
 }
 
 // downloadAsset uses the GitHub API to download the asset with the given name from the release.
diff --git a/private/bufpkg/bufstate/global_state.go b/private/bufpkg/bufstate/global_state.go
index f61924a4..a13202be 100644
--- a/private/bufpkg/bufstate/global_state.go
+++ b/private/bufpkg/bufstate/global_state.go
@@ -15,11 +15,11 @@
 package bufstate
 
 import (
-	"encoding/json"
 	"fmt"
 	"io"
 	"sort"
 
+	"github.com/bufbuild/buf/private/pkg/protoencoding"
 	statev1alpha1 "github.com/bufbuild/modules/private/gen/modules/state/v1alpha1"
 	"go.uber.org/multierr"
 )
@@ -33,12 +33,16 @@ func (rw *ReadWriter) ReadGlobalState(reader io.ReadCloser) (_ *statev1alpha1.Gl
 			retErr = multierr.Append(retErr, fmt.Errorf("close file: %w", err))
 		}
 	}()
+	bytes, err := io.ReadAll(reader)
+	if err != nil {
+		return nil, fmt.Errorf("read global state file: %w", err)
+	}
 	var globalState statev1alpha1.GlobalState
-	if err := json.NewDecoder(reader).Decode(&globalState); err != nil {
-		return nil, fmt.Errorf("read file: %w", err)
+	if err := protoencoding.NewJSONUnmarshaler(protoencoding.EmptyResolver).Unmarshal(bytes, &globalState); err != nil {
+		return nil, fmt.Errorf("unmarshal global state: %w", err)
 	}
 	if err := rw.validator.Validate(&globalState); err != nil {
-		return nil, fmt.Errorf("validate: %w", err)
+		return nil, fmt.Errorf("validate global state: %w", err)
 	}
 	return &globalState, nil
 }
@@ -57,10 +61,14 @@ func (rw *ReadWriter) WriteGlobalState(writer io.WriteCloser, globalState *state
 	sort.Slice(mods, func(i, j int) bool {
 		return mods[i].GetModuleName() < mods[j].GetModuleName()
 	})
-	globalState.Modules = mods
-	data, err := json.MarshalIndent(globalState, "", "  ")
+	globalState.SetModules(mods)
+	data, err := protoencoding.NewJSONMarshaler(
+		protoencoding.EmptyResolver,
+		protoencoding.JSONMarshalerWithUseProtoNames(),
+		protoencoding.JSONMarshalerWithIndent(),
+	).Marshal(globalState)
 	if err != nil {
-		return fmt.Errorf("json marshal state: %w", err)
+		return fmt.Errorf("marshal global state: %w", err)
 	}
 	if _, err := writer.Write(data); err != nil {
 		return fmt.Errorf("write to file: %w", err)
diff --git a/private/bufpkg/bufstate/global_state_test.go b/private/bufpkg/bufstate/global_state_test.go
index ab7f545e..3c5626f4 100644
--- a/private/bufpkg/bufstate/global_state_test.go
+++ b/private/bufpkg/bufstate/global_state_test.go
@@ -31,21 +31,21 @@ func TestValidGlobalStates(t *testing.T) {
 	})
 	t.Run("valid", func(t *testing.T) {
 		t.Parallel()
-		require.NoError(t, readWriter.validator.Validate(&statev1alpha1.GlobalState{
+		require.NoError(t, readWriter.validator.Validate(statev1alpha1.GlobalState_builder{
 			Modules: []*statev1alpha1.GlobalStateReference{
-				{ModuleName: "aaa/bbb", LatestReference: "foo"},
-				{ModuleName: "ccc/ddd", LatestReference: "bar"},
+				statev1alpha1.GlobalStateReference_builder{ModuleName: "aaa/bbb", LatestReference: "foo"}.Build(),
+				statev1alpha1.GlobalStateReference_builder{ModuleName: "ccc/ddd", LatestReference: "bar"}.Build(),
 			},
-		}))
+		}.Build()))
 	})
 	t.Run("repeatedReferencesForDifferentModules", func(t *testing.T) {
 		t.Parallel()
-		require.NoError(t, readWriter.validator.Validate(&statev1alpha1.GlobalState{
+		require.NoError(t, readWriter.validator.Validate(statev1alpha1.GlobalState_builder{
 			Modules: []*statev1alpha1.GlobalStateReference{
-				{ModuleName: "aaa/bbb", LatestReference: "foo"},
-				{ModuleName: "ccc/ddd", LatestReference: "foo"},
+				statev1alpha1.GlobalStateReference_builder{ModuleName: "aaa/bbb", LatestReference: "foo"}.Build(),
+				statev1alpha1.GlobalStateReference_builder{ModuleName: "ccc/ddd", LatestReference: "foo"}.Build(),
 			},
-		}))
+		}.Build()))
 	})
 }
 
@@ -55,35 +55,35 @@ func TestInvalidGlobalStates(t *testing.T) {
 	require.NoError(t, err)
 	t.Run("repeatedModules", func(t *testing.T) {
 		t.Parallel()
-		err := readWriter.validator.Validate(&statev1alpha1.GlobalState{
+		err := readWriter.validator.Validate(statev1alpha1.GlobalState_builder{
 			Modules: []*statev1alpha1.GlobalStateReference{
-				{ModuleName: "aaa/bbb", LatestReference: "foo"},
-				{ModuleName: "aaa/bbb", LatestReference: "bar"},
-				{ModuleName: "aaa/ccc", LatestReference: "baz"},
+				statev1alpha1.GlobalStateReference_builder{ModuleName: "aaa/bbb", LatestReference: "foo"}.Build(),
+				statev1alpha1.GlobalStateReference_builder{ModuleName: "aaa/bbb", LatestReference: "bar"}.Build(),
+				statev1alpha1.GlobalStateReference_builder{ModuleName: "aaa/ccc", LatestReference: "baz"}.Build(),
 			},
-		})
+		}.Build())
 		require.Contains(t, err.Error(), "module name aaa/bbb has appeared multiple times")
 	})
 	t.Run("emptyReferences", func(t *testing.T) {
 		t.Parallel()
-		err := readWriter.validator.Validate(&statev1alpha1.GlobalState{
+		err := readWriter.validator.Validate(statev1alpha1.GlobalState_builder{
 			Modules: []*statev1alpha1.GlobalStateReference{
-				{ModuleName: "aaa/bbb", LatestReference: "foo"},
-				{ModuleName: "aaa/ccc", LatestReference: ""},
-				{ModuleName: "aaa/ddd", LatestReference: "bar"},
+				statev1alpha1.GlobalStateReference_builder{ModuleName: "aaa/bbb", LatestReference: "foo"}.Build(),
+				statev1alpha1.GlobalStateReference_builder{ModuleName: "aaa/ccc", LatestReference: ""}.Build(),
+				statev1alpha1.GlobalStateReference_builder{ModuleName: "aaa/ddd", LatestReference: "bar"}.Build(),
 			},
-		})
+		}.Build())
 		require.Contains(t, err.Error(), "modules[1].latest_reference: value is required")
 	})
 	t.Run("emptyModuleNames", func(t *testing.T) {
 		t.Parallel()
-		err := readWriter.validator.Validate(&statev1alpha1.GlobalState{
+		err := readWriter.validator.Validate(statev1alpha1.GlobalState_builder{
 			Modules: []*statev1alpha1.GlobalStateReference{
-				{ModuleName: "aaa/bbb", LatestReference: "foo"},
-				{ModuleName: "", LatestReference: "foo"},
-				{ModuleName: "aaa/ddd", LatestReference: "bar"},
+				statev1alpha1.GlobalStateReference_builder{ModuleName: "aaa/bbb", LatestReference: "foo"}.Build(),
+				statev1alpha1.GlobalStateReference_builder{ModuleName: "", LatestReference: "foo"}.Build(),
+				statev1alpha1.GlobalStateReference_builder{ModuleName: "aaa/ddd", LatestReference: "bar"}.Build(),
 			},
-		})
+		}.Build())
 		require.Contains(t, err.Error(), "modules[1].module_name: value is required")
 	})
 }
diff --git a/private/bufpkg/bufstate/module_state.go b/private/bufpkg/bufstate/module_state.go
index 8af5a6e4..09f5d900 100644
--- a/private/bufpkg/bufstate/module_state.go
+++ b/private/bufpkg/bufstate/module_state.go
@@ -15,10 +15,10 @@
 package bufstate
 
 import (
-	"encoding/json"
 	"fmt"
 	"io"
 
+	"github.com/bufbuild/buf/private/pkg/protoencoding"
 	statev1alpha1 "github.com/bufbuild/modules/private/gen/modules/state/v1alpha1"
 	"go.uber.org/multierr"
 )
@@ -32,9 +32,13 @@ func (rw *ReadWriter) ReadModStateFile(readCloser io.ReadCloser) (_ *statev1alph
 			retErr = multierr.Append(retErr, fmt.Errorf("close file: %w", err))
 		}
 	}()
+	bytes, err := io.ReadAll(readCloser)
+	if err != nil {
+		return nil, fmt.Errorf("read module state file: %w", err)
+	}
 	var moduleState statev1alpha1.ModuleState
-	if err := json.NewDecoder(readCloser).Decode(&moduleState); err != nil {
-		return nil, fmt.Errorf("read file: %w", err)
+	if err := protoencoding.NewJSONUnmarshaler(protoencoding.EmptyResolver).Unmarshal(bytes, &moduleState); err != nil {
+		return nil, fmt.Errorf("unmarshal module state: %w", err)
 	}
 	if err := rw.validator.Validate(&moduleState); err != nil {
 		return nil, fmt.Errorf("validate: %w", err)
@@ -52,11 +56,14 @@ func (rw *ReadWriter) WriteModStateFile(writeCloser io.WriteCloser, moduleState
 	if err := rw.validator.Validate(moduleState); err != nil {
 		return fmt.Errorf("validate: %w", err)
 	}
-	data, err := json.MarshalIndent(moduleState, "", "  ")
+	data, err := protoencoding.NewJSONMarshaler(
+		protoencoding.EmptyResolver,
+		protoencoding.JSONMarshalerWithUseProtoNames(),
+		protoencoding.JSONMarshalerWithIndent(),
+	).Marshal(moduleState)
 	if err != nil {
-		return fmt.Errorf("json marshal state: %w", err)
+		return fmt.Errorf("marshal module state: %w", err)
 	}
-
 	if _, err := writeCloser.Write(data); err != nil {
 		return fmt.Errorf("write to file: %w", err)
 	}
diff --git a/private/bufpkg/bufstate/module_state_test.go b/private/bufpkg/bufstate/module_state_test.go
index b7f068b8..20bc844c 100644
--- a/private/bufpkg/bufstate/module_state_test.go
+++ b/private/bufpkg/bufstate/module_state_test.go
@@ -31,26 +31,26 @@ func TestValidModuleStates(t *testing.T) {
 	})
 	t.Run("valid", func(t *testing.T) {
 		t.Parallel()
-		require.NoError(t, readWriter.validator.Validate(&statev1alpha1.ModuleState{
+		require.NoError(t, readWriter.validator.Validate(statev1alpha1.ModuleState_builder{
 			References: []*statev1alpha1.ModuleReference{
-				{Name: "commit1", Digest: "foo"},
-				{Name: "commit2", Digest: "bar"},
-				{Name: "v1.23.4", Digest: "baz"},
+				statev1alpha1.ModuleReference_builder{Name: "commit1", Digest: "foo"}.Build(),
+				statev1alpha1.ModuleReference_builder{Name: "commit2", Digest: "bar"}.Build(),
+				statev1alpha1.ModuleReference_builder{Name: "v1.23.4", Digest: "baz"}.Build(),
 			},
-		}))
+		}.Build()))
 	})
 	t.Run("repeatedDigestsForDifferentReferences", func(t *testing.T) {
 		// this happens all the time, many references with the same digest, meaning
 		// between those commits there were no changes in the relevant files that we
 		// sync.
 		t.Parallel()
-		require.NoError(t, readWriter.validator.Validate(&statev1alpha1.ModuleState{
+		require.NoError(t, readWriter.validator.Validate(statev1alpha1.ModuleState_builder{
 			References: []*statev1alpha1.ModuleReference{
-				{Name: "commit1", Digest: "foo"},
-				{Name: "commit2", Digest: "foo"},
-				{Name: "v1.23.4", Digest: "foo"},
+				statev1alpha1.ModuleReference_builder{Name: "commit1", Digest: "foo"}.Build(),
+				statev1alpha1.ModuleReference_builder{Name: "commit2", Digest: "foo"}.Build(),
+				statev1alpha1.ModuleReference_builder{Name: "v1.23.4", Digest: "foo"}.Build(),
 			},
-		}))
+		}.Build()))
 	})
 }
 
@@ -60,38 +60,38 @@ func TestInvalidModuleStates(t *testing.T) {
 	require.NoError(t, err)
 	t.Run("repeatedReferences", func(t *testing.T) {
 		t.Parallel()
-		err := readWriter.validator.Validate(&statev1alpha1.ModuleState{
+		err := readWriter.validator.Validate(statev1alpha1.ModuleState_builder{
 			References: []*statev1alpha1.ModuleReference{
-				{Name: "commit1", Digest: "foo"},
-				{Name: "commit1", Digest: "bar"},
-				{Name: "commit2", Digest: "baz"},
+				statev1alpha1.ModuleReference_builder{Name: "commit1", Digest: "foo"}.Build(),
+				statev1alpha1.ModuleReference_builder{Name: "commit1", Digest: "bar"}.Build(),
+				statev1alpha1.ModuleReference_builder{Name: "commit2", Digest: "baz"}.Build(),
 			},
-		})
+		}.Build())
 		require.Contains(t, err.Error(), "reference commit1 has appeared multiple times")
 	})
 	t.Run("emptyDigests", func(t *testing.T) {
 		// even if the reference has no files or empty content, an empty manifest
 		// still has a digest.
 		t.Parallel()
-		err := readWriter.validator.Validate(&statev1alpha1.ModuleState{
+		err := readWriter.validator.Validate(statev1alpha1.ModuleState_builder{
 			References: []*statev1alpha1.ModuleReference{
-				{Name: "commit1", Digest: "foo"},
-				{Name: "commit2", Digest: ""},
-				{Name: "commit3", Digest: "baz"},
+				statev1alpha1.ModuleReference_builder{Name: "commit1", Digest: "foo"}.Build(),
+				statev1alpha1.ModuleReference_builder{Name: "commit2", Digest: ""}.Build(),
+				statev1alpha1.ModuleReference_builder{Name: "commit3", Digest: "baz"}.Build(),
 			},
-		})
+		}.Build())
 		require.Contains(t, err.Error(), "references[1].digest: value is required")
 	})
 	t.Run("emptyReferenceNames", func(t *testing.T) {
 		// all commits should have a valid, unique reference
 		t.Parallel()
-		err := readWriter.validator.Validate(&statev1alpha1.ModuleState{
+		err := readWriter.validator.Validate(statev1alpha1.ModuleState_builder{
 			References: []*statev1alpha1.ModuleReference{
-				{Name: "commit1", Digest: "foo"},
-				{Name: "", Digest: "foo"},
-				{Name: "commit3", Digest: "baz"},
+				statev1alpha1.ModuleReference_builder{Name: "commit1", Digest: "foo"}.Build(),
+				statev1alpha1.ModuleReference_builder{Name: "", Digest: "foo"}.Build(),
+				statev1alpha1.ModuleReference_builder{Name: "commit3", Digest: "baz"}.Build(),
 			},
-		})
+		}.Build())
 		require.Contains(t, err.Error(), "references[1].name: value is required")
 	})
 }
diff --git a/private/bufpkg/bufstate/state.go b/private/bufpkg/bufstate/state.go
index 5a9dfe50..9302410e 100644
--- a/private/bufpkg/bufstate/state.go
+++ b/private/bufpkg/bufstate/state.go
@@ -53,7 +53,7 @@ func (rw *ReadWriter) AppendModuleReference(
 			return fmt.Errorf("read module state file: %w", err)
 		}
 	}
-	modState.References = append(modState.GetReferences(), &statev1alpha1.ModuleReference{Name: reference, Digest: digest})
+	modState.SetReferences(append(modState.GetReferences(), statev1alpha1.ModuleReference_builder{Name: reference, Digest: digest}.Build()))
 	// As the state file read/write functions both close after their operations,
 	// we need to re-open another io.WriteCloser here, the easiest way is to
 	// truncate the file with Create if it exists.
@@ -87,18 +87,18 @@ func (rw *ReadWriter) AppendModuleReference(
 	for i := range len(globalState.GetModules()) {
 		if globalState.GetModules()[i].GetModuleName() == moduleName {
 			found = true
-			globalState.GetModules()[i].LatestReference = reference
+			globalState.GetModules()[i].SetLatestReference(reference)
 			break
 		}
 	}
 	if !found {
-		globalState.Modules = append(
+		globalState.SetModules(append(
 			globalState.GetModules(),
-			&statev1alpha1.GlobalStateReference{
+			statev1alpha1.GlobalStateReference_builder{
 				ModuleName:      moduleName,
 				LatestReference: reference,
-			},
-		)
+			}.Build(),
+		))
 	}
 	// As the state file read/write functions both close after their operations,
 	// we need to re-open another io.WriteCloser here, the easiest way is to
diff --git a/private/gen/modules/state/v1alpha1/state.pb.go b/private/gen/modules/state/v1alpha1/state.pb.go
index 99cd2ca0..401ce7c5 100644
--- a/private/gen/modules/state/v1alpha1/state.pb.go
+++ b/private/gen/modules/state/v1alpha1/state.pb.go
@@ -18,8 +18,6 @@
 // 	protoc        (unknown)
 // source: state/v1alpha1/state.proto
 
-//go:build !protoopaque
-
 package v1alpha1
 
 import (
@@ -40,10 +38,10 @@ const (
 // reference from its local array of references. This is kept updated in a
 // global state file at the root sync directory.
 type GlobalState struct {
-	state         protoimpl.MessageState  `protogen:"hybrid.v1"`
-	Modules       []*GlobalStateReference `protobuf:"bytes,1,rep,name=modules,proto3" json:"modules,omitempty"`
-	unknownFields protoimpl.UnknownFields
-	sizeCache     protoimpl.SizeCache
+	state              protoimpl.MessageState   `protogen:"opaque.v1"`
+	xxx_hidden_Modules *[]*GlobalStateReference `protobuf:"bytes,1,rep,name=modules,proto3" json:"modules,omitempty"`
+	unknownFields      protoimpl.UnknownFields
+	sizeCache          protoimpl.SizeCache
 }
 
 func (x *GlobalState) Reset() {
@@ -73,13 +71,15 @@ func (x *GlobalState) ProtoReflect() protoreflect.Message {
 
 func (x *GlobalState) GetModules() []*GlobalStateReference {
 	if x != nil {
-		return x.Modules
+		if x.xxx_hidden_Modules != nil {
+			return *x.xxx_hidden_Modules
+		}
 	}
 	return nil
 }
 
 func (x *GlobalState) SetModules(v []*GlobalStateReference) {
-	x.Modules = v
+	x.xxx_hidden_Modules = &v
 }
 
 type GlobalState_builder struct {
@@ -92,18 +92,18 @@ func (b0 GlobalState_builder) Build() *GlobalState {
 	m0 := &GlobalState{}
 	b, x := &b0, m0
 	_, _ = b, x
-	x.Modules = b.Modules
+	x.xxx_hidden_Modules = &b.Modules
 	return m0
 }
 
 // GlobalReference is a single managed module reference with the latest
 // reference from its local array of references.
 type GlobalStateReference struct {
-	state           protoimpl.MessageState `protogen:"hybrid.v1"`
-	ModuleName      string                 `protobuf:"bytes,1,opt,name=module_name,json=moduleName,proto3" json:"module_name,omitempty"`
-	LatestReference string                 `protobuf:"bytes,2,opt,name=latest_reference,json=latestReference,proto3" json:"latest_reference,omitempty"`
-	unknownFields   protoimpl.UnknownFields
-	sizeCache       protoimpl.SizeCache
+	state                      protoimpl.MessageState `protogen:"opaque.v1"`
+	xxx_hidden_ModuleName      string                 `protobuf:"bytes,1,opt,name=module_name,json=moduleName,proto3" json:"module_name,omitempty"`
+	xxx_hidden_LatestReference string                 `protobuf:"bytes,2,opt,name=latest_reference,json=latestReference,proto3" json:"latest_reference,omitempty"`
+	unknownFields              protoimpl.UnknownFields
+	sizeCache                  protoimpl.SizeCache
 }
 
 func (x *GlobalStateReference) Reset() {
@@ -133,24 +133,24 @@ func (x *GlobalStateReference) ProtoReflect() protoreflect.Message {
 
 func (x *GlobalStateReference) GetModuleName() string {
 	if x != nil {
-		return x.ModuleName
+		return x.xxx_hidden_ModuleName
 	}
 	return ""
 }
 
 func (x *GlobalStateReference) GetLatestReference() string {
 	if x != nil {
-		return x.LatestReference
+		return x.xxx_hidden_LatestReference
 	}
 	return ""
 }
 
 func (x *GlobalStateReference) SetModuleName(v string) {
-	x.ModuleName = v
+	x.xxx_hidden_ModuleName = v
 }
 
 func (x *GlobalStateReference) SetLatestReference(v string) {
-	x.LatestReference = v
+	x.xxx_hidden_LatestReference = v
 }
 
 type GlobalStateReference_builder struct {
@@ -164,8 +164,8 @@ func (b0 GlobalStateReference_builder) Build() *GlobalStateReference {
 	m0 := &GlobalStateReference{}
 	b, x := &b0, m0
 	_, _ = b, x
-	x.ModuleName = b.ModuleName
-	x.LatestReference = b.LatestReference
+	x.xxx_hidden_ModuleName = b.ModuleName
+	x.xxx_hidden_LatestReference = b.LatestReference
 	return m0
 }
 
@@ -173,10 +173,10 @@ func (b0 GlobalStateReference_builder) Build() *GlobalStateReference {
 // managed module. This is kept updated in a state file at the managed module
 // directory.
 type ModuleState struct {
-	state         protoimpl.MessageState `protogen:"hybrid.v1"`
-	References    []*ModuleReference     `protobuf:"bytes,1,rep,name=references,proto3" json:"references,omitempty"`
-	unknownFields protoimpl.UnknownFields
-	sizeCache     protoimpl.SizeCache
+	state                 protoimpl.MessageState `protogen:"opaque.v1"`
+	xxx_hidden_References *[]*ModuleReference    `protobuf:"bytes,1,rep,name=references,proto3" json:"references,omitempty"`
+	unknownFields         protoimpl.UnknownFields
+	sizeCache             protoimpl.SizeCache
 }
 
 func (x *ModuleState) Reset() {
@@ -206,13 +206,15 @@ func (x *ModuleState) ProtoReflect() protoreflect.Message {
 
 func (x *ModuleState) GetReferences() []*ModuleReference {
 	if x != nil {
-		return x.References
+		if x.xxx_hidden_References != nil {
+			return *x.xxx_hidden_References
+		}
 	}
 	return nil
 }
 
 func (x *ModuleState) SetReferences(v []*ModuleReference) {
-	x.References = v
+	x.xxx_hidden_References = &v
 }
 
 type ModuleState_builder struct {
@@ -225,18 +227,18 @@ func (b0 ModuleState_builder) Build() *ModuleState {
 	m0 := &ModuleState{}
 	b, x := &b0, m0
 	_, _ = b, x
-	x.References = b.References
+	x.xxx_hidden_References = &b.References
 	return m0
 }
 
 // ModuleReference is a single git reference of a managed module that will be
 // synced to a BSR cluster.
 type ModuleReference struct {
-	state         protoimpl.MessageState `protogen:"hybrid.v1"`
-	Name          string                 `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
-	Digest        string                 `protobuf:"bytes,2,opt,name=digest,proto3" json:"digest,omitempty"`
-	unknownFields protoimpl.UnknownFields
-	sizeCache     protoimpl.SizeCache
+	state             protoimpl.MessageState `protogen:"opaque.v1"`
+	xxx_hidden_Name   string                 `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
+	xxx_hidden_Digest string                 `protobuf:"bytes,2,opt,name=digest,proto3" json:"digest,omitempty"`
+	unknownFields     protoimpl.UnknownFields
+	sizeCache         protoimpl.SizeCache
 }
 
 func (x *ModuleReference) Reset() {
@@ -266,24 +268,24 @@ func (x *ModuleReference) ProtoReflect() protoreflect.Message {
 
 func (x *ModuleReference) GetName() string {
 	if x != nil {
-		return x.Name
+		return x.xxx_hidden_Name
 	}
 	return ""
 }
 
 func (x *ModuleReference) GetDigest() string {
 	if x != nil {
-		return x.Digest
+		return x.xxx_hidden_Digest
 	}
 	return ""
 }
 
 func (x *ModuleReference) SetName(v string) {
-	x.Name = v
+	x.xxx_hidden_Name = v
 }
 
 func (x *ModuleReference) SetDigest(v string) {
-	x.Digest = v
+	x.xxx_hidden_Digest = v
 }
 
 type ModuleReference_builder struct {
@@ -297,8 +299,8 @@ func (b0 ModuleReference_builder) Build() *ModuleReference {
 	m0 := &ModuleReference{}
 	b, x := &b0, m0
 	_, _ = b, x
-	x.Name = b.Name
-	x.Digest = b.Digest
+	x.xxx_hidden_Name = b.Name
+	x.xxx_hidden_Digest = b.Digest
 	return m0
 }
 
diff --git a/private/gen/modules/state/v1alpha1/state_protoopaque.pb.go b/private/gen/modules/state/v1alpha1/state_protoopaque.pb.go
deleted file mode 100644
index 174d05d4..00000000
--- a/private/gen/modules/state/v1alpha1/state_protoopaque.pb.go
+++ /dev/null
@@ -1,423 +0,0 @@
-// Copyright 2021-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.
-
-// Code generated by protoc-gen-go. DO NOT EDIT.
-// versions:
-// 	protoc-gen-go v1.36.1
-// 	protoc        (unknown)
-// source: state/v1alpha1/state.proto
-
-//go:build protoopaque
-
-package v1alpha1
-
-import (
-	_ "buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go/buf/validate"
-	protoreflect "google.golang.org/protobuf/reflect/protoreflect"
-	protoimpl "google.golang.org/protobuf/runtime/protoimpl"
-	reflect "reflect"
-)
-
-const (
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
-)
-
-// GlobalState is a sorted array managed modules, each one with the latest
-// reference from its local array of references. This is kept updated in a
-// global state file at the root sync directory.
-type GlobalState struct {
-	state              protoimpl.MessageState   `protogen:"opaque.v1"`
-	xxx_hidden_Modules *[]*GlobalStateReference `protobuf:"bytes,1,rep,name=modules,proto3" json:"modules,omitempty"`
-	unknownFields      protoimpl.UnknownFields
-	sizeCache          protoimpl.SizeCache
-}
-
-func (x *GlobalState) Reset() {
-	*x = GlobalState{}
-	mi := &file_state_v1alpha1_state_proto_msgTypes[0]
-	ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
-	ms.StoreMessageInfo(mi)
-}
-
-func (x *GlobalState) String() string {
-	return protoimpl.X.MessageStringOf(x)
-}
-
-func (*GlobalState) ProtoMessage() {}
-
-func (x *GlobalState) ProtoReflect() protoreflect.Message {
-	mi := &file_state_v1alpha1_state_proto_msgTypes[0]
-	if x != nil {
-		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
-		if ms.LoadMessageInfo() == nil {
-			ms.StoreMessageInfo(mi)
-		}
-		return ms
-	}
-	return mi.MessageOf(x)
-}
-
-func (x *GlobalState) GetModules() []*GlobalStateReference {
-	if x != nil {
-		if x.xxx_hidden_Modules != nil {
-			return *x.xxx_hidden_Modules
-		}
-	}
-	return nil
-}
-
-func (x *GlobalState) SetModules(v []*GlobalStateReference) {
-	x.xxx_hidden_Modules = &v
-}
-
-type GlobalState_builder struct {
-	_ [0]func() // Prevents comparability and use of unkeyed literals for the builder.
-
-	Modules []*GlobalStateReference
-}
-
-func (b0 GlobalState_builder) Build() *GlobalState {
-	m0 := &GlobalState{}
-	b, x := &b0, m0
-	_, _ = b, x
-	x.xxx_hidden_Modules = &b.Modules
-	return m0
-}
-
-// GlobalReference is a single managed module reference with the latest
-// reference from its local array of references.
-type GlobalStateReference struct {
-	state                      protoimpl.MessageState `protogen:"opaque.v1"`
-	xxx_hidden_ModuleName      string                 `protobuf:"bytes,1,opt,name=module_name,json=moduleName,proto3" json:"module_name,omitempty"`
-	xxx_hidden_LatestReference string                 `protobuf:"bytes,2,opt,name=latest_reference,json=latestReference,proto3" json:"latest_reference,omitempty"`
-	unknownFields              protoimpl.UnknownFields
-	sizeCache                  protoimpl.SizeCache
-}
-
-func (x *GlobalStateReference) Reset() {
-	*x = GlobalStateReference{}
-	mi := &file_state_v1alpha1_state_proto_msgTypes[1]
-	ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
-	ms.StoreMessageInfo(mi)
-}
-
-func (x *GlobalStateReference) String() string {
-	return protoimpl.X.MessageStringOf(x)
-}
-
-func (*GlobalStateReference) ProtoMessage() {}
-
-func (x *GlobalStateReference) ProtoReflect() protoreflect.Message {
-	mi := &file_state_v1alpha1_state_proto_msgTypes[1]
-	if x != nil {
-		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
-		if ms.LoadMessageInfo() == nil {
-			ms.StoreMessageInfo(mi)
-		}
-		return ms
-	}
-	return mi.MessageOf(x)
-}
-
-func (x *GlobalStateReference) GetModuleName() string {
-	if x != nil {
-		return x.xxx_hidden_ModuleName
-	}
-	return ""
-}
-
-func (x *GlobalStateReference) GetLatestReference() string {
-	if x != nil {
-		return x.xxx_hidden_LatestReference
-	}
-	return ""
-}
-
-func (x *GlobalStateReference) SetModuleName(v string) {
-	x.xxx_hidden_ModuleName = v
-}
-
-func (x *GlobalStateReference) SetLatestReference(v string) {
-	x.xxx_hidden_LatestReference = v
-}
-
-type GlobalStateReference_builder struct {
-	_ [0]func() // Prevents comparability and use of unkeyed literals for the builder.
-
-	ModuleName      string
-	LatestReference string
-}
-
-func (b0 GlobalStateReference_builder) Build() *GlobalStateReference {
-	m0 := &GlobalStateReference{}
-	b, x := &b0, m0
-	_, _ = b, x
-	x.xxx_hidden_ModuleName = b.ModuleName
-	x.xxx_hidden_LatestReference = b.LatestReference
-	return m0
-}
-
-// ModuleState is an array of references that will be synced to a BSR cluster for a
-// managed module. This is kept updated in a state file at the managed module
-// directory.
-type ModuleState struct {
-	state                 protoimpl.MessageState `protogen:"opaque.v1"`
-	xxx_hidden_References *[]*ModuleReference    `protobuf:"bytes,1,rep,name=references,proto3" json:"references,omitempty"`
-	unknownFields         protoimpl.UnknownFields
-	sizeCache             protoimpl.SizeCache
-}
-
-func (x *ModuleState) Reset() {
-	*x = ModuleState{}
-	mi := &file_state_v1alpha1_state_proto_msgTypes[2]
-	ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
-	ms.StoreMessageInfo(mi)
-}
-
-func (x *ModuleState) String() string {
-	return protoimpl.X.MessageStringOf(x)
-}
-
-func (*ModuleState) ProtoMessage() {}
-
-func (x *ModuleState) ProtoReflect() protoreflect.Message {
-	mi := &file_state_v1alpha1_state_proto_msgTypes[2]
-	if x != nil {
-		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
-		if ms.LoadMessageInfo() == nil {
-			ms.StoreMessageInfo(mi)
-		}
-		return ms
-	}
-	return mi.MessageOf(x)
-}
-
-func (x *ModuleState) GetReferences() []*ModuleReference {
-	if x != nil {
-		if x.xxx_hidden_References != nil {
-			return *x.xxx_hidden_References
-		}
-	}
-	return nil
-}
-
-func (x *ModuleState) SetReferences(v []*ModuleReference) {
-	x.xxx_hidden_References = &v
-}
-
-type ModuleState_builder struct {
-	_ [0]func() // Prevents comparability and use of unkeyed literals for the builder.
-
-	References []*ModuleReference
-}
-
-func (b0 ModuleState_builder) Build() *ModuleState {
-	m0 := &ModuleState{}
-	b, x := &b0, m0
-	_, _ = b, x
-	x.xxx_hidden_References = &b.References
-	return m0
-}
-
-// ModuleReference is a single git reference of a managed module that will be
-// synced to a BSR cluster.
-type ModuleReference struct {
-	state             protoimpl.MessageState `protogen:"opaque.v1"`
-	xxx_hidden_Name   string                 `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
-	xxx_hidden_Digest string                 `protobuf:"bytes,2,opt,name=digest,proto3" json:"digest,omitempty"`
-	unknownFields     protoimpl.UnknownFields
-	sizeCache         protoimpl.SizeCache
-}
-
-func (x *ModuleReference) Reset() {
-	*x = ModuleReference{}
-	mi := &file_state_v1alpha1_state_proto_msgTypes[3]
-	ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
-	ms.StoreMessageInfo(mi)
-}
-
-func (x *ModuleReference) String() string {
-	return protoimpl.X.MessageStringOf(x)
-}
-
-func (*ModuleReference) ProtoMessage() {}
-
-func (x *ModuleReference) ProtoReflect() protoreflect.Message {
-	mi := &file_state_v1alpha1_state_proto_msgTypes[3]
-	if x != nil {
-		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
-		if ms.LoadMessageInfo() == nil {
-			ms.StoreMessageInfo(mi)
-		}
-		return ms
-	}
-	return mi.MessageOf(x)
-}
-
-func (x *ModuleReference) GetName() string {
-	if x != nil {
-		return x.xxx_hidden_Name
-	}
-	return ""
-}
-
-func (x *ModuleReference) GetDigest() string {
-	if x != nil {
-		return x.xxx_hidden_Digest
-	}
-	return ""
-}
-
-func (x *ModuleReference) SetName(v string) {
-	x.xxx_hidden_Name = v
-}
-
-func (x *ModuleReference) SetDigest(v string) {
-	x.xxx_hidden_Digest = v
-}
-
-type ModuleReference_builder struct {
-	_ [0]func() // Prevents comparability and use of unkeyed literals for the builder.
-
-	Name   string
-	Digest string
-}
-
-func (b0 ModuleReference_builder) Build() *ModuleReference {
-	m0 := &ModuleReference{}
-	b, x := &b0, m0
-	_, _ = b, x
-	x.xxx_hidden_Name = b.Name
-	x.xxx_hidden_Digest = b.Digest
-	return m0
-}
-
-var File_state_v1alpha1_state_proto protoreflect.FileDescriptor
-
-var file_state_v1alpha1_state_proto_rawDesc = []byte{
-	0x0a, 0x1a, 0x73, 0x74, 0x61, 0x74, 0x65, 0x2f, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31,
-	0x2f, 0x73, 0x74, 0x61, 0x74, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0e, 0x73, 0x74,
-	0x61, 0x74, 0x65, 0x2e, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x1a, 0x1b, 0x62, 0x75,
-	0x66, 0x2f, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x2f, 0x76, 0x61, 0x6c, 0x69, 0x64,
-	0x61, 0x74, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x81, 0x03, 0x0a, 0x0b, 0x47, 0x6c,
-	0x6f, 0x62, 0x61, 0x6c, 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x3e, 0x0a, 0x07, 0x6d, 0x6f, 0x64,
-	0x75, 0x6c, 0x65, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x24, 0x2e, 0x73, 0x74, 0x61,
-	0x74, 0x65, 0x2e, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x2e, 0x47, 0x6c, 0x6f, 0x62,
-	0x61, 0x6c, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65,
-	0x52, 0x07, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x73, 0x3a, 0xb1, 0x02, 0xba, 0x48, 0xad, 0x02,
-	0x1a, 0xaa, 0x02, 0x0a, 0x20, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x5f, 0x73, 0x74, 0x61, 0x74,
-	0x65, 0x2e, 0x75, 0x6e, 0x69, 0x71, 0x75, 0x65, 0x5f, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x5f,
-	0x6e, 0x61, 0x6d, 0x65, 0x73, 0x1a, 0x85, 0x02, 0x74, 0x68, 0x69, 0x73, 0x2e, 0x6d, 0x6f, 0x64,
-	0x75, 0x6c, 0x65, 0x73, 0x2e, 0x6d, 0x61, 0x70, 0x28, 0x69, 0x2c, 0x20, 0x69, 0x2e, 0x6d, 0x6f,
-	0x64, 0x75, 0x6c, 0x65, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x2e, 0x75, 0x6e, 0x69, 0x71, 0x75,
-	0x65, 0x28, 0x29, 0x20, 0x3f, 0x20, 0x27, 0x27, 0x20, 0x3a, 0x20, 0x27, 0x6d, 0x6f, 0x64, 0x75,
-	0x6c, 0x65, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x27, 0x20, 0x2b, 0x20, 0x28, 0x74, 0x68, 0x69,
-	0x73, 0x2e, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x73, 0x2e, 0x6d, 0x61, 0x70, 0x28, 0x72, 0x65,
-	0x66, 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65, 0x2c, 0x20, 0x72, 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e,
-	0x63, 0x65, 0x2e, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x2e,
-	0x66, 0x69, 0x6c, 0x74, 0x65, 0x72, 0x28, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x5f, 0x6e, 0x61,
-	0x6d, 0x65, 0x2c, 0x20, 0x21, 0x74, 0x68, 0x69, 0x73, 0x2e, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65,
-	0x73, 0x2e, 0x6d, 0x61, 0x70, 0x28, 0x72, 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65, 0x2c,
-	0x20, 0x72, 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65, 0x2e, 0x6d, 0x6f, 0x64, 0x75, 0x6c,
-	0x65, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x2e, 0x65, 0x78, 0x69, 0x73, 0x74, 0x73, 0x5f, 0x6f,
-	0x6e, 0x65, 0x28, 0x78, 0x2c, 0x20, 0x78, 0x20, 0x3d, 0x3d, 0x20, 0x6d, 0x6f, 0x64, 0x75, 0x6c,
-	0x65, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x29, 0x29, 0x5b, 0x30, 0x5d, 0x20, 0x2b, 0x20, 0x27,
-	0x20, 0x68, 0x61, 0x73, 0x20, 0x61, 0x70, 0x70, 0x65, 0x61, 0x72, 0x65, 0x64, 0x20, 0x6d, 0x75,
-	0x6c, 0x74, 0x69, 0x70, 0x6c, 0x65, 0x20, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x27, 0x22, 0x72, 0x0a,
-	0x14, 0x47, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x66, 0x65,
-	0x72, 0x65, 0x6e, 0x63, 0x65, 0x12, 0x27, 0x0a, 0x0b, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x5f,
-	0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, 0x06, 0xba, 0x48, 0x03, 0xc8,
-	0x01, 0x01, 0x52, 0x0a, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x31,
-	0x0a, 0x10, 0x6c, 0x61, 0x74, 0x65, 0x73, 0x74, 0x5f, 0x72, 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e,
-	0x63, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x42, 0x06, 0xba, 0x48, 0x03, 0xc8, 0x01, 0x01,
-	0x52, 0x0f, 0x6c, 0x61, 0x74, 0x65, 0x73, 0x74, 0x52, 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63,
-	0x65, 0x22, 0xe4, 0x02, 0x0a, 0x0b, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x53, 0x74, 0x61, 0x74,
-	0x65, 0x12, 0x3f, 0x0a, 0x0a, 0x72, 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65, 0x73, 0x18,
-	0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1f, 0x2e, 0x73, 0x74, 0x61, 0x74, 0x65, 0x2e, 0x76, 0x31,
-	0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x2e, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x52, 0x65, 0x66,
-	0x65, 0x72, 0x65, 0x6e, 0x63, 0x65, 0x52, 0x0a, 0x72, 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63,
-	0x65, 0x73, 0x3a, 0x93, 0x02, 0xba, 0x48, 0x8f, 0x02, 0x1a, 0x8c, 0x02, 0x0a, 0x1e, 0x6d, 0x6f,
-	0x64, 0x75, 0x6c, 0x65, 0x5f, 0x73, 0x74, 0x61, 0x74, 0x65, 0x2e, 0x75, 0x6e, 0x69, 0x71, 0x75,
-	0x65, 0x5f, 0x72, 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65, 0x73, 0x1a, 0xe9, 0x01, 0x74,
-	0x68, 0x69, 0x73, 0x2e, 0x72, 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65, 0x73, 0x2e, 0x6d,
-	0x61, 0x70, 0x28, 0x69, 0x2c, 0x20, 0x69, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x2e, 0x75, 0x6e,
-	0x69, 0x71, 0x75, 0x65, 0x28, 0x29, 0x20, 0x3f, 0x20, 0x27, 0x27, 0x20, 0x3a, 0x20, 0x27, 0x72,
-	0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65, 0x20, 0x27, 0x20, 0x2b, 0x20, 0x28, 0x74, 0x68,
-	0x69, 0x73, 0x2e, 0x72, 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65, 0x73, 0x2e, 0x6d, 0x61,
-	0x70, 0x28, 0x72, 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65, 0x2c, 0x20, 0x72, 0x65, 0x66,
-	0x65, 0x72, 0x65, 0x6e, 0x63, 0x65, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x2e, 0x66, 0x69, 0x6c,
-	0x74, 0x65, 0x72, 0x28, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x20, 0x21, 0x74, 0x68, 0x69, 0x73, 0x2e,
-	0x72, 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65, 0x73, 0x2e, 0x6d, 0x61, 0x70, 0x28, 0x72,
-	0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65, 0x2c, 0x20, 0x72, 0x65, 0x66, 0x65, 0x72, 0x65,
-	0x6e, 0x63, 0x65, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x2e, 0x65, 0x78, 0x69, 0x73, 0x74, 0x73,
-	0x5f, 0x6f, 0x6e, 0x65, 0x28, 0x78, 0x2c, 0x20, 0x78, 0x20, 0x3d, 0x3d, 0x20, 0x6e, 0x61, 0x6d,
-	0x65, 0x29, 0x29, 0x29, 0x5b, 0x30, 0x5d, 0x20, 0x2b, 0x20, 0x27, 0x20, 0x68, 0x61, 0x73, 0x20,
-	0x61, 0x70, 0x70, 0x65, 0x61, 0x72, 0x65, 0x64, 0x20, 0x6d, 0x75, 0x6c, 0x74, 0x69, 0x70, 0x6c,
-	0x65, 0x20, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x27, 0x22, 0x4d, 0x0a, 0x0f, 0x4d, 0x6f, 0x64, 0x75,
-	0x6c, 0x65, 0x52, 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65, 0x12, 0x1a, 0x0a, 0x04, 0x6e,
-	0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, 0x06, 0xba, 0x48, 0x03, 0xc8, 0x01,
-	0x01, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x1e, 0x0a, 0x06, 0x64, 0x69, 0x67, 0x65, 0x73,
-	0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x42, 0x06, 0xba, 0x48, 0x03, 0xc8, 0x01, 0x01, 0x52,
-	0x06, 0x64, 0x69, 0x67, 0x65, 0x73, 0x74, 0x42, 0x4d, 0x5a, 0x4b, 0x62, 0x75, 0x66, 0x2e, 0x62,
-	0x75, 0x69, 0x6c, 0x64, 0x2f, 0x67, 0x65, 0x6e, 0x2f, 0x67, 0x6f, 0x2f, 0x62, 0x75, 0x66, 0x62,
-	0x75, 0x69, 0x6c, 0x64, 0x2f, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x64, 0x2d, 0x6d, 0x6f, 0x64,
-	0x75, 0x6c, 0x65, 0x73, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x62, 0x75, 0x66,
-	0x66, 0x65, 0x72, 0x73, 0x2f, 0x67, 0x6f, 0x2f, 0x73, 0x74, 0x61, 0x74, 0x65, 0x2f, 0x76, 0x31,
-	0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
-}
-
-var file_state_v1alpha1_state_proto_msgTypes = make([]protoimpl.MessageInfo, 4)
-var file_state_v1alpha1_state_proto_goTypes = []any{
-	(*GlobalState)(nil),          // 0: state.v1alpha1.GlobalState
-	(*GlobalStateReference)(nil), // 1: state.v1alpha1.GlobalStateReference
-	(*ModuleState)(nil),          // 2: state.v1alpha1.ModuleState
-	(*ModuleReference)(nil),      // 3: state.v1alpha1.ModuleReference
-}
-var file_state_v1alpha1_state_proto_depIdxs = []int32{
-	1, // 0: state.v1alpha1.GlobalState.modules:type_name -> state.v1alpha1.GlobalStateReference
-	3, // 1: state.v1alpha1.ModuleState.references:type_name -> state.v1alpha1.ModuleReference
-	2, // [2:2] is the sub-list for method output_type
-	2, // [2:2] is the sub-list for method input_type
-	2, // [2:2] is the sub-list for extension type_name
-	2, // [2:2] is the sub-list for extension extendee
-	0, // [0:2] is the sub-list for field type_name
-}
-
-func init() { file_state_v1alpha1_state_proto_init() }
-func file_state_v1alpha1_state_proto_init() {
-	if File_state_v1alpha1_state_proto != nil {
-		return
-	}
-	type x struct{}
-	out := protoimpl.TypeBuilder{
-		File: protoimpl.DescBuilder{
-			GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
-			RawDescriptor: file_state_v1alpha1_state_proto_rawDesc,
-			NumEnums:      0,
-			NumMessages:   4,
-			NumExtensions: 0,
-			NumServices:   0,
-		},
-		GoTypes:           file_state_v1alpha1_state_proto_goTypes,
-		DependencyIndexes: file_state_v1alpha1_state_proto_depIdxs,
-		MessageInfos:      file_state_v1alpha1_state_proto_msgTypes,
-	}.Build()
-	File_state_v1alpha1_state_proto = out.File
-	file_state_v1alpha1_state_proto_rawDesc = nil
-	file_state_v1alpha1_state_proto_goTypes = nil
-	file_state_v1alpha1_state_proto_depIdxs = nil
-}