@@ -34,6 +34,7 @@ import (
34
34
"google.golang.org/grpc/xds/internal/clients/xdsclient"
35
35
"google.golang.org/grpc/xds/internal/clients/xdsclient/internal/xdsresource"
36
36
"google.golang.org/protobuf/proto"
37
+ "google.golang.org/protobuf/types/known/anypb"
37
38
38
39
v3listenerpb "github.com/envoyproxy/go-control-plane/envoy/config/listener/v3"
39
40
v3httppb "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/http_connection_manager/v3"
@@ -73,17 +74,24 @@ var (
73
74
}
74
75
)
75
76
76
- func unmarshalListenerResource (r []byte ) (string , listenerUpdate , error ) {
77
+ func unmarshalListenerResource (rProto * anypb.Any ) (string , listenerUpdate , error ) {
78
+ rProto , err := xdsresource .UnwrapResource (rProto )
79
+ if err != nil {
80
+ return "" , listenerUpdate {}, fmt .Errorf ("failed to unwrap resource: %v" , err )
81
+ }
82
+ if ! xdsresource .IsListenerResource (rProto .GetTypeUrl ()) {
83
+ return "" , listenerUpdate {}, fmt .Errorf ("unexpected listener resource type: %q" , rProto .GetTypeUrl ())
84
+ }
77
85
lis := & v3listenerpb.Listener {}
78
- if err := proto .Unmarshal (r , lis ); err != nil {
86
+ if err := proto .Unmarshal (rProto . GetValue () , lis ); err != nil {
79
87
return "" , listenerUpdate {}, fmt .Errorf ("failed to unmarshal resource: %v" , err )
80
88
}
81
89
82
90
lu , err := processListener (lis )
83
91
if err != nil {
84
92
return lis .GetName (), listenerUpdate {}, err
85
93
}
86
- lu .Raw = r
94
+ lu .Raw = rProto . GetValue ()
87
95
return lis .GetName (), * lu , nil
88
96
}
89
97
@@ -165,8 +173,12 @@ type listenerDecoder struct{}
165
173
166
174
// Decode deserializes and validates an xDS resource serialized inside the
167
175
// provided `Any` proto, as received from the xDS management server.
168
- func (listenerDecoder ) Decode (resource []byte , _ xdsclient.DecodeOptions ) (* xdsclient.DecodeResult , error ) {
169
- name , listener , err := unmarshalListenerResource (resource )
176
+ func (listenerDecoder ) Decode (resource xdsclient.AnyProto , _ xdsclient.DecodeOptions ) (* xdsclient.DecodeResult , error ) {
177
+ rProto := & anypb.Any {
178
+ TypeUrl : resource .TypeURL ,
179
+ Value : resource .Value ,
180
+ }
181
+ name , listener , err := unmarshalListenerResource (rProto )
170
182
switch {
171
183
case name == "" :
172
184
// Name is unset only when protobuf deserialization fails.
0 commit comments