mirror of
https://github.com/golang/go
synced 2024-11-21 22:24:40 -07:00
go/token: document deserialization property
FileSet deserialization (Read) uses its own instance of a gob decoder. If the FileSet data may be followed by other data on the reader, Read may consume too much data that is lost unless the reader implements ReadByte. Also: Minor internal refactoring for symmetry. R=r CC=golang-dev https://golang.org/cl/5233041
This commit is contained in:
parent
ec9ea9a5cb
commit
5782ea9646
@ -24,10 +24,19 @@ type serializedFileSet struct {
|
||||
Files []serializedFile
|
||||
}
|
||||
|
||||
func (s *serializedFileSet) Read(r io.Reader) os.Error {
|
||||
return gob.NewDecoder(r).Decode(s)
|
||||
}
|
||||
|
||||
func (s *serializedFileSet) Write(w io.Writer) os.Error {
|
||||
return gob.NewEncoder(w).Encode(s)
|
||||
}
|
||||
|
||||
// Read reads the fileset from r into s; s must not be nil.
|
||||
// If r does not also implement io.ByteReader, it will be wrapped in a bufio.Reader.
|
||||
func (s *FileSet) Read(r io.Reader) os.Error {
|
||||
var ss serializedFileSet
|
||||
if err := gob.NewDecoder(r).Decode(&ss); err != nil {
|
||||
if err := ss.Read(r); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -58,5 +67,5 @@ func (s *FileSet) Write(w io.Writer) os.Error {
|
||||
ss.Files = files
|
||||
s.mutex.Unlock()
|
||||
|
||||
return gob.NewEncoder(w).Encode(ss)
|
||||
return ss.Write(w)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user