Skip to content

Commit

Permalink
added marshalVT to types.resource
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhipsa20 committed Aug 22, 2024
1 parent 813bc6f commit 9d85983
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions pkg/cache/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
// Resource is the base interface for the xDS payload.
type Resource interface {
proto.Message
MarshalVTStrict() ([]byte, error)
}

// ResourceWithTTL is a Resource with an optional TTL.
Expand Down
8 changes: 7 additions & 1 deletion pkg/cache/v3/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"encoding/hex"
"fmt"
"google.golang.org/protobuf/proto"
"reflect"

cluster "github.com/envoyproxy/go-control-plane/envoy/config/cluster/v3"
endpoint "github.com/envoyproxy/go-control-plane/envoy/config/endpoint/v3"
Expand Down Expand Up @@ -125,7 +126,12 @@ func GetResourceWithTTLNames(resources []types.ResourceWithTTL) []string {

// MarshalResource converts the Resource to MarshaledResource.
func MarshalResource(resource types.Resource) (types.MarshaledResource, error) {
return proto.MarshalOptions{Deterministic: true}.Marshal(resource)
t := reflect.TypeOf(resource)
_, ok := t.MethodByName("MarshalVTStrict")
if !ok {
return proto.MarshalOptions{Deterministic: true}.Marshal(resource)
}
return resource.MarshalVTStrict()
}

// GetResourceReferences returns a map of dependent resources keyed by resource type, given a map of resources.
Expand Down

0 comments on commit 9d85983

Please sign in to comment.