diff options
| author | Tim King <taking@google.com> | 2024-08-14 12:34:32 -0700 |
|---|---|---|
| committer | Tim King <taking@google.com> | 2024-08-20 21:55:59 +0000 |
| commit | 830621bc09c175d1b87496fd1be79bdcd1ce27c8 (patch) | |
| tree | e00c1bb5234e61703f166935f7df97788c7d3199 /src/internal/pkgbits/decoder.go | |
| parent | 54c948de9a18949c88b1453d3288253f86256ce9 (diff) | |
| download | go-830621bc09c175d1b87496fd1be79bdcd1ce27c8.tar.xz | |
internal/pkgbits: add Version type
Adds a new Version type to pkgbits to represent the version of the
bitstream. Versions let readers and writers know when different data is
expected to be present or not in the bitstream. These different pieces
of data are called Fields, as an analogy with fields of a struct.
Fields can be added, removed or changed in a Version. Extends Encoder
and Decoder to report which version they are.
Updates #68778
Change-Id: Iaffa1828544fb4cbc47a905de853449bc8e5b91f
Reviewed-on: https://go-review.googlesource.com/c/go/+/605655
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Diffstat (limited to 'src/internal/pkgbits/decoder.go')
| -rw-r--r-- | src/internal/pkgbits/decoder.go | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/src/internal/pkgbits/decoder.go b/src/internal/pkgbits/decoder.go index 76eb255fc2..ca66446dba 100644 --- a/src/internal/pkgbits/decoder.go +++ b/src/internal/pkgbits/decoder.go @@ -21,7 +21,7 @@ import ( // export data. type PkgDecoder struct { // version is the file format version. - version uint32 + version Version // sync indicates whether the file uses sync markers. sync bool @@ -68,8 +68,6 @@ func (pr *PkgDecoder) SyncMarkers() bool { return pr.sync } // 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. -// -// TODO(mdempsky): Remove pkgPath parameter; unneeded since CL 391014. func NewPkgDecoder(pkgPath, input string) PkgDecoder { pr := PkgDecoder{ pkgPath: pkgPath, @@ -80,14 +78,15 @@ func NewPkgDecoder(pkgPath, input string) PkgDecoder { r := strings.NewReader(input) - assert(binary.Read(r, binary.LittleEndian, &pr.version) == nil) + var ver uint32 + assert(binary.Read(r, binary.LittleEndian, &ver) == nil) + pr.version = Version(ver) - switch pr.version { - default: - panicf("unsupported version: %v", pr.version) - case 0: - // no flags - case 1: + if pr.version >= V2 { // TODO(taking): Switch to numVersions. + panic(fmt.Errorf("cannot decode %q, export data version %d is too new", pkgPath, pr.version)) + } + + if pr.version.Has(Flags) { var flags uint32 assert(binary.Read(r, binary.LittleEndian, &flags) == nil) pr.sync = flags&flagSyncMarkers != 0 @@ -513,3 +512,6 @@ func (pr *PkgDecoder) PeekObj(idx Index) (string, string, CodeObj) { return path, name, tag } + +// Version reports the version of the bitstream. +func (w *Decoder) Version() Version { return w.common.version } |
