Documentation
¶
Index ¶
- Constants
- type ConnInfo
- type Decoder
- func (d *Decoder) Byte() (int8, error)
- func (d *Decoder) Float64() (float64, error)
- func (d *Decoder) Int16() (int16, error)
- func (d *Decoder) Int32() (int32, error)
- func (d *Decoder) Int64() (int64, error)
- func (d *Decoder) Login() (*ConnInfo, error)
- func (d *Decoder) LoginInfo() (*ConnInfo, error)
- func (d *Decoder) Message() ([]byte, error)
- func (d *Decoder) MessageHeader() (int32, error)
- func (d *Decoder) Read(b []byte) (int, error)
- func (d *Decoder) Reset()
- func (d *Decoder) SetReader(r io.Reader)
- func (d *Decoder) String() (string, error)
- func (d *Decoder) StringSlice() ([]string, error)
- func (d *Decoder) Time() (time.Time, error)
- func (d *Decoder) Uint16() (uint16, error)
- func (d *Decoder) Uint32() (uint32, error)
- func (d *Decoder) Uint64() (uint64, error)
- type DecoderAt
- func (d *DecoderAt) ByteAt(offset int64) (byte, error)
- func (d *DecoderAt) ByteSliceAt(offset int64) ([]byte, error)
- func (d *DecoderAt) Float64At(offset int64) (float64, error)
- func (d *DecoderAt) Int16At(offset int64) (int16, error)
- func (d *DecoderAt) Int32At(offset int64) (int32, error)
- func (d *DecoderAt) Int64At(offset int64) (int64, error)
- func (d *DecoderAt) SetReaderAt(r io.ReaderAt)
- func (d *DecoderAt) StringAt(offset int64) (string, error)
- func (d *DecoderAt) Uint16At(offset int64) (uint16, error)
- func (d *DecoderAt) Uint32At(offset int64) (uint32, error)
- func (d *DecoderAt) Uint64At(offset int64) (uint64, error)
- type Encoder
- func (e *Encoder) Args(v []driver.Value) error
- func (e *Encoder) Binary(v []byte) (int, error)
- func (e *Encoder) Bool(v bool) (int, error)
- func (e *Encoder) Byte(v int8) (int, error)
- func (e *Encoder) Bytes() []byte
- func (e *Encoder) Float64(v float64) (int, error)
- func (e *Encoder) Int(v int) (int, error)
- func (e *Encoder) Int16(v int16) (int, error)
- func (e *Encoder) Int32(v int32) (int, error)
- func (e *Encoder) Int64(v int64) (int, error)
- func (e *Encoder) Len() int
- func (e *Encoder) Login(version int, user, password string) ([]byte, error)
- func (e *Encoder) Marshal(v interface{}) (int, error)
- func (e *Encoder) MarshalBool(v bool) (int, error)
- func (e *Encoder) MarshalByte(v int8) (int, error)
- func (e *Encoder) MarshalFloat64(v float64) (int, error)
- func (e *Encoder) MarshalInt(v int) (int, error)
- func (e *Encoder) MarshalInt32(v int32) (int, error)
- func (e *Encoder) MarshalInt64(v int64) (int, error)
- func (e *Encoder) MarshalNil() (int, error)
- func (e *Encoder) MarshalShort(v int16) (int, error)
- func (e *Encoder) MarshalSlice(v reflect.Value) (int, error)
- func (e *Encoder) MarshalString(v string) (int, error)
- func (e *Encoder) MarshalTime(v time.Time) (int, error)
- func (e *Encoder) Message(v []byte) []byte
- func (e *Encoder) Read(b []byte) (int, error)
- func (e *Encoder) Reset()
- func (e *Encoder) String(v string) (int, error)
- func (e *Encoder) Time(v time.Time) (int, error)
- func (e *Encoder) Write(b []byte) (int, error)
Constants ¶
const ( ByteSize = 1 ShortSize = 2 IntegerSize = 4 LongSize = 8 )
integer sizes
const ( ArrayColumn int8 = -99 // array (short)(values*) NullColumn int8 = 1 // null BoolColumn int8 = 3 // boolean ByteColumn int8 = 3 // byte ShortColumn int8 = 4 // int16 IntColumn int8 = 5 // int32 LongColumn int8 = 6 // int64 FloatColumn int8 = 8 // float64 StringColumn int8 = 9 // string (int32-length-prefix)(utf-8 bytes) TimestampColumn int8 = 11 // int64 timestamp microseconds Table int8 = 21 // VoltTable DecimalColumn int8 = 22 // fix-scaled, fix-precision decimal VarBinColumn int8 = 25 // varbinary (int)(bytes) )
Column types
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConnInfo ¶
type ConnInfo struct { // HostID is the host ID of the volt node HostID int32 // Connection unique id for the connection in the current volt node Connection int64 // Time in which the cluster was started ClusterStart time.Time // IPV4 address of the leader node LeaderAddr struct { Value int32 IP net.IP } // Representation of the build of the connected node Build string }
ConnInfo contains information about the database connection. This is returned from the database on a successful login.
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
Decoder is voltdb wire protocol decoder
func NewDecoder ¶
NewDecoder returns a new Decoder that decods values read from src
func (*Decoder) Login ¶
Login decodes response message received after successful logging to a voltdb database.
The response is first decoded for voltdb wire protocol message i.e first we read an int32 value to know the size of the encoded response, then we read the next n bytes where n is the size of the message.
The message is then decoded to *ConnInfo by calling (*Decoder).LoginInfo.
func (*Decoder) Message ¶
Message reads a voltdb wire protocol encoded message block from the underlying io.Reader.
A message is represented as, a message header followed by the message body. The message header is an int32 value dictacting the size of the message i.e how many bytes the message body occupies. The message body is the next n bytes after the message header where n is the value of the message header.
func (*Decoder) MessageHeader ¶
MessageHeader reads an int32 value representing the size of the encoded message body.
func (*Decoder) Reset ¶
func (d *Decoder) Reset()
Reset clears the underlying io.Reader . This sets the reader to nil.
func (*Decoder) SetReader ¶
SetReader replaces the underlying reader, next call to Decode methods will read from this
func (*Decoder) StringSlice ¶
StringSlice reads and decodes voltdb wire protocol encoded []byte to []string.
func (*Decoder) Uint16 ¶
Uint16 reads and decodes voltdb wire protocol encoded []byte into uint16.
This reads 2 bytes from the the underlying io.Reader, assuming the io.Reader is for voltdb wire protocol encoded bytes stream. Then the bytes read are decoded as uint16 using big endianess
func (*Decoder) Uint32 ¶
Uint32 reads and decodes voltdb wire protocol encoded []byte into uint32.
This reads 4 bytes from the the underlying io.Reader, assuming the io.Reader is for voltdb wire protocol encoded bytes stream. Then the bytes read are decoded as uint32 using big endianess
type DecoderAt ¶
type DecoderAt struct {
// contains filtered or unexported fields
}
DecoderAt is like Decoder but accepts additional offset that is used to determine where to read on the underlying io.ReaderAt
func NewDecoderAt ¶
NewDecoderAt retruns new DecoderAt instance that is reading from r.
func (*DecoderAt) ByteAt ¶
ByteAt decodes voltdb wire protocol encoded []byte read from the given offset to int8.
func (*DecoderAt) ByteSliceAt ¶
ByteSliceAt decodes voltdb wire protocol encoded []byte read from the given offset to []byte.
func (*DecoderAt) Float64At ¶
Float64At decodes voltdb wire protocol encoded []byte read from the given offset to float64.
func (*DecoderAt) Int16At ¶
Int16At decodes voltdb wire protocol encoded []byte read from the given offset to int16.
func (*DecoderAt) Int32At ¶
Int32At decodes voltdb wire protocol encoded []byte read from the given offset to int32.
func (*DecoderAt) Int64At ¶
Int64At decodes voltdb wire protocol encoded []byte read from the given offset to int64.
func (*DecoderAt) SetReaderAt ¶
SetReaderAt changes the underlying io.ReaderAt to r. Any next call on the *Decoder methods will read from r.
func (*DecoderAt) StringAt ¶
StringAt decodes voltdb wire protocol encoded []byte read from the given offset to string.
func (*DecoderAt) Uint16At ¶
Uint16At decodes voltdb wire protocol encoded []byte read from the given offset to uint16.
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
Encoder defines methods for encoding Go values to voltdb wire protocol. This struct is reusable, you can call Reset method and start encodeing new fresh values.
Values are encoded in Big Endian byte order mark.
To retrieve []byte of the encoded values use Bytes method.
func (*Encoder) Binary ¶
Binary encodes []byte to voltdb wire protocol varbinary
This first encodes the size of v as voltdb Integer followed by raw bytes of v.
func (*Encoder) Byte ¶
Byte encodes int8 value to voltdb wire protocol Byte. This returns the number of bytes written and an error if any.
For a successful encoding the value of number of bytes written is 1
func (*Encoder) Float64 ¶
Float64 encodes float64 value to voltdb wire protocol float type. This uses math.Float64bits to covert v to uint64 which is encoded into []byte of size 8. For a successful encoding the number of bytes written is 8
func (*Encoder) Int16 ¶
Int16 encodes int16 value to voltdb wire protocol Short. For a successful encoding the number of bytes written is 2
func (*Encoder) Int32 ¶
Int32 encodes int32 value to voltdb wire protocol Integer. For a successful encoding the number of bytes written is 4
func (*Encoder) Int64 ¶
Int64 encodes int64 value into voltdb wire protocol Long. For a successful encoding the number of bytes written is 8
func (*Encoder) Login ¶
Login encodes login details. This supports both version 0 and 1 of the wire protocol.
The password is hashed using sha1 and sha356 for version 0 and 1 respectively.
For instance if the username is foo and password is bar, the login message will be encoded as follows
version 0
+------------------+--------------+-----------------------+----------+--------------------------------------+ | protocol version | service name | password hash version | username | password | +------------------+--------------+-----------------------+----------+--------------------------------------+ | 0 | database | 0 | foo | sha1 encoded raw bytes of string bar | +------------------+--------------+-----------------------+----------+--------------------------------------+
version 1
+------------------+--------------+-----------------------+----------+----------------------------------------+ | protocol version | service name | password hash version | username | password | +------------------+--------------+-----------------------+----------+----------------------------------------+ | 1 | database | 1 | foo | sha256 encoded raw bytes of string bar | +------------------+--------------+-----------------------+----------+----------------------------------------+
func (*Encoder) Marshal ¶
Marshal encodes query arguments, these are values passed as driver.Value when executing queries
func (*Encoder) MarshalBool ¶
MarshalBool encodes boolean argument
func (*Encoder) MarshalByte ¶
MarshalByte encodes int8 argument
func (*Encoder) MarshalFloat64 ¶
MarshalFloat64 encodes float64 argument
func (*Encoder) MarshalInt ¶ added in v1.0.3
MarshalInt encodes int argument
func (*Encoder) MarshalInt32 ¶
MarshalInt32 encodes int32 argument
func (*Encoder) MarshalInt64 ¶
MarshalInt64 encodes int64 argument
func (*Encoder) MarshalNil ¶ added in v1.0.3
MarshalNil encodes nil
func (*Encoder) MarshalShort ¶
MarshalShort encodes int16 argument
func (*Encoder) MarshalSlice ¶
MarshalSlice encodes slice of arguments
func (*Encoder) MarshalString ¶
MarshalString encodes string argument
func (*Encoder) MarshalTime ¶
MarshalTime encodes time.Time argument
func (*Encoder) Message ¶
Message encodes v into a voldb wire protocol. voltdb wire protocol message comprizes of int32 encoded size of v followed by v raw bytes.
func (*Encoder) Reset ¶
func (e *Encoder) Reset()
Reset resets the underlying buffer. This will remove any values that were encoded before.
Call this to reuse the Encoder and avoid unnecessary allocations.
func (*Encoder) String ¶
String encodes strings to voltdb wire protocol string. A string is treated like []byte. We first encode the size of the string, followed by the raw bytes of the string.