go.ligato.io/vpp-agent/v3@v3.5.0/pkg/models/option.go (about)

     1  //  Copyright (c) 2019 Cisco and/or its affiliates.
     2  //
     3  //  Licensed under the Apache License, Version 2.0 (the "License");
     4  //  you may not use this file except in compliance with the License.
     5  //  You may obtain a copy of the License at:
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  //  Unless required by applicable law or agreed to in writing, software
    10  //  distributed under the License is distributed on an "AS IS" BASIS,
    11  //  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  //  See the License for the specific language governing permissions and
    13  //  limitations under the License.
    14  
    15  package models
    16  
    17  import (
    18  	"google.golang.org/protobuf/proto"
    19  	"google.golang.org/protobuf/reflect/protoreflect"
    20  
    21  	"go.ligato.io/vpp-agent/v3/proto/ligato/generic"
    22  )
    23  
    24  func (r *LocalRegistry) checkProtoOptions(x interface{}) *LocallyKnownModel {
    25  	p, ok := x.(protoreflect.Message)
    26  	if !ok {
    27  		return nil
    28  	}
    29  	s := proto.GetExtension(p.Interface(), generic.E_Model)
    30  	if spec, ok := s.(*generic.ModelSpec); ok {
    31  		km, err := r.Register(x, ToSpec(spec))
    32  		if err != nil {
    33  			panic(err)
    34  		}
    35  		return km.(*LocallyKnownModel)
    36  	}
    37  	return nil
    38  }