1
0
mirror of https://github.com/golang/go synced 2024-11-23 23:30:10 -07:00

internal/pkgbits: add version number

Especially once this code gets copied into x/tools, we need a way to
evolve the file format, so add an explicit version number.

Change-Id: I9cc2e357c3ca3f07fd8d0c0ba4e4a95f89edeac6
Reviewed-on: https://go-review.googlesource.com/c/go/+/388914
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
This commit is contained in:
Matthew Dempsky 2022-03-01 12:58:20 -08:00
parent b0db2f00a0
commit d40e7bb174
2 changed files with 6 additions and 0 deletions

View File

@ -37,6 +37,10 @@ func NewPkgDecoder(pkgPath, input string) PkgDecoder {
r := strings.NewReader(input)
var version uint32
assert(binary.Read(r, binary.LittleEndian, &version) == nil)
assert(version == 0)
assert(binary.Read(r, binary.LittleEndian, pr.elemEndsEnds[:]) == nil)
pr.elemEnds = make([]uint32, pr.elemEndsEnds[len(pr.elemEndsEnds)-1])

View File

@ -35,6 +35,8 @@ func (pw *PkgEncoder) DumpTo(out io.Writer) {
assert(binary.Write(out, binary.LittleEndian, x) == nil)
}
writeUint32(0) // version
var sum uint32
for _, elems := range &pw.elems {
sum += uint32(len(elems))