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

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- (Feature) (Platform) Generate GRPC Gateway Code
- (Feature) (Platform) Identity Endpoint
- (Feature) (Platform) Authz V1 Types
- (Maintenance) Allow GRPC Marshal Opts

## [1.2.46](https://github.com/arangodb/kube-arangodb/tree/1.2.46) (2025-02-24)
- (Bugfix) Clean Phase change properly during upgrade
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"encoding/json"
"net/http"

"google.golang.org/protobuf/encoding/protojson"

"github.com/arangodb/kube-arangodb/pkg/util"
)

Expand All @@ -32,7 +34,7 @@ type ConfigDestinationStaticInterface interface {
StaticResponse() ([]byte, uint32, error)
}

type ConfigDestinationStaticMarshaller[T any] func(in T) ([]byte, error)
type ConfigDestinationStaticMarshaller[T any] func(in T, opts ...util.Mod[protojson.MarshalOptions]) ([]byte, error)

type ConfigDestinationStatic[T any] struct {
Code *uint32 `json:"insecure,omitempty"`
Expand Down
22 changes: 15 additions & 7 deletions pkg/util/grpc/marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,23 @@ import (
"github.com/arangodb/kube-arangodb/pkg/util"
)

func Marshal[T proto.Message](in T) ([]byte, error) {
data, err := protojson.MarshalOptions{
func Marshal[T proto.Message](in T, opts ...util.Mod[protojson.MarshalOptions]) ([]byte, error) {
options := protojson.MarshalOptions{
UseProtoNames: true,
}.Marshal(in)
}

util.ApplyMods(&options, opts...)

data, err := options.Marshal(in)
if err != nil {
return nil, err
}

return data, err
}

func MarshalYAML[T proto.Message](in T) ([]byte, error) {
data, err := Marshal[T](in)
func MarshalYAML[T proto.Message](in T, opts ...util.Mod[protojson.MarshalOptions]) ([]byte, error) {
data, err := Marshal[T](in, opts...)
if err != nil {
return nil, err
}
Expand All @@ -49,13 +53,17 @@ func MarshalYAML[T proto.Message](in T) ([]byte, error) {
return data, err
}

func Unmarshal[T proto.Message](data []byte) (T, error) {
func Unmarshal[T proto.Message](data []byte, opts ...util.Mod[protojson.UnmarshalOptions]) (T, error) {
v, err := util.DeepType[T]()
if err != nil {
return util.Default[T](), err
}

if err := (protojson.UnmarshalOptions{}).Unmarshal(data, v); err != nil {
options := protojson.UnmarshalOptions{}

util.ApplyMods(&options, opts...)

if err := options.Unmarshal(data, v); err != nil {
return util.Default[T](), err
}

Expand Down