package token
type serializedFile struct {
Name string
Base int
Size int
Lines []int
Infos []lineInfo
}
type serializedFileSet struct {
Base int
Files []serializedFile
}
func (s *FileSet ) Read (decode func (any ) 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 {
name : f .Name ,
base : f .Base ,
size : f .Size ,
lines : f .Lines ,
infos : f .Infos ,
}
}
s .files = files
s .last .Store (nil )
s .mutex .Unlock ()
return nil
}
func (s *FileSet ) Write (encode func (any ) error ) error {
var ss serializedFileSet
s .mutex .Lock ()
ss .Base = s .base
files := make ([]serializedFile , len (s .files ))
for i , f := range s .files {
f .mutex .Lock ()
files [i ] = serializedFile {
Name : f .name ,
Base : f .base ,
Size : f .size ,
Lines : append ([]int (nil ), f .lines ...),
Infos : append ([]lineInfo (nil ), f .infos ...),
}
f .mutex .Unlock ()
}
ss .Files = files
s .mutex .Unlock ()
return encode (ss )
}
The pages are generated with Golds v0.7.0-preview . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .