Browse Source

codec: clean up codebase to try to keep lines within 90 bytes.

Ugorji Nwoke 8 years ago
parent
commit
7bdfbc6818
10 changed files with 128 additions and 114 deletions
  1. 3 2
      codec/binc.go
  2. 4 2
      codec/cbor.go
  3. 1 11
      codec/codec_test.go
  4. 9 7
      codec/decode.go
  5. 2 19
      codec/encode.go
  6. 67 52
      codec/helper.go
  7. 15 6
      codec/msgpack.go
  8. 8 4
      codec/noop.go
  9. 1 1
      codec/rpc.go
  10. 18 10
      codec/simple.go

+ 3 - 2
codec/binc.go

@@ -501,7 +501,7 @@ func (d *bincDecDriver) decCheckInteger() (ui uint64, neg bool) {
 			return
 			return
 		}
 		}
 	} else {
 	} else {
-		d.d.errorf("number can only be decoded from uint or int values. d.bd: 0x%x, d.vd: 0x%x", d.bd, d.vd)
+		d.d.errorf("integer can only be decoded from int/uint. d.bd: 0x%x, d.vd: 0x%x", d.bd, d.vd)
 		return
 		return
 	}
 	}
 	return
 	return
@@ -621,7 +621,8 @@ func (d *bincDecDriver) decLenNumber() (v uint64) {
 	return
 	return
 }
 }
 
 
