1// Copyright (C) 2024 The Android Open Source Project 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 requirements generates src using templates and Media Performance Class (MPC) 16// requirements data. 17package requirements 18 19import ( 20 "io" 21 "text/template" 22 23 "cts/test/mediapc/requirements/templatefns" 24 "google.golang.org/protobuf/proto" 25 26 pb "cts/test/mediapc/requirements/requirements_go_proto" 27) 28 29// Gensrc generates source from a template using a list of MPC requirements. 30func Gensrc(tmplString string, reqList *pb.RequirementList, w io.Writer) error { 31 type Top struct { 32 ReqList *pb.RequirementList 33 } 34 top := Top{ReqList: reqList} 35 tmpl, err := template.New("gensrc").Funcs(templatefns.Funcs()).Parse(tmplString) 36 if err != nil { 37 return err 38 } 39 err = tmpl.Execute(w, top) 40 if err != nil { 41 return err 42 } 43 return nil 44} 45 46// UnmarshalRequirementList unmarshals MPC requirements data. 47func UnmarshalRequirementList(reqBinary []byte) (*pb.RequirementList, error) { 48 req := &pb.RequirementList{} 49 err := proto.Unmarshal(reqBinary, req) 50 return req, err 51} 52