summaryrefslogtreecommitdiff
path: root/src/pkg/gob/decoder.go
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2009-12-15 15:35:38 -0800
committerRobert Griesemer <gri@golang.org>2009-12-15 15:35:38 -0800
commite4bd81f903362d998f7bfc02095935408aff0bc5 (patch)
tree05f75a90e239d33be427da4f9c5596d2fcb3dc96 /src/pkg/gob/decoder.go
parentd9527dd16f72598b54a64550607bf892efa12384 (diff)
downloadgolang-e4bd81f903362d998f7bfc02095935408aff0bc5.tar.gz
1) Change default gofmt default settings for
parsing and printing to new syntax. Use -oldparser to parse the old syntax, use -oldprinter to print the old syntax. 2) Change default gofmt formatting settings to use tabs for indentation only and to use spaces for alignment. This will make the code alignment insensitive to an editor's tabwidth. Use -spaces=false to use tabs for alignment. 3) Manually changed src/exp/parser/parser_test.go so that it doesn't try to parse the parser's source files using the old syntax (they have new syntax now). 4) gofmt -w src misc test/bench 3rd set of files. R=rsc CC=golang-dev http://codereview.appspot.com/180048
Diffstat (limited to 'src/pkg/gob/decoder.go')
-rw-r--r--src/pkg/gob/decoder.go92
1 files changed, 46 insertions, 46 deletions
diff --git a/src/pkg/gob/decoder.go b/src/pkg/gob/decoder.go
index 5202c8285..73f0979ed 100644
--- a/src/pkg/gob/decoder.go
+++ b/src/pkg/gob/decoder.go
@@ -5,51 +5,51 @@
package gob
import (
- "bytes";
- "io";
- "os";
- "reflect";
- "sync";
+ "bytes"
+ "io"
+ "os"
+ "reflect"
+ "sync"
)
// A Decoder manages the receipt of type and data information read from the
// remote side of a connection.
type Decoder struct {
- mutex sync.Mutex; // each item must be received atomically
- r io.Reader; // source of the data
- wireType map[typeId]*wireType; // map from remote ID to local description
- decoderCache map[reflect.Type]map[typeId]**decEngine; // cache of compiled engines
- ignorerCache map[typeId]**decEngine; // ditto for ignored objects
- state *decodeState; // reads data from in-memory buffer
- countState *decodeState; // reads counts from wire
- buf []byte;
- countBuf [9]byte; // counts may be uint64s (unlikely!), require 9 bytes
+ mutex sync.Mutex // each item must be received atomically
+ r io.Reader // source of the data
+ wireType map[typeId]*wireType // map from remote ID to local description
+ decoderCache map[reflect.Type]map[typeId]**decEngine // cache of compiled engines
+ ignorerCache map[typeId]**decEngine // ditto for ignored objects
+ state *decodeState // reads data from in-memory buffer
+ countState *decodeState // reads counts from wire
+ buf []byte
+ countBuf [9]byte // counts may be uint64s (unlikely!), require 9 bytes
}
// NewDecoder returns a new decoder that reads from the io.Reader.
func NewDecoder(r io.Reader) *Decoder {
- dec := new(Decoder);
- dec.r = r;
- dec.wireType = make(map[typeId]*wireType);
- dec.state = newDecodeState(nil); // buffer set in Decode(); rest is unimportant
- dec.decoderCache = make(map[reflect.Type]map[typeId]**decEngine);
- dec.ignorerCache = make(map[typeId]**decEngine);
+ dec := new(Decoder)
+ dec.r = r
+ dec.wireType = make(map[typeId]*wireType)
+ dec.state = newDecodeState(nil) // buffer set in Decode(); rest is unimportant
+ dec.decoderCache = make(map[reflect.Type]map[typeId]**decEngine)
+ dec.ignorerCache = make(map[typeId]**decEngine)
- return dec;
+ return dec
}
func (dec *Decoder) recvType(id typeId) {
// Have we already seen this type? That's an error
if _, alreadySeen := dec.wireType[id]; alreadySeen {
- dec.state.err = os.ErrorString("gob: duplicate type received");
- return;
+ dec.state.err = os.ErrorString("gob: duplicate type received")
+ return
}
// Type:
- wire := new(wireType);
- dec.state.err = dec.decode(tWireType, wire);
+ wire := new(wireType)
+ dec.state.err = dec.decode(tWireType, wire)
// Remember we've seen this type.
- dec.wireType[id] = wire;
+ dec.wireType[id] = wire
}
// Decode reads the next value from the connection and stores
@@ -60,19 +60,19 @@ func (dec *Decoder) Decode(e interface{}) os.Error {
// If e represents a value, the answer won't get back to the
// caller. Make sure it's a pointer.
if _, ok := reflect.Typeof(e).(*reflect.PtrType); !ok {
- dec.state.err = os.ErrorString("gob: attempt to decode into a non-pointer");
- return dec.state.err;
+ dec.state.err = os.ErrorString("gob: attempt to decode into a non-pointer")
+ return dec.state.err
}
// Make sure we're single-threaded through here.
- dec.mutex.Lock();
- defer dec.mutex.Unlock();
+ dec.mutex.Lock()
+ defer dec.mutex.Unlock()
- dec.state.err = nil;
+ dec.state.err = nil
for {
// Read a count.
- var nbytes uint64;
- nbytes, dec.state.err = decodeUintReader(dec.r, dec.countBuf[0:]);
+ var nbytes uint64
+ nbytes, dec.state.err = decodeUintReader(dec.r, dec.countBuf[0:])
if dec.state.err != nil {
break
}
@@ -80,42 +80,42 @@ func (dec *Decoder) Decode(e interface{}) os.Error {
if nbytes > uint64(len(dec.buf)) {
dec.buf = make([]byte, nbytes+1000)
}
- dec.state.b = bytes.NewBuffer(dec.buf[0:nbytes]);
+ dec.state.b = bytes.NewBuffer(dec.buf[0:nbytes])
// Read the data
- _, dec.state.err = io.ReadFull(dec.r, dec.buf[0:nbytes]);
+ _, dec.state.err = io.ReadFull(dec.r, dec.buf[0:nbytes])
if dec.state.err != nil {
if dec.state.err == os.EOF {
dec.state.err = io.ErrUnexpectedEOF
}
- break;
+ break
}
// Receive a type id.
- id := typeId(decodeInt(dec.state));
+ id := typeId(decodeInt(dec.state))
if dec.state.err != nil {
break
}
// Is it a new type?
- if id < 0 { // 0 is the error state, handled above
+ if id < 0 { // 0 is the error state, handled above
// If the id is negative, we have a type.
- dec.recvType(-id);
+ dec.recvType(-id)
if dec.state.err != nil {
break
}
- continue;
+ continue
}
// No, it's a value.
// Make sure the type has been defined already.
- _, ok := dec.wireType[id];
+ _, ok := dec.wireType[id]
if !ok {
- dec.state.err = errBadType;
- break;
+ dec.state.err = errBadType
+ break
}
- dec.state.err = dec.decode(id, e);
- break;
+ dec.state.err = dec.decode(id, e)
+ break
}
- return dec.state.err;
+ return dec.state.err
}