MCPcopy
hub / github.com/golang/tools / NewPkgDecoder

Function NewPkgDecoder

internal/pkgbits/decoder.go:71–109  ·  view source on GitHub ↗

NewPkgDecoder returns a PkgDecoder initialized to read the Unified IR export data from input. pkgPath is the package path for the compilation unit that produced the export data.

(pkgPath, input string)

Source from the content-addressed store, hash-verified

69// IR export data from input. pkgPath is the package path for the
70// compilation unit that produced the export data.
71func NewPkgDecoder(pkgPath, input string) PkgDecoder {
72 pr := PkgDecoder{
73 pkgPath: pkgPath,
74 }
75
76 // TODO(mdempsky): Implement direct indexing of input string to
77 // avoid copying the position information.
78
79 r := strings.NewReader(input)
80
81 var ver uint32
82 assert(binary.Read(r, binary.LittleEndian, &ver) == nil)
83 pr.version = Version(ver)
84
85 if pr.version >= numVersions {
86 panic(fmt.Errorf("cannot decode %q, export data version %d is greater than maximum supported version %d", pkgPath, pr.version, numVersions-1))
87 }
88
89 if pr.version.Has(Flags) {
90 var flags uint32
91 assert(binary.Read(r, binary.LittleEndian, &flags) == nil)
92 pr.sync = flags&flagSyncMarkers != 0
93 }
94
95 assert(binary.Read(r, binary.LittleEndian, pr.elemEndsEnds[:]) == nil)
96
97 pr.elemEnds = make([]uint32, pr.elemEndsEnds[len(pr.elemEndsEnds)-1])
98 assert(binary.Read(r, binary.LittleEndian, pr.elemEnds[:]) == nil)
99
100 pos, err := r.Seek(0, io.SeekCurrent)
101 assert(err == nil)
102
103 pr.elemData = input[pos:]
104
105 const fingerprintSize = 8
106 assert(len(pr.elemData)-fingerprintSize == int(pr.elemEnds[len(pr.elemEnds)-1]))
107
108 return pr
109}
110
111// NumElems returns the number of elements in section k.
112func (pr *PkgDecoder) NumElems(k RelocKind) int {

Callers 2

UImportDataFunction · 0.92
TestRoundTripFunction · 0.92

Calls 7

intTypeAlias · 0.85
SeekMethod · 0.80
assertFunction · 0.70
VersionTypeAlias · 0.70
ReadMethod · 0.65
ErrorfMethod · 0.65
HasMethod · 0.45

Tested by 1

TestRoundTripFunction · 0.74

Used in the wild real call sites across dependent graphs

searching dependent graphs…