Commit 5782ea96 authored by Robert Griesemer's avatar Robert Griesemer

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
parent ec9ea9a5
......@@ -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)
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment