github.com/google/osv-scalibr@v0.4.1/extractor/filesystem/os/macports/metadata/metadata.go (about) 1 // Copyright 2025 Google LLC 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 metadata defines a metadata struct for Macports packages. 16 package metadata 17 18 import ( 19 pb "github.com/google/osv-scalibr/binary/proto/scan_result_go_proto" 20 ) 21 22 // Metadata holds parsing information for an Macports package. 23 type Metadata struct { 24 PackageName string 25 PackageVersion string 26 PackageRevision string 27 } 28 29 // SetProto sets the MacportsPackageMetadata field in the Package proto. 30 func (m *Metadata) SetProto(p *pb.Package) { 31 if m == nil { 32 return 33 } 34 if p == nil { 35 return 36 } 37 38 p.Metadata = &pb.Package_MacportsMetadata{ 39 MacportsMetadata: &pb.MacportsPackageMetadata{ 40 PackageName: m.PackageName, 41 PackageVersion: m.PackageVersion, 42 PackageRevision: m.PackageRevision, 43 }, 44 } 45 } 46 47 // ToStruct converts the MacportsPackageMetadata proto to a Metadata struct. 48 func ToStruct(m *pb.MacportsPackageMetadata) *Metadata { 49 if m == nil { 50 return nil 51 } 52 53 return &Metadata{ 54 PackageName: m.GetPackageName(), 55 PackageVersion: m.GetPackageVersion(), 56 PackageRevision: m.GetPackageRevision(), 57 } 58 }