diff --git a/README.md b/README.md index c4b6209b8b..7a00c3a6a9 100644 --- a/README.md +++ b/README.md @@ -16,8 +16,8 @@ Golang SQL database driver for [Yandex ClickHouse](https://clickhouse.yandex/) * no_delay - disable/enable the Nagle Algorithm for tcp socket (default is 'true' - disable) * alt_hosts - comma separated list of single address host for load-balancing * connection_open_strategy - random/in_order (default random). - * random - always try to open a new connection with a random host - * in_order - use only for failover, host will be chosen by order priority + * random - choose random server from set + * in_order - first live server is choosen in specified order * block_size - maximum rows in block (default is 1000000). If the rows are larger then the data will be split into several blocks to send them to the server * debug - enable debug output (boolean value) diff --git a/lib/binary/decoder.go b/lib/binary/decoder.go index 3df2304b1e..736caabfc4 100644 --- a/lib/binary/decoder.go +++ b/lib/binary/decoder.go @@ -14,7 +14,7 @@ func NewDecoder(input io.Reader) *Decoder { type Decoder struct { input io.Reader - scratch [16]byte + scratch [binary.MaxVarintLen64]byte } func (decoder *Decoder) Bool() (bool, error) { @@ -70,28 +70,34 @@ func (decoder *Decoder) UInt8() (uint8, error) { } func (decoder *Decoder) UInt16() (uint16, error) { - buf := decoder.scratch[:2] - if _, err := decoder.input.Read(buf); err != nil { + if _, err := decoder.input.Read(decoder.scratch[:2]); err != nil { return 0, err } - return uint16(buf[0]) | uint16(buf[1])<<8, nil + return uint16(decoder.scratch[0]) | uint16(decoder.scratch[1])<<8, nil } func (decoder *Decoder) UInt32() (uint32, error) { - buf := decoder.scratch[:4] - if _, err := decoder.input.Read(buf); err != nil { + if _, err := decoder.input.Read(decoder.scratch[:4]); err != nil { return 0, err } - return uint32(buf[0]) | uint32(buf[1])<<8 | uint32(buf[2])<<16 | uint32(buf[3])<<24, nil + return uint32(decoder.scratch[0]) | + uint32(decoder.scratch[1])<<8 | + uint32(decoder.scratch[2])<<16 | + uint32(decoder.scratch[3])<<24, nil } func (decoder *Decoder) UInt64() (uint64, error) { - buf := decoder.scratch[:8] - if _, err := decoder.input.Read(buf); err != nil { + if _, err := decoder.input.Read(decoder.scratch[:8]); err != nil { return 0, err } - return uint64(buf[0]) | uint64(buf[1])<<8 | uint64(buf[2])<<16 | uint64(buf[3])<<24 | - uint64(buf[4])<<32 | uint64(buf[5])<<40 | uint64(buf[6])<<48 | uint64(buf[7])<<56, nil + return uint64(decoder.scratch[0]) | + uint64(decoder.scratch[1])<<8 | + uint64(decoder.scratch[2])<<16 | + uint64(decoder.scratch[3])<<24 | + uint64(decoder.scratch[4])<<32 | + uint64(decoder.scratch[5])<<40 | + uint64(decoder.scratch[6])<<48 | + uint64(decoder.scratch[7])<<56, nil } func (decoder *Decoder) Float32() (float32, error) { diff --git a/lib/binary/encoder.go b/lib/binary/encoder.go index c510cbc7f6..101304094f 100644 --- a/lib/binary/encoder.go +++ b/lib/binary/encoder.go @@ -16,7 +16,7 @@ func NewEncoder(output io.Writer) *Encoder { type Encoder struct { output io.Writer - scratch [16]byte + scratch [binary.MaxVarintLen64]byte } func (enc *Encoder) Uvarint(v uint64) error {