github.com/linuxboot/fiano@v1.2.0/pkg/intel/metadata/cbnt/structure.go (about) 1 // Copyright 2017-2021 the LinuxBoot Authors. All rights reserved 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 //go:generate manifestcodegen 6 7 package cbnt 8 9 import ( 10 "encoding/binary" 11 "io" 12 13 "github.com/linuxboot/fiano/pkg/intel/metadata/common/pretty" 14 ) 15 16 var ( 17 binaryOrder = binary.LittleEndian 18 ) 19 20 // StructInfo is the common part of any structure of a manifest 21 type StructInfo struct { 22 ID StructureID `json:"StructInfoID"` 23 Version uint8 `json:"StructInfoVersion"` 24 Variable0 uint8 `json:"StructInfoVariable0"` 25 ElementSize uint16 `json:"StructInfoElementSize"` 26 } 27 28 // StructInfo just returns StructInfo, it is a handy method if StructInfo 29 // is included anonymously to another type. 30 func (s StructInfo) StructInfo() StructInfo { 31 return s 32 } 33 34 // StructureID is the magic ID string used to identify the structure type 35 // in the manifest 36 type StructureID [8]byte 37 38 // String returns the ID as a string. 39 func (s StructureID) String() string { 40 return string(s[:]) 41 } 42 43 // Structure is an abstraction of a structure of a manifest. 44 type Structure interface { 45 io.ReaderFrom 46 io.WriterTo 47 TotalSize() uint64 48 // PrettyString returns the whole object as a structured string. 49 PrettyString(depth uint, withHeader bool, opts ...pretty.Option) string 50 } 51 52 // Element is an abstraction of an element of a manifest. 53 type Element interface { 54 Structure 55 ReadDataFrom(r io.Reader) (int64, error) 56 GetStructInfo() StructInfo 57 SetStructInfo(StructInfo) 58 } 59 60 // ElementsContainer is an abstraction of set of elements of a manifest (for 61 // example: the root structure of BPM). 62 type ElementsContainer interface { 63 Structure 64 GetFieldByStructID(structID string) interface{} 65 } 66 67 // Manifest is an abstract manifest. 68 type Manifest interface { 69 Structure 70 }