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/encoder.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/encoder.go')
| -rw-r--r-- | src/internal/pkgbits/encoder.go | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/src/internal/pkgbits/encoder.go b/src/internal/pkgbits/encoder.go index e52bc85014..a1489c88d0 100644 --- a/src/internal/pkgbits/encoder.go +++ b/src/internal/pkgbits/encoder.go @@ -15,20 +15,15 @@ import ( "strings" ) -// currentVersion is the current version number. -// -// - v0: initial prototype -// -// - v1: adds the flags uint32 word -// -// TODO(mdempsky): For the next version bump: -// - remove the legacy "has init" bool from the public root -// - remove obj's "derived func instance" bool -const currentVersion uint32 = 1 +// currentVersion is the current version number written. +const currentVersion = V1 // A PkgEncoder provides methods for encoding a package's Unified IR // export data. type PkgEncoder struct { + // version of the bitstream. + version Version + // elems holds the bitstream for previously encoded elements. elems [numRelocs][]string @@ -54,6 +49,8 @@ func (pw *PkgEncoder) SyncMarkers() bool { return pw.syncFrames >= 0 } // negative, then sync markers are omitted entirely. func NewPkgEncoder(syncFrames int) PkgEncoder { return PkgEncoder{ + // TODO(taking): Change NewPkgEncoder to take a version as an argument, and remove currentVersion. + version: currentVersion, stringsIdx: make(map[string]Index), syncFrames: syncFrames, } @@ -69,7 +66,7 @@ func (pw *PkgEncoder) DumpTo(out0 io.Writer) (fingerprint [8]byte) { assert(binary.Write(out, binary.LittleEndian, x) == nil) } - writeUint32(currentVersion) + writeUint32(uint32(pw.version)) var flags uint32 if pw.SyncMarkers() { @@ -392,3 +389,6 @@ func (w *Encoder) bigFloat(v *big.Float) { b := v.Append(nil, 'p', -1) w.String(string(b)) // TODO: More efficient encoding. } + +// Version reports the version of the bitstream. +func (w *Encoder) Version() Version { return w.p.version } |