-func (d *bincDecDriver) decStringAndBytes(bs []byte, withString, zerocopy bool) (bs2 []byte, s string) {
+func (d *bincDecDriver) decStringAndBytes(bs []byte, withString, zerocopy bool) (
+	bs2 []byte, s string) {
 	if !d.bdRead {
 	if !d.bdRead {
 		d.readNextBd()
 		d.readNextBd()
 	}
 	}

+ 4 - 2
codec/cbor.go

@@ -440,7 +440,8 @@ func (d *cborDecDriver) decAppendIndefiniteBytes(bs []byte) []byte {
 			break
 			break
 		}
 		}
 		if major := d.bd >> 5; major != cborMajorBytes && major != cborMajorText {
 		if major := d.bd >> 5; major != cborMajorBytes && major != cborMajorText {
-			d.d.errorf("expect bytes or string major type in indefinite string/bytes; got: %v, byte: %v", major, d.bd)
+			d.d.errorf("expect bytes/string major type in indefinite string/bytes;"+
+				" got: %v, byte: %v", major, d.bd)
 			return nil
 			return nil
 		}
 		}
 		n := d.decLen()
 		n := d.decLen()
@@ -537,7 +538,8 @@ func (d *cborDecDriver) decodeTime(xtag uint64) (t time.Time) {
 		case d.bd == cborBdFloat64:
 		case d.bd == cborBdFloat64:
 			f1, f2 := math.Modf(d.DecodeFloat64())
 			f1, f2 := math.Modf(d.DecodeFloat64())
 			t = time.Unix(int64(f1), int64(f2*1e9))
 			t = time.Unix(int64(f1), int64(f2*1e9))
-		case d.bd >= cborBaseUint && d.bd < cborBaseNegInt, d.bd >= cborBaseNegInt && d.bd < cborBaseBytes:
+		case d.bd >= cborBaseUint && d.bd < cborBaseNegInt,
+			d.bd >= cborBaseNegInt && d.bd < cborBaseBytes:
 			t = time.Unix(d.DecodeInt64(), 0)
 			t = time.Unix(d.DecodeInt64(), 0)
 		default:
 		default:
 			d.d.errorf("time.Time can only be decoded from a number (or RFC3339 string)")
 			d.d.errorf("time.Time can only be decoded from a number (or RFC3339 string)")

+ 1 - 11
codec/codec_test.go

@@ -211,18 +211,8 @@ func (x *testUnixNanoTimeExt) ReadExt(v interface{}, bs []byte) {
 	*v2 = time.Unix(0, int64(ui)).UTC()
 	*v2 = time.Unix(0, int64(ui)).UTC()
 }
 }
 func (x *testUnixNanoTimeExt) ConvertExt(v interface{}) interface{} {
 func (x *testUnixNanoTimeExt) ConvertExt(v interface{}) interface{} {
-	v2 := v.(*time.Time) // structs are encoded by passing the value
+	v2 := v.(*time.Time) // structs are encoded by passing the ptr
 	return v2.UTC().UnixNano()
 	return v2.UTC().UnixNano()
-	// return x.ts
-	// switch v2 := v.(type) {
-	// case time.Time:
-	// 	x.ts = v2.UTC().UnixNano()
-	// case *time.Time:
-	// 	x.ts = v2.UTC().UnixNano()
-	// default:
-	// 	panic(fmt.Sprintf("unsupported format for time conversion: expecting time.Time; got %T", v))
-	// }
-	// return &x.ts
 }
 }
 
 
 func (x *testUnixNanoTimeExt) UpdateExt(dest interface{}, v interface{}) {
 func (x *testUnixNanoTimeExt) UpdateExt(dest interface{}, v interface{}) {

+ 9 - 7
codec/decode.go

@@ -146,11 +146,12 @@ type DecodeOptions struct {
 	// If nil (unset), we default to []interface{} for all formats.
 	// If nil (unset), we default to []interface{} for all formats.
 	SliceType reflect.Type
 	SliceType reflect.Type
 
 
-	// MaxInitLen defines the maxinum initial length that we "make" a collection (string, slice, map, chan).
-	// If 0 or negative, we default to a sensible value based on the size of an element in the collection.
+	// MaxInitLen defines the maxinum initial length that we "make" a collection
+	// (string, slice, map, chan). If 0 or negative, we default to a sensible value
+	// based on the size of an element in the collection.
 	//
 	//
 	// For example, when decoding, a stream may say that it has 2^64 elements.
 	// For example, when decoding, a stream may say that it has 2^64 elements.
-	// We should not auto-matically provision a slice of that length, to prevent Out-Of-Memory crash.
+	// We should not auto-matically provision a slice of that size, to prevent Out-Of-Memory crash.
 	// Instead, we provision up to MaxInitLen, fill that up, and start appending after that.
 	// Instead, we provision up to MaxInitLen, fill that up, and start appending after that.
 	MaxInitLen int
 	MaxInitLen int
 
 
@@ -1190,7 +1191,7 @@ func (d *Decoder) kStruct(f *codecFnInfo, rv reflect.Value) {
 			} else {
 			} else {
 				d.structFieldNotFound(-1, rvkencname)
 				d.structFieldNotFound(-1, rvkencname)
 			}
 			}
-			// keepAlive4StringView(rvkencnameB) // maintain ref 4 stringView // not needed, as reference is outside loop
+			// keepAlive4StringView(rvkencnameB) // not needed, as reference is outside loop
 		}
 		}
 		dd.ReadMapEnd()
 		dd.ReadMapEnd()
 	} else if ctyp == valueTypeArray {
 	} else if ctyp == valueTypeArray {
@@ -1244,7 +1245,7 @@ func (d *Decoder) kSlice(f *codecFnInfo, rv reflect.Value) {
 	if ctyp == valueTypeBytes || ctyp == valueTypeString {
 	if ctyp == valueTypeBytes || ctyp == valueTypeString {
 		// you can only decode bytes or string in the stream into a slice or array of bytes
 		// you can only decode bytes or string in the stream into a slice or array of bytes
 		if !(ti.rtid == uint8SliceTypId || rtelem0.Kind() == reflect.Uint8) {
 		if !(ti.rtid == uint8SliceTypId || rtelem0.Kind() == reflect.Uint8) {
-			d.errorf("bytes or string in the stream must be decoded into a slice or array of bytes, not %v", ti.rt)
+			d.errorf("bytes/string in stream must decode into slice/array of bytes, not %v", ti.rt)
 		}
 		}
 		if f.seq == seqTypeChan {
 		if f.seq == seqTypeChan {
 			bs2 := dd.DecodeBytes(nil, true)
 			bs2 := dd.DecodeBytes(nil, true)
@@ -1393,10 +1394,11 @@ func (d *Decoder) kSlice(f *codecFnInfo, rv reflect.Value) {
 					d.arrayCannotExpand(rvlen, j+1)
 					d.arrayCannotExpand(rvlen, j+1)
 					decodeIntoBlank = true
 					decodeIntoBlank = true
 				} else { // if f.seq == seqTypeSlice
 				} else { // if f.seq == seqTypeSlice
-					// rv = reflect.Append(rv, reflect.Zero(rtelem0)) // uses append logic, plus varargs
+					// rv = reflect.Append(rv, reflect.Zero(rtelem0)) // append logic + varargs
 					var rvcap2 int
 					var rvcap2 int
 					var rvErrmsg2 string
 					var rvErrmsg2 string
-					rv9, rvcap2, rvChanged, rvErrmsg2 = expandSliceRV(rv, ti.rt, rvCanset, rtelem0Size, 1, rvlen, rvcap)
+					rv9, rvcap2, rvChanged, rvErrmsg2 =
+						expandSliceRV(rv, ti.rt, rvCanset, rtelem0Size, 1, rvlen, rvcap)
 					if rvErrmsg2 != "" {
 					if rvErrmsg2 != "" {
 						d.errorf(rvErrmsg2)
 						d.errorf(rvErrmsg2)
 					}
 					}

+ 2 - 19
codec/encode.go

@@ -258,26 +258,9 @@ func (e *Encoder) rawExt(f *codecFnInfo, rv reflect.Value) {
 }
 }
 
 
 func (e *Encoder) ext(f *codecFnInfo, rv reflect.Value) {
 func (e *Encoder) ext(f *codecFnInfo, rv reflect.Value) {
-	// if this is a struct|array and it was addressable, then pass the address directly (not the value)
-	// if k := rv.Kind(); (k == reflect.Struct || k == reflect.Array) && rv.CanAddr() {
-	// 	rv = rv.Addr()
-	// }
 	e.e.EncodeExt(rv2i(rv), f.xfTag, f.xfFn, e)
 	e.e.EncodeExt(rv2i(rv), f.xfTag, f.xfFn, e)
 }
 }
 
 
-// func rviptr(rv reflect.Value) (v interface{}) {
-// 	// If a non-pointer was passed to Encode(), then that value is not addressable.
-// 	// Take addr if addressable, else copy value to an addressable value.
-// 	if rv.CanAddr() {
-// 		v = rv2i(rv.Addr())
-// 	} else {
-// 		rv2 := reflect.New(rv.Type())
-// 		rv2.Elem().Set(rv)
-// 		v = rv2i(rv2)
-// 	}
-// 	return v
-// }
-
 func (e *Encoder) selferMarshal(f *codecFnInfo, rv reflect.Value) {
 func (e *Encoder) selferMarshal(f *codecFnInfo, rv reflect.Value) {
 	rv2i(rv).(Selfer).CodecEncodeSelf(e)
 	rv2i(rv).(Selfer).CodecEncodeSelf(e)
 }
 }
@@ -1037,7 +1020,7 @@ func (e *Encoder) ResetBytes(out *[]byte) {
 // However, there are instances where the encoded stream has mapping keys encoded as numbers.
 // However, there are instances where the encoded stream has mapping keys encoded as numbers.
 // For example, some cbor streams have keys as integer codes in the stream, but they should map
 // For example, some cbor streams have keys as integer codes in the stream, but they should map
 // to fields in a structured object. Consequently, a struct is the natural representation in code.
 // to fields in a structured object. Consequently, a struct is the natural representation in code.
-// For these, you can configure the struct to encode/decode the keys as numbers (instead of string).
+// For these, configure the struct to encode/decode the keys as numbers (instead of string).
 // This is done with the int,uint or float option on the _struct field (see above).
 // This is done with the int,uint or float option on the _struct field (see above).
 //
 //
 // However, struct values may encode as arrays. This happens when:
 // However, struct values may encode as arrays. This happens when:
@@ -1083,7 +1066,7 @@ func (e *Encoder) ResetBytes(out *[]byte) {
 // The mode of encoding is based on the type of the value. When a value is seen:
 // The mode of encoding is based on the type of the value. When a value is seen:
 //   - If a Selfer, call its CodecEncodeSelf method
 //   - If a Selfer, call its CodecEncodeSelf method
 //   - If an extension is registered for it, call that extension function
 //   - If an extension is registered for it, call that extension function
-//   - If it implements encoding.(Binary|Text|JSON)Marshaler, call its Marshal(Binary|Text|JSON) method
+//   - If implements encoding.(Binary|Text|JSON)Marshaler, call Marshal(Binary|Text|JSON) method
 //   - Else encode it based on its reflect.Kind
 //   - Else encode it based on its reflect.Kind
 //
 //
 // Note that struct field names and keys in map[string]XXX will be treated as symbols.
 // Note that struct field names and keys in map[string]XXX will be treated as symbols.

+ 67 - 52
codec/helper.go

@@ -388,7 +388,7 @@ type Selfer interface {
 	CodecDecodeSelf(*Decoder)
 	CodecDecodeSelf(*Decoder)
 }
 }
 
 
-// MapBySlice is a tag interface that denotes a slice which should be encoded as a map in the stream.
+// MapBySlice is a tag interface that denotes wrapped slice should encode as a map in the stream.
 // The slice contains a sequence of key-value pairs.
 // The slice contains a sequence of key-value pairs.
 // This affords storing a map in a specific sequence in the stream.
 // This affords storing a map in a specific sequence in the stream.
 //
 //
@@ -463,20 +463,24 @@ type Handle interface {
 
 
 // Raw represents raw formatted bytes.
 // Raw represents raw formatted bytes.
 // We "blindly" store it during encode and retrieve the raw bytes during decode.
 // We "blindly" store it during encode and retrieve the raw bytes during decode.
-// Note: it is dangerous during encode, so we may gate the behaviour behind an Encode flag which must be explicitly set.
+// Note: it is dangerous during encode, so we may gate the behaviour
+// behind an Encode flag which must be explicitly set.
 type Raw []byte
 type Raw []byte
 
 
 // RawExt represents raw unprocessed extension data.
 // RawExt represents raw unprocessed extension data.
-// Some codecs will decode extension data as a *RawExt if there is no registered extension for the tag.
+// Some codecs will decode extension data as a *RawExt
+// if there is no registered extension for the tag.
 //
 //
-// Only one of Data or Value is nil. If Data is nil, then the content of the RawExt is in the Value.
+// Only one of Data or Value is nil.
+// If Data is nil, then the content of the RawExt is in the Value.
 type RawExt struct {
 type RawExt struct {
 	Tag uint64
 	Tag uint64
-	// Data is the []byte which represents the raw ext. If Data is nil, ext is exposed in Value.
-	// Data is used by codecs (e.g. binc, msgpack, simple) which do custom serialization of the types
+	// Data is the []byte which represents the raw ext. If nil, ext is exposed in Value.
+	// Data is used by codecs (e.g. binc, msgpack, simple) which do custom serialization of types
 	Data []byte
 	Data []byte
 	// Value represents the extension, if Data is nil.
 	// Value represents the extension, if Data is nil.
-	// Value is used by codecs (e.g. cbor, json) which use the format to do custom serialization of the types.
+	// Value is used by codecs (e.g. cbor, json) which leverage the format to do
+	// custom serialization of the types.
 	Value interface{}
 	Value interface{}
 }
 }
 
 
@@ -485,24 +489,30 @@ type RawExt struct {
 type BytesExt interface {
 type BytesExt interface {
 	// WriteExt converts a value to a []byte.
 	// WriteExt converts a value to a []byte.
 	//
 	//
-	// Note: v *may* be a pointer to the extension type, if the extension type was a struct or array.
+	// Note: v is a pointer iff the registered extension type is a struct or array kind.
 	WriteExt(v interface{}) []byte
 	WriteExt(v interface{}) []byte
 
 
 	// ReadExt updates a value from a []byte.
 	// ReadExt updates a value from a []byte.
+	//
+	// Note: dst is always a pointer kind to the registered extension type.
 	ReadExt(dst interface{}, src []byte)
 	ReadExt(dst interface{}, src []byte)
 }
 }
 
 
 // InterfaceExt handles custom (de)serialization of types to/from another interface{} value.
 // InterfaceExt handles custom (de)serialization of types to/from another interface{} value.
 // The Encoder or Decoder will then handle the further (de)serialization of that known type.
 // The Encoder or Decoder will then handle the further (de)serialization of that known type.
 //
 //
-// It is used by codecs (e.g. cbor, json) which use the format to do custom serialization of the types.
+// It is used by codecs (e.g. cbor, json) which use the format to do custom serialization of types.
 type InterfaceExt interface {
 type InterfaceExt interface {
-	// ConvertExt converts a value into a simpler interface for easy encoding e.g. convert time.Time to int64.
+	// ConvertExt converts a value into a simpler interface for easy encoding
+	// e.g. convert time.Time to int64.
 	//
 	//
-	// Note: v *may* be a pointer to the extension type, if the extension type was a struct or array.
+	// Note: v is a pointer iff the registered extension type is a struct or array kind.
 	ConvertExt(v interface{}) interface{}
 	ConvertExt(v interface{}) interface{}
 
 
-	// UpdateExt updates a value from a simpler interface for easy decoding e.g. convert int64 to time.Time.
+	// UpdateExt updates a value from a simpler interface for easy decoding
+	// e.g. convert int64 to time.Time.
+	//
+	// Note: dst is always a pointer kind to the registered extension type.
 	UpdateExt(dst interface{}, src interface{})
 	UpdateExt(dst interface{}, src interface{})
 }
 }
 
 
@@ -1169,7 +1179,8 @@ func (x *TypeInfos) rget(rt reflect.Type, rtid uintptr, omitEmpty bool,
 	//       and iteration using equals is faster than maps there
 	//       and iteration using equals is faster than maps there
 	flen := rt.NumField()
 	flen := rt.NumField()
 	if flen > (1<<maxLevelsEmbedding - 1) {
 	if flen > (1<<maxLevelsEmbedding - 1) {
-		panicv.errorf("codec: types with more than %v fields are not supported - has %v fields", (1<<maxLevelsEmbedding - 1), flen)
+		panicv.errorf("codec: types with > %v fields are not supported - has %v fields",
+			(1<<maxLevelsEmbedding - 1), flen)
 	}
 	}
 LOOP:
 LOOP:
 	for j, jlen := uint16(0), uint16(flen); j < jlen; j++ {
 	for j, jlen := uint16(0), uint16(flen); j < jlen; j++ {
@@ -1266,7 +1277,8 @@ LOOP:
 
 
 		// si.ikind = int(f.Type.Kind())
 		// si.ikind = int(f.Type.Kind())
 		if len(indexstack) > maxLevelsEmbedding-1 {
 		if len(indexstack) > maxLevelsEmbedding-1 {
-			panicv.errorf("codec: only supports up to %v depth of embedding - type has %v depth", maxLevelsEmbedding-1, len(indexstack))
+			panicv.errorf("codec: only supports up to %v depth of embedding - type has %v depth",
+				maxLevelsEmbedding-1, len(indexstack))
 		}
 		}
 		si.nis = uint8(len(indexstack)) + 1
 		si.nis = uint8(len(indexstack)) + 1
 		copy(si.is[:], indexstack)
 		copy(si.is[:], indexstack)
@@ -1389,46 +1401,8 @@ func panicValToErr(h errstrDecorator, v interface{}, err *error) {
 
 
 func isImmutableKind(k reflect.Kind) (v bool) {
 func isImmutableKind(k reflect.Kind) (v bool) {
 	return immutableKindsSet[k]
 	return immutableKindsSet[k]
-	// return false ||
-	// 	k == reflect.Int ||
-	// 	k == reflect.Int8 ||
-	// 	k == reflect.Int16 ||
-	// 	k == reflect.Int32 ||
-	// 	k == reflect.Int64 ||
-	// 	k == reflect.Uint ||
-	// 	k == reflect.Uint8 ||
-	// 	k == reflect.Uint16 ||
-	// 	k == reflect.Uint32 ||
-	// 	k == reflect.Uint64 ||
-	// 	k == reflect.Uintptr ||
-	// 	k == reflect.Float32 ||
-	// 	k == reflect.Float64 ||
-	// 	k == reflect.Bool ||
-	// 	k == reflect.String
 }
 }
 
 
-// func timeLocUTCName(tzint int16) string {
-// 	if tzint == 0 {
-// 		return "UTC"
-// 	}
-// 	var tzname = []byte("UTC+00:00")
-// 	//tzname := fmt.Sprintf("UTC%s%02d:%02d", tzsign, tz/60, tz%60) //perf issue using Sprintf. inline below.
-// 	//tzhr, tzmin := tz/60, tz%60 //faster if u convert to int first
-// 	var tzhr, tzmin int16
-// 	if tzint < 0 {
-// 		tzname[3] = '-' // (TODO: verify. this works here)
-// 		tzhr, tzmin = -tzint/60, (-tzint)%60
-// 	} else {
-// 		tzhr, tzmin = tzint/60, tzint%60
-// 	}
-// 	tzname[4] = timeDigits[tzhr/10]
-// 	tzname[5] = timeDigits[tzhr%10]
-// 	tzname[7] = timeDigits[tzmin/10]
-// 	tzname[8] = timeDigits[tzmin%10]
-// 	return string(tzname)
-// 	//return time.FixedZone(string(tzname), int(tzint)*60)
-// }
-
 // ----
 // ----
 
 
 type codecFnInfo struct {
 type codecFnInfo struct {
@@ -2203,3 +2177,44 @@ func (must) Float(s float64, err error) float64 {
 	}
 	}
 	return s
 	return s
 }
 }
+
+// func isImmutableKind(k reflect.Kind) (v bool) {
+// 	return false ||
+// 		k == reflect.Int ||
+// 		k == reflect.Int8 ||
+// 		k == reflect.Int16 ||
+// 		k == reflect.Int32 ||
+// 		k == reflect.Int64 ||
+// 		k == reflect.Uint ||
+// 		k == reflect.Uint8 ||
+// 		k == reflect.Uint16 ||
+// 		k == reflect.Uint32 ||
+// 		k == reflect.Uint64 ||
+// 		k == reflect.Uintptr ||
+// 		k == reflect.Float32 ||
+// 		k == reflect.Float64 ||
+// 		k == reflect.Bool ||
+// 		k == reflect.String
+// }
+
+// func timeLocUTCName(tzint int16) string {
+// 	if tzint == 0 {
+// 		return "UTC"
+// 	}
+// 	var tzname = []byte("UTC+00:00")
+// 	//tzname := fmt.Sprintf("UTC%s%02d:%02d", tzsign, tz/60, tz%60) //perf issue using Sprintf. inline below.
+// 	//tzhr, tzmin := tz/60, tz%60 //faster if u convert to int first
+// 	var tzhr, tzmin int16
+// 	if tzint < 0 {
+// 		tzname[3] = '-' // (TODO: verify. this works here)
+// 		tzhr, tzmin = -tzint/60, (-tzint)%60
+// 	} else {
+// 		tzhr, tzmin = tzint/60, tzint%60
+// 	}
+// 	tzname[4] = timeDigits[tzhr/10]
+// 	tzname[5] = timeDigits[tzhr%10]
+// 	tzname[7] = timeDigits[tzmin/10]
+// 	tzname[8] = timeDigits[tzmin%10]
+// 	return string(tzname)
+// 	//return time.FixedZone(string(tzname), int(tzint)*60)
+// }

+ 15 - 6
codec/msgpack.go

@@ -98,10 +98,18 @@ type msgpackContainerType struct {
 }
 }
 
 
 var (
 var (
-	msgpackContainerStr  = msgpackContainerType{32, mpFixStrMin, mpStr8, mpStr16, mpStr32, true, true, false}
-	msgpackContainerBin  = msgpackContainerType{0, 0, mpBin8, mpBin16, mpBin32, false, true, true}
-	msgpackContainerList = msgpackContainerType{16, mpFixArrayMin, 0, mpArray16, mpArray32, true, false, false}
-	msgpackContainerMap  = msgpackContainerType{16, mpFixMapMin, 0, mpMap16, mpMap32, true, false, false}
+	msgpackContainerStr = msgpackContainerType{
+		32, mpFixStrMin, mpStr8, mpStr16, mpStr32, true, true, false,
+	}
+	msgpackContainerBin = msgpackContainerType{
+		0, 0, mpBin8, mpBin16, mpBin32, false, true, true,
+	}
+	msgpackContainerList = msgpackContainerType{
+		16, mpFixArrayMin, 0, mpArray16, mpArray32, true, false, false,
+	}
+	msgpackContainerMap = msgpackContainerType{
+		16, mpFixMapMin, 0, mpMap16, mpMap32, true, false, false,
+	}
 )
 )
 
 
 //---------------------------------------------
 //---------------------------------------------
@@ -763,7 +771,7 @@ func (d *msgpackDecDriver) DecodeTime() (t time.Time) {
 		} else if d.bd == mpExt8 && b2 == 12 && d.r.readn1() == mpTimeExtTagU {
 		} else if d.bd == mpExt8 && b2 == 12 && d.r.readn1() == mpTimeExtTagU {
 			clen = 12
 			clen = 12
 		} else {
 		} else {
-			d.d.errorf("invalid sequence of bytes for decoding time as an extension: got 0x%x, 0x%x", d.bd, b2)
+			d.d.errorf("invalid bytes for decoding time as extension: got 0x%x, 0x%x", d.bd, b2)
 			return
 			return
 		}
 		}
 	}
 	}
@@ -965,7 +973,8 @@ func (c *msgpackSpecRpcCodec) parseCustomHeader(expectTypeByte byte, msgid *uint
 		err = c.read(&b)
 		err = c.read(&b)
 		if err == nil {
 		if err == nil {
 			if b != expectTypeByte {
 			if b != expectTypeByte {
-				err = fmt.Errorf("Unexpected byte descriptor in header. Expecting %v. Received %v", expectTypeByte, b)
+				err = fmt.Errorf("Unexpected byte descriptor. Expecting %v; Received %v",
+					expectTypeByte, b)
 			} else {
 			} else {
 				err = c.read(msgid)
 				err = c.read(msgid)
 				if err == nil {
 				if err == nil {

+ 8 - 4
codec/noop.go

@@ -120,9 +120,12 @@ func (h *noopDrv) ReadArrayStart() int { h.start(false); return h.m(10) }
 
 
 func (h *noopDrv) ContainerType() (vt valueType) {
 func (h *noopDrv) ContainerType() (vt valueType) {
 	// return h.m(2) == 0
 	// return h.m(2) == 0
-	// handle kStruct, which will bomb is it calls this and doesn't get back a map or array.
-	// consequently, if the return value is not map or array, reset it to one of them based on h.m(7) % 2
-	// for kstruct: at least one out of every 2 times, return one of valueTypeMap or Array (else kstruct bombs)
+	// handle kStruct, which will bomb is it calls this and
+	// doesn't get back a map or array.
+	// consequently, if the return value is not map or array,
+	// reset it to one of them based on h.m(7) % 2
+	// for kstruct: at least one out of every 2 times,
+	// return one of valueTypeMap or Array (else kstruct bombs)
 	// however, every 10th time it is called, we just return something else.
 	// however, every 10th time it is called, we just return something else.
 	var vals = [...]valueType{valueTypeArray, valueTypeMap}
 	var vals = [...]valueType{valueTypeArray, valueTypeMap}
 	//  ------------ TAKE ------------
 	//  ------------ TAKE ------------
@@ -151,7 +154,8 @@ func (h *noopDrv) ContainerType() (vt valueType) {
 	// }
 	// }
 	// return valueTypeUnset
 	// return valueTypeUnset
 	// TODO: may need to tweak this so it works.
 	// TODO: may need to tweak this so it works.
-	// if h.ct == valueTypeMap && vt == valueTypeArray || h.ct == valueTypeArray && vt == valueTypeMap {
+	// if h.ct == valueTypeMap && vt == valueTypeArray ||
+	// 	h.ct == valueTypeArray && vt == valueTypeMap {
 	// 	h.cb = !h.cb
 	// 	h.cb = !h.cb
 	// 	h.ct = vt
 	// 	h.ct = vt
 	// 	return h.cb
 	// 	return h.cb

+ 1 - 1
codec/rpc.go

@@ -211,7 +211,7 @@ type goRpc struct{}
 //   var clientCodec = GoRpc.ClientCodec(conn, handle)
 //   var clientCodec = GoRpc.ClientCodec(conn, handle)
 //
 //
 // Example 2: you can also explicitly create a buffered connection yourself,
 // Example 2: you can also explicitly create a buffered connection yourself,
-//            and not worry about configuring the buffer sizes in the Handle.
+// and not worry about configuring the buffer sizes in the Handle.
 //   var handle codec.Handle     // codec handle
 //   var handle codec.Handle     // codec handle
 //   var conn io.ReadWriteCloser // connection got from a socket
 //   var conn io.ReadWriteCloser // connection got from a socket
 //   var bufconn = struct {      // bufconn here is a buffered io.ReadWriteCloser
 //   var bufconn = struct {      // bufconn here is a buffered io.ReadWriteCloser

+ 18 - 10
codec/simple.go

@@ -232,13 +232,17 @@ func (d *simpleDecDriver) ContainerType() (vt valueType) {
 	switch d.bd {
 	switch d.bd {
 	case simpleVdNil:
 	case simpleVdNil:
 		return valueTypeNil
 		return valueTypeNil
-	case simpleVdByteArray, simpleVdByteArray + 1, simpleVdByteArray + 2, simpleVdByteArray + 3, simpleVdByteArray + 4:
+	case simpleVdByteArray, simpleVdByteArray + 1,
+		simpleVdByteArray + 2, simpleVdByteArray + 3, simpleVdByteArray + 4:
 		return valueTypeBytes
 		return valueTypeBytes
-	case simpleVdString, simpleVdString + 1, simpleVdString + 2, simpleVdString + 3, simpleVdString + 4:
+	case simpleVdString, simpleVdString + 1,
+		simpleVdString + 2, simpleVdString + 3, simpleVdString + 4:
 		return valueTypeString
 		return valueTypeString
-	case simpleVdArray, simpleVdArray + 1, simpleVdArray + 2, simpleVdArray + 3, simpleVdArray + 4:
+	case simpleVdArray, simpleVdArray + 1,
+		simpleVdArray + 2, simpleVdArray + 3, simpleVdArray + 4:
 		return valueTypeArray
 		return valueTypeArray
-	case simpleVdMap, simpleVdMap + 1, simpleVdMap + 2, simpleVdMap + 3, simpleVdMap + 4:
+	case simpleVdMap, simpleVdMap + 1,
+		simpleVdMap + 2, simpleVdMap + 3, simpleVdMap + 4:
 		return valueTypeMap
 		return valueTypeMap
 		// case simpleVdTime:
 		// case simpleVdTime:
 		// 	return valueTypeTime
 		// 	return valueTypeTime
@@ -286,7 +290,7 @@ func (d *simpleDecDriver) decCheckInteger() (ui uint64, neg bool) {
 		ui = uint64(bigen.Uint64(d.r.readx(8)))
 		ui = uint64(bigen.Uint64(d.r.readx(8)))
 		neg = true
 		neg = true
 	default:
 	default:
-		d.d.errorf("decIntAny: Integer only valid from pos/neg integer1..8. Invalid descriptor: %v", d.bd)
+		d.d.errorf("Integer only valid from pos/neg integer1..8. Invalid descriptor: %v", d.bd)
 		return
 		return
 	}
 	}
 	// don't do this check, because callers may only want the unsigned value.
 	// don't do this check, because callers may only want the unsigned value.
@@ -506,10 +510,11 @@ func (d *simpleDecDriver) decodeExtV(verifyTag bool, tag byte) (xtag byte, xbs [
 			return
 			return
 		}
 		}
 		xbs = d.r.readx(l)
 		xbs = d.r.readx(l)
-	case simpleVdByteArray, simpleVdByteArray + 1, simpleVdByteArray + 2, simpleVdByteArray + 3, simpleVdByteArray + 4:
+	case simpleVdByteArray, simpleVdByteArray + 1,
+		simpleVdByteArray + 2, simpleVdByteArray + 3, simpleVdByteArray + 4:
 		xbs = d.DecodeBytes(nil, true)
 		xbs = d.DecodeBytes(nil, true)
 	default:
 	default:
-		d.d.errorf("Invalid descriptor for extensions (Expecting extensions or byte array). Got: 0x%x", d.bd)
+		d.d.errorf("Invalid descriptor - expecting extensions/bytearray, got: 0x%x", d.bd)
 		return
 		return
 	}
 	}
 	d.bdRead = false
 	d.bdRead = false
@@ -553,10 +558,12 @@ func (d *simpleDecDriver) DecodeNaked() {
 	case simpleVdTime:
 	case simpleVdTime:
 		n.v = valueTypeTime
 		n.v = valueTypeTime
 		n.t = d.DecodeTime()
 		n.t = d.DecodeTime()
-	case simpleVdString, simpleVdString + 1, simpleVdString + 2, simpleVdString + 3, simpleVdString + 4:
+	case simpleVdString, simpleVdString + 1,
+		simpleVdString + 2, simpleVdString + 3, simpleVdString + 4:
 		n.v = valueTypeString
 		n.v = valueTypeString
 		n.s = d.DecodeString()
 		n.s = d.DecodeString()
-	case simpleVdByteArray, simpleVdByteArray + 1, simpleVdByteArray + 2, simpleVdByteArray + 3, simpleVdByteArray + 4:
+	case simpleVdByteArray, simpleVdByteArray + 1,
+		simpleVdByteArray + 2, simpleVdByteArray + 3, simpleVdByteArray + 4:
 		n.v = valueTypeBytes
 		n.v = valueTypeBytes
 		n.l = d.DecodeBytes(nil, false)
 		n.l = d.DecodeBytes(nil, false)
 	case simpleVdExt, simpleVdExt + 1, simpleVdExt + 2, simpleVdExt + 3, simpleVdExt + 4:
 	case simpleVdExt, simpleVdExt + 1, simpleVdExt + 2, simpleVdExt + 3, simpleVdExt + 4:
@@ -564,7 +571,8 @@ func (d *simpleDecDriver) DecodeNaked() {
 		l := d.decLen()
 		l := d.decLen()
 		n.u = uint64(d.r.readn1())
 		n.u = uint64(d.r.readn1())
 		n.l = d.r.readx(l)
 		n.l = d.r.readx(l)
-	case simpleVdArray, simpleVdArray + 1, simpleVdArray + 2, simpleVdArray + 3, simpleVdArray + 4:
+	case simpleVdArray, simpleVdArray + 1, simpleVdArray + 2,
+		simpleVdArray + 3, simpleVdArray + 4:
 		n.v = valueTypeArray
 		n.v = valueTypeArray
 		decodeFurther = true
 		decodeFurther = true
 	case simpleVdMap, simpleVdMap + 1, simpleVdMap + 2, simpleVdMap + 3, simpleVdMap + 4:
 	case simpleVdMap, simpleVdMap + 1, simpleVdMap + 2, simpleVdMap + 3, simpleVdMap + 4: