forked from toolshed/abra
cli
cmd
pkg
scripts
tests
vendor
coopcloud.tech
dario.cat
git.coopcloud.tech
github.com
AlecAivazis
Azure
BurntSushi
Microsoft
ProtonMail
aymanbagabas
beorn7
cenkalti
cespare
charmbracelet
cloudflare
containerd
containers
cpuguy83
cyphar
davecgh
decentral1se
distribution
docker
emirpasic
felixge
fvbommel
ghodss
go-git
gcfg
scanner
token
position.go
serialize.go
token.go
types
.gitignore
LICENSE
Makefile
README
doc.go
errors.go
read.go
set.go
go-billy
go-git
go-logfmt
go-logr
go-viper
gogo
golang
google
gorilla
grpc-ecosystem
hashicorp
inconshreveable
jbenet
kballard
kevinburke
klauspost
lucasb-eyer
mattn
mgutz
miekg
mitchellh
mmcloughlin
moby
morikuni
muesli
munnerz
opencontainers
pjbgf
pkg
pmezard
prometheus
rivo
russross
schollz
sergi
sirupsen
skeema
spf13
stretchr
theupdateframework
xanzy
xeipuuv
go.opentelemetry.io
golang.org
google.golang.org
gopkg.in
gotest.tools
modules.txt
.dockerignore
.drone.yml
.envrc.sample
.gitignore
.goreleaser.yml
AUTHORS.md
Dockerfile
LICENSE
Makefile
README.md
go.mod
go.sum
renovate.json
57 lines
1.2 KiB
Go
57 lines
1.2 KiB
Go
// Copyright 2011 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package token
|
|
|
|
type serializedFile struct {
|
|
// fields correspond 1:1 to fields with same (lower-case) name in File
|
|
Name string
|
|
Base int
|
|
Size int
|
|
Lines []int
|
|
Infos []lineInfo
|
|
}
|
|
|
|
type serializedFileSet struct {
|
|
Base int
|
|
Files []serializedFile
|
|
}
|
|
|
|
// Read calls decode to deserialize a file set into s; s must not be nil.
|
|
func (s *FileSet) Read(decode func(interface{}) error) error {
|
|
var ss serializedFileSet
|
|
if err := decode(&ss); err != nil {
|
|
return err
|
|
}
|
|
|
|
s.mutex.Lock()
|
|
s.base = ss.Base
|
|
files := make([]*File, len(ss.Files))
|
|
for i := 0; i < len(ss.Files); i++ {
|
|
f := &ss.Files[i]
|
|
files[i] = &File{s, f.Name, f.Base, f.Size, f.Lines, f.Infos}
|
|
}
|
|
s.files = files
|
|
s.last = nil
|
|
s.mutex.Unlock()
|
|
|
|
return nil
|
|
}
|
|
|
|
// Write calls encode to serialize the file set s.
|
|
func (s *FileSet) Write(encode func(interface{}) error) error {
|
|
var ss serializedFileSet
|
|
|
|
s.mutex.Lock()
|
|
ss.Base = s.base
|
|
files := make([]serializedFile, len(s.files))
|
|
for i, f := range s.files {
|
|
files[i] = serializedFile{f.name, f.base, f.size, f.lines, f.infos}
|
|
}
|
|
ss.Files = files
|
|
s.mutex.Unlock()
|
|
|
|
return encode(ss)
|
|
}
|