var errBadUint … var errBadType … var errRange … type decHelper … type decoderState … type decBuffer … func (d *decBuffer) Read(p []byte) (int, error) { … } func (d *decBuffer) Drop(n int) { … } func (d *decBuffer) ReadByte() (byte, error) { … } func (d *decBuffer) Len() int { … } func (d *decBuffer) Bytes() []byte { … } // SetBytes sets the buffer to the bytes, discarding any existing data. func (d *decBuffer) SetBytes(data []byte) { … } func (d *decBuffer) Reset() { … } // We pass the bytes.Buffer separately for easier testing of the infrastructure // without requiring a full Decoder. func (dec *Decoder) newDecoderState(buf *decBuffer) *decoderState { … } func (dec *Decoder) freeDecoderState(d *decoderState) { … } func overflow(name string) error { … } // decodeUintReader reads an encoded unsigned integer from an io.Reader. // Used only by the Decoder to read the message length. func decodeUintReader(r io.Reader, buf []byte) (x uint64, width int, err error) { … } // decodeUint reads an encoded unsigned integer from state.r. // Does not check for overflow. func (state *decoderState) decodeUint() (x uint64) { … } // decodeInt reads an encoded signed integer from state.r. // Does not check for overflow. func (state *decoderState) decodeInt() int64 { … } // getLength decodes the next uint and makes sure it is a possible // size for a data item that follows, which means it must fit in a // non-negative int and fit in the buffer. func (state *decoderState) getLength() (int, bool) { … } type decOp … type decInstr … // ignoreUint discards a uint value with no destination. func ignoreUint(i *decInstr, state *decoderState, v reflect.Value) { … } // ignoreTwoUints discards a uint value with no destination. It's used to skip // complex values. func ignoreTwoUints(i *decInstr, state *decoderState, v reflect.Value) { … } // decAlloc takes a value and returns a settable value that can // be assigned to. If the value is a pointer, decAlloc guarantees it points to storage. // The callers to the individual decoders are expected to have used decAlloc. // The individual decoders don't need it. func decAlloc(v reflect.Value) reflect.Value { … } // decBool decodes a uint and stores it as a boolean in value. func decBool(i *decInstr, state *decoderState, value reflect.Value) { … } // decInt8 decodes an integer and stores it as an int8 in value. func decInt8(i *decInstr, state *decoderState, value reflect.Value) { … } // decUint8 decodes an unsigned integer and stores it as a uint8 in value. func decUint8(i *decInstr, state *decoderState, value reflect.Value) { … } // decInt16 decodes an integer and stores it as an int16 in value. func decInt16(i *decInstr, state *decoderState, value reflect.Value) { … } // decUint16 decodes an unsigned integer and stores it as a uint16 in value. func decUint16(i *decInstr, state *decoderState, value reflect.Value) { … } // decInt32 decodes an integer and stores it as an int32 in value. func decInt32(i *decInstr, state *decoderState, value reflect.Value) { … } // decUint32 decodes an unsigned integer and stores it as a uint32 in value. func decUint32(i *decInstr, state *decoderState, value reflect.Value) { … } // decInt64 decodes an integer and stores it as an int64 in value. func decInt64(i *decInstr, state *decoderState, value reflect.Value) { … } // decUint64 decodes an unsigned integer and stores it as a uint64 in value. func decUint64(i *decInstr, state *decoderState, value reflect.Value) { … } // Floating-point numbers are transmitted as uint64s holding the bits // of the underlying representation. They are sent byte-reversed, with // the exponent end coming out first, so integer floating point numbers // (for example) transmit more compactly. This routine does the // unswizzling. func float64FromBits(u uint64) float64 { … } // float32FromBits decodes an unsigned integer, treats it as a 32-bit floating-point // number, and returns it. It's a helper function for float32 and complex64. // It returns a float64 because that's what reflection needs, but its return // value is known to be accurately representable in a float32. func float32FromBits(u uint64, ovfl error) float64 { … } // decFloat32 decodes an unsigned integer, treats it as a 32-bit floating-point // number, and stores it in value. func decFloat32(i *decInstr, state *decoderState, value reflect.Value) { … } // decFloat64 decodes an unsigned integer, treats it as a 64-bit floating-point // number, and stores it in value. func decFloat64(i *decInstr, state *decoderState, value reflect.Value) { … } // decComplex64 decodes a pair of unsigned integers, treats them as a // pair of floating point numbers, and stores them as a complex64 in value. // The real part comes first. func decComplex64(i *decInstr, state *decoderState, value reflect.Value) { … } // decComplex128 decodes a pair of unsigned integers, treats them as a // pair of floating point numbers, and stores them as a complex128 in value. // The real part comes first. func decComplex128(i *decInstr, state *decoderState, value reflect.Value) { … } // decUint8Slice decodes a byte slice and stores in value a slice header // describing the data. // uint8 slices are encoded as an unsigned count followed by the raw bytes. func decUint8Slice(i *decInstr, state *decoderState, value reflect.Value) { … } // decString decodes byte array and stores in value a string header // describing the data. // Strings are encoded as an unsigned count followed by the raw bytes. func decString(i *decInstr, state *decoderState, value reflect.Value) { … } // ignoreUint8Array skips over the data for a byte slice value with no destination. func ignoreUint8Array(i *decInstr, state *decoderState, value reflect.Value) { … } type decEngine … // decodeSingle decodes a top-level value that is not a struct and stores it in value. // Such values are preceded by a zero, making them have the memory layout of a // struct field (although with an illegal field number). func (dec *Decoder) decodeSingle(engine *decEngine, value reflect.Value) { … } // decodeStruct decodes a top-level struct and stores it in value. // Indir is for the value, not the type. At the time of the call it may // differ from ut.indir, which was computed when the engine was built. // This state cannot arise for decodeSingle, which is called directly // from the user's value, not from the innards of an engine. func (dec *Decoder) decodeStruct(engine *decEngine, value reflect.Value) { … } var noValue … // ignoreStruct discards the data for a struct with no destination. func (dec *Decoder) ignoreStruct(engine *decEngine) { … } // ignoreSingle discards the data for a top-level non-struct value with no // destination. It's used when calling Decode with a nil value. func (dec *Decoder) ignoreSingle(engine *decEngine) { … } // decodeArrayHelper does the work for decoding arrays and slices. func (dec *Decoder) decodeArrayHelper(state *decoderState, value reflect.Value, elemOp decOp, length int, ovfl error, helper decHelper) { … } // decodeArray decodes an array and stores it in value. // The length is an unsigned integer preceding the elements. Even though the length is redundant // (it's part of the type), it's a useful check and is included in the encoding. func (dec *Decoder) decodeArray(state *decoderState, value reflect.Value, elemOp decOp, length int, ovfl error, helper decHelper) { … } // decodeIntoValue is a helper for map decoding. func decodeIntoValue(state *decoderState, op decOp, isPtr bool, value reflect.Value, instr *decInstr) reflect.Value { … } // decodeMap decodes a map and stores it in value. // Maps are encoded as a length followed by key:value pairs. // Because the internals of maps are not visible to us, we must // use reflection rather than pointer magic. func (dec *Decoder) decodeMap(mtyp reflect.Type, state *decoderState, value reflect.Value, keyOp, elemOp decOp, ovfl error) { … } // ignoreArrayHelper does the work for discarding arrays and slices. func (dec *Decoder) ignoreArrayHelper(state *decoderState, elemOp decOp, length int) { … } // ignoreArray discards the data for an array value with no destination. func (dec *Decoder) ignoreArray(state *decoderState, elemOp decOp, length int) { … } // ignoreMap discards the data for a map value with no destination. func (dec *Decoder) ignoreMap(state *decoderState, keyOp, elemOp decOp) { … } // decodeSlice decodes a slice and stores it in value. // Slices are encoded as an unsigned length followed by the elements. func (dec *Decoder) decodeSlice(state *decoderState, value reflect.Value, elemOp decOp, ovfl error, helper decHelper) { … } // ignoreSlice skips over the data for a slice value with no destination. func (dec *Decoder) ignoreSlice(state *decoderState, elemOp decOp) { … } // decodeInterface decodes an interface value and stores it in value. // Interfaces are encoded as the name of a concrete type followed by a value. // If the name is empty, the value is nil and no value is sent. func (dec *Decoder) decodeInterface(ityp reflect.Type, state *decoderState, value reflect.Value) { … } // ignoreInterface discards the data for an interface value with no destination. func (dec *Decoder) ignoreInterface(state *decoderState) { … } // decodeGobDecoder decodes something implementing the GobDecoder interface. // The data is encoded as a byte slice. func (dec *Decoder) decodeGobDecoder(ut *userTypeInfo, state *decoderState, value reflect.Value) { … } // ignoreGobDecoder discards the data for a GobDecoder value with no destination. func (dec *Decoder) ignoreGobDecoder(state *decoderState) { … } var decOpTable … var decIgnoreOpMap … // decOpFor returns the decoding op for the base type under rt and // the indirection count to reach it. func (dec *Decoder) decOpFor(wireId typeId, rt reflect.Type, name string, inProgress map[reflect.Type]*decOp) *decOp { … } var maxIgnoreNestingDepth … // decIgnoreOpFor returns the decoding op for a field that has no destination. func (dec *Decoder) decIgnoreOpFor(wireId typeId, inProgress map[typeId]*decOp) *decOp { … } // gobDecodeOpFor returns the op for a type that is known to implement // GobDecoder. func (dec *Decoder) gobDecodeOpFor(ut *userTypeInfo) *decOp { … } // compatibleType asks: Are these two gob Types compatible? // Answers the question for basic types, arrays, maps and slices, plus // GobEncoder/Decoder pairs. // Structs are considered ok; fields will be checked later. func (dec *Decoder) compatibleType(fr reflect.Type, fw typeId, inProgress map[reflect.Type]typeId) bool { … } // typeString returns a human-readable description of the type identified by remoteId. func (dec *Decoder) typeString(remoteId typeId) string { … } // compileSingle compiles the decoder engine for a non-struct top-level value, including // GobDecoders. func (dec *Decoder) compileSingle(remoteId typeId, ut *userTypeInfo) (engine *decEngine, err error) { … } // compileIgnoreSingle compiles the decoder engine for a non-struct top-level value that will be discarded. func (dec *Decoder) compileIgnoreSingle(remoteId typeId) *decEngine { … } // compileDec compiles the decoder engine for a value. If the value is not a struct, // it calls out to compileSingle. func (dec *Decoder) compileDec(remoteId typeId, ut *userTypeInfo) (engine *decEngine, err error) { … } // getDecEnginePtr returns the engine for the specified type. func (dec *Decoder) getDecEnginePtr(remoteId typeId, ut *userTypeInfo) (enginePtr **decEngine, err error) { … } type emptyStruct … var emptyStructType … // getIgnoreEnginePtr returns the engine for the specified type when the value is to be discarded. func (dec *Decoder) getIgnoreEnginePtr(wireId typeId) (enginePtr **decEngine, err error) { … } // decodeValue decodes the data stream representing a value and stores it in value. func (dec *Decoder) decodeValue(wireId typeId, value reflect.Value) { … } // decodeIgnoredValue decodes the data stream representing a value of the specified type and discards it. func (dec *Decoder) decodeIgnoredValue(wireId typeId) { … } const intBits … const uintptrBits … func init() { … } // Gob depends on being able to take the address // of zeroed Values it creates, so use this wrapper instead // of the standard reflect.Zero. // Each call allocates once. func allocValue(t reflect.Type) reflect.Value { … }