// 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 ( *FileSet) ( func(any) error) error {
	var  serializedFileSet
	if  := (&);  != nil {
		return 
	}

	.mutex.Lock()
	.base = .Base
	 := make([]*File, len(.Files))
	for  := 0;  < len(.Files); ++ {
		 := &.Files[]
		[] = &File{
			name:  .Name,
			base:  .Base,
			size:  .Size,
			lines: .Lines,
			infos: .Infos,
		}
	}
	.files = 
	.last.Store(nil)
	.mutex.Unlock()

	return nil
}

// Write calls encode to serialize the file set s.
func ( *FileSet) ( func(any) error) error {
	var  serializedFileSet

	.mutex.Lock()
	.Base = .base
	 := make([]serializedFile, len(.files))
	for ,  := range .files {
		.mutex.Lock()
		[] = serializedFile{
			Name:  .name,
			Base:  .base,
			Size:  .size,
			Lines: append([]int(nil), .lines...),
			Infos: append([]lineInfo(nil), .infos...),
		}
		.mutex.Unlock()
	}
	.Files = 
	.mutex.Unlock()

	return ()
}