summaryrefslogtreecommitdiff
path: root/src/pkg/gob/decoder.go
diff options
context:
space:
mode:
authorRob Pike <r@golang.org>2009-07-27 11:02:06 -0700
committerRob Pike <r@golang.org>2009-07-27 11:02:06 -0700
commitc8e43d6ee052cf72b1cd037baceb19f16ed9b038 (patch)
tree3f6b6494dae9ebde3b936a77f1009c3db0cf9111 /src/pkg/gob/decoder.go
parentc0797ee99b7cab39567c55d995d1a43d34032310 (diff)
downloadgolang-c8e43d6ee052cf72b1cd037baceb19f16ed9b038.tar.gz
clean up for public use: make some stuff private, add doc comments.
R=rsc DELTA=298 (202 added, 0 deleted, 96 changed) OCL=32006 CL=32224
Diffstat (limited to 'src/pkg/gob/decoder.go')
-rw-r--r--src/pkg/gob/decoder.go21
1 files changed, 13 insertions, 8 deletions
diff --git a/src/pkg/gob/decoder.go b/src/pkg/gob/decoder.go
index 609a20484..7dd99a076 100644
--- a/src/pkg/gob/decoder.go
+++ b/src/pkg/gob/decoder.go
@@ -13,27 +13,30 @@ import (
"sync";
)
+// A Decoder manages the receipt of type and data information read from the
+// remote side of a connection.
type Decoder struct {
- sync.Mutex; // each item must be received atomically
+ mutex sync.Mutex; // each item must be received atomically
r io.Reader; // source of the data
- seen map[TypeId] *wireType; // which types we've already seen described
+ seen map[typeId] *wireType; // which types we've already seen described
state *decodeState; // reads data from in-memory buffer
countState *decodeState; // reads counts from wire
buf []byte;
oneByte []byte;
}
+// NewDecoder returns a new decoder that reads from the io.Reader.
func NewDecoder(r io.Reader) *Decoder {
dec := new(Decoder);
dec.r = r;
- dec.seen = make(map[TypeId] *wireType);
+ dec.seen = make(map[typeId] *wireType);
dec.state = new(decodeState); // buffer set in Decode(); rest is unimportant
dec.oneByte = make([]byte, 1);
return dec;
}
-func (dec *Decoder) recvType(id TypeId) {
+func (dec *Decoder) recvType(id typeId) {
// Have we already seen this type? That's an error
if wt_, alreadySeen := dec.seen[id]; alreadySeen {
dec.state.err = os.ErrorString("gob: duplicate type received");
@@ -47,14 +50,16 @@ func (dec *Decoder) recvType(id TypeId) {
dec.seen[id] = wire;
}
+// Decode reads the next value from the connection and stores
+// it in the data represented by the empty interface value.
// The value underlying e must be the correct type for the next
-// value to be received for this decoder.
+// data item received.
func (dec *Decoder) Decode(e interface{}) os.Error {
rt, indir := indirect(reflect.Typeof(e));
// Make sure we're single-threaded through here.
- dec.Lock();
- defer dec.Unlock();
+ dec.mutex.Lock();
+ defer dec.mutex.Unlock();
dec.state.err = nil;
for {
@@ -81,7 +86,7 @@ func (dec *Decoder) Decode(e interface{}) os.Error {
}
// Receive a type id.
- id := TypeId(decodeInt(dec.state));
+ id := typeId(decodeInt(dec.state));
if dec.state.err != nil {
break;
}