diff options
author | Ugorji Nwoke <ugorji@gmail.com> | 2013-08-07 14:27:29 -0400 |
---|---|---|
committer | Ugorji Nwoke <ugorji@gmail.com> | 2013-08-07 14:27:29 -0400 |
commit | 8f3b3ef7412a6a4a2daac4f873be81549aab7913 (patch) | |
tree | 16e3508514c63577052a2e8f41c6522f8e84eb94 /codec/time.go | |
parent | 70872afeb4c51351ff12bb63d9605105fd76cd6c (diff) |
codec: remove buffering from encoder/decoder. Add buffering to rpc. fix binc floatZero bug.
This codec library does not internally do buffering during encode or decode, leaving
that to the caller of the NewEncoder or NewDecoder function to pass a buffered stream
if desired.
However, RPC owns the connection and is the caller of the NewEncoder/NewDecoder. The RPC
support now internally passes buffered streams to the NewEncoder/NewDecoder calls.
Fixes #9 .
In addition, there was a floatZero bug in binc, where floats with zero value could
mess up the decoder state. This is now fixed.
Diffstat (limited to 'codec/time.go')
-rw-r--r-- | codec/time.go | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/codec/time.go b/codec/time.go index 05c45b3..90a4010 100644 --- a/codec/time.go +++ b/codec/time.go @@ -8,8 +8,7 @@ import ( ) var ( - timeBs0xff = []byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff} - digits = [...]byte{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'} + timeDigits = [...]byte{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'} ) // encodeTime encodes a time.Time as a []byte, including @@ -79,7 +78,7 @@ func decodeTime(bs []byte) (tt time.Time, err error) { copy(btmp[8-n:], bs[i:i2]) //if first bit of bs[i] is set, then fill btmp[0..8-n] with 0xff (ie sign extend it) if bs[i] & (1 << 7) != 0 { - copy(btmp[0:8-n], timeBs0xff) + copy(btmp[0:8-n], bsAll0xff) //for j,k := byte(0), 8-n; j < k; j++ { btmp[j] = 0xff } } i = i2 @@ -122,10 +121,10 @@ func decodeTime(bs []byte) (tt time.Time, err error) { } else { tzhr, tzmin = tzint/60, tzint%60 } - tzname[4] = digits[tzhr/10] - tzname[5] = digits[tzhr%10] - tzname[7] = digits[tzmin/10] - tzname[8] = digits[tzmin%10] + tzname[4] = timeDigits[tzhr/10] + tzname[5] = timeDigits[tzhr%10] + tzname[7] = timeDigits[tzmin/10] + tzname[8] = timeDigits[tzmin%10] tt = time.Unix(tsec, int64(tnsec)).In(time.FixedZone(string(tzname), int(tzint)*60)) return |