wire

package
v1.0.15 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 28, 2023 License: MIT Imports: 13 Imported by: 3

Documentation

Index

Constants

View Source
const (
	ByteSize    = 1
	ShortSize   = 2
	IntegerSize = 4
	LongSize    = 8
)

integer sizes

View Source
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

func NewDecoder(src io.Reader) *Decoder

NewDecoder returns a new Decoder that decods values read from src

func (*Decoder) Byte

func (d *Decoder) Byte() (int8, error)

Byte reads and decodes voltdb wire protocol encoded []byte to int8.

func (*Decoder) Float64

func (d *Decoder) Float64() (float64, error)

Float64 reads and decodes voltdb wire protocol encoded []byte to float64.

func (*Decoder) Int16

func (d *Decoder) Int16() (int16, error)

Int16 reads and decodes voltdb wire protocol encoded []byte to int16.

func (*Decoder) Int32

func (d *Decoder) Int32() (int32, error)

Int32 reads and decodes voltdb wire protocol encoded []byte to int32.

func (*Decoder) Int64

func (d *Decoder) Int64() (int64, error)

Int64 reads and decodes voltdb wire protocol encoded []byte to int64.

func (*Decoder) Login

func (d *Decoder) Login() (*ConnInfo, error)

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) LoginInfo

func (d *Decoder) LoginInfo() (*ConnInfo, error)

LoginInfo decodes login message.

func (*Decoder) Message

func (d *Decoder) Message() ([]byte, error)

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

func (d *Decoder) MessageHeader() (int32, error)

MessageHeader reads an int32 value representing the size of the encoded message body.

func (*Decoder) Read

func (d *Decoder) Read(b []byte) (int, error)

Read implements io.Reader

func (*Decoder) Reset

func (d *Decoder) Reset()

Reset clears the underlying io.Reader . This sets the reader to nil.

func (*Decoder) SetReader

func (d *Decoder) SetReader(r io.Reader)

SetReader replaces the underlying reader, next call to Decode methods will read from this

func (*Decoder) String

func (d *Decoder) String() (string, error)

String reads and decodes voltdb wire protocol encoded []byte to string.

func (*Decoder) StringSlice

func (d *Decoder) StringSlice() ([]string, error)

StringSlice reads and decodes voltdb wire protocol encoded []byte to []string.

func (*Decoder) Time

func (d *Decoder) Time() (time.Time, error)

Time reads and decodes voltdb wire protocol encoded []byte to time.Time.

func (*Decoder) Uint16

func (d *Decoder) Uint16() (uint16, error)

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

func (d *Decoder) Uint32() (uint32, error)

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

func (*Decoder) Uint64

func (d *Decoder) Uint64() (uint64, error)

Uint64 reads and decodes voltdb wire protocol encoded []byte into uint64.

This reads 8 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 uint64 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

func NewDecoderAt(r io.ReaderAt) *DecoderAt

NewDecoderAt retruns new DecoderAt instance that is reading from r.

func (*DecoderAt) ByteAt

func (d *DecoderAt) ByteAt(offset int64) (byte, error)

ByteAt decodes voltdb wire protocol encoded []byte read from the given offset to int8.

func (*DecoderAt) ByteSliceAt

func (d *DecoderAt) ByteSliceAt(offset int64) ([]byte, error)

ByteSliceAt decodes voltdb wire protocol encoded []byte read from the given offset to []byte.

func (*DecoderAt) Float64At

func (d *DecoderAt) Float64At(offset int64) (float64, error)

Float64At decodes voltdb wire protocol encoded []byte read from the given offset to float64.

func (*DecoderAt) Int16At

func (d *DecoderAt) Int16At(offset int64) (int16, error)

Int16At decodes voltdb wire protocol encoded []byte read from the given offset to int16.

func (*DecoderAt) Int32At

func (d *DecoderAt) Int32At(offset int64) (int32, error)

Int32At decodes voltdb wire protocol encoded []byte read from the given offset to int32.

func (*DecoderAt) Int64At

func (d *DecoderAt) Int64At(offset int64) (int64, error)

Int64At decodes voltdb wire protocol encoded []byte read from the given offset to int64.

func (*DecoderAt) SetReaderAt

func (d *DecoderAt) SetReaderAt(r io.ReaderAt)

SetReaderAt changes the underlying io.ReaderAt to r. Any next call on the *Decoder methods will read from r.

func (*DecoderAt) StringAt

func (d *DecoderAt) StringAt(offset int64) (string, error)

StringAt decodes voltdb wire protocol encoded []byte read from the given offset to string.

func (*DecoderAt) Uint16At

func (d *DecoderAt) Uint16At(offset int64) (uint16, error)

Uint16At decodes voltdb wire protocol encoded []byte read from the given offset to uint16.

func (*DecoderAt) Uint32At

func (d *DecoderAt) Uint32At(offset int64) (uint32, error)

Uint32At decodes voltdb wire protocol encoded []byte read from the given offset to uint32.

func (*DecoderAt) Uint64At

func (d *DecoderAt) Uint64At(offset int64) (uint64, error)

Uint64At decodes voltdb wire protocol encoded []byte read from the given offset to uint64.

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 NewEncoder

func NewEncoder() *Encoder

NewEncoder returns a new Encoder instance

func (*Encoder) Args

func (e *Encoder) Args(v []driver.Value) error

Args a helper to encode driver arguments

func (*Encoder) Binary

func (e *Encoder) Binary(v []byte) (int, error)

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) Bool

func (e *Encoder) Bool(v bool) (int, error)

Bool encodes bool values to voltdb wireprotocol boolean

func (*Encoder) Byte

func (e *Encoder) Byte(v int8) (int, error)

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) Bytes

func (e *Encoder) Bytes() []byte

Bytes returns the buffered voltdb wire protocol encoded bytes

func (*Encoder) Float64

func (e *Encoder) Float64(v float64) (int, error)

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) Int added in v1.0.3

func (e *Encoder) Int(v int) (int, error)

func (*Encoder) Int16

func (e *Encoder) Int16(v int16) (int, error)

Int16 encodes int16 value to voltdb wire protocol Short. For a successful encoding the number of bytes written is 2

func (*Encoder) Int32

func (e *Encoder) Int32(v int32) (int, error)

Int32 encodes int32 value to voltdb wire protocol Integer. For a successful encoding the number of bytes written is 4

func (*Encoder) Int64

func (e *Encoder) Int64(v int64) (int, error)

Int64 encodes int64 value into voltdb wire protocol Long. For a successful encoding the number of bytes written is 8

func (*Encoder) Len

func (e *Encoder) Len() int

Len retuns the size of the cueent encoded values

func (*Encoder) Login

func (e *Encoder) Login(version int, user, password string) ([]byte, error)

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

func (e *Encoder) Marshal(v interface{}) (int, error)

Marshal encodes query arguments, these are values passed as driver.Value when executing queries

func (*Encoder) MarshalBool

func (e *Encoder) MarshalBool(v bool) (int, error)

MarshalBool encodes boolean argument

func (*Encoder) MarshalByte

func (e *Encoder) MarshalByte(v int8) (int, error)

MarshalByte encodes int8 argument

func (*Encoder) MarshalFloat64

func (e *Encoder) MarshalFloat64(v float64) (int, error)

MarshalFloat64 encodes float64 argument

func (*Encoder) MarshalInt added in v1.0.3

func (e *Encoder) MarshalInt(v int) (int, error)

MarshalInt encodes int argument

func (*Encoder) MarshalInt32

func (e *Encoder) MarshalInt32(v int32) (int, error)

MarshalInt32 encodes int32 argument

func (*Encoder) MarshalInt64

func (e *Encoder) MarshalInt64(v int64) (int, error)

MarshalInt64 encodes int64 argument

func (*Encoder) MarshalNil added in v1.0.3

func (e *Encoder) MarshalNil() (int, error)

MarshalNil encodes nil

func (*Encoder) MarshalShort

func (e *Encoder) MarshalShort(v int16) (int, error)

MarshalShort encodes int16 argument

func (*Encoder) MarshalSlice

func (e *Encoder) MarshalSlice(v reflect.Value) (int, error)

MarshalSlice encodes slice of arguments

func (*Encoder) MarshalString

func (e *Encoder) MarshalString(v string) (int, error)

MarshalString encodes string argument

func (*Encoder) MarshalTime

func (e *Encoder) MarshalTime(v time.Time) (int, error)

MarshalTime encodes time.Time argument

func (*Encoder) Message

func (e *Encoder) Message(v []byte) []byte

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) Read

func (e *Encoder) Read(b []byte) (int, error)

Read implements io.Reader interface

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

func (e *Encoder) String(v string) (int, error)

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.

func (*Encoder) Time

func (e *Encoder) Time(v time.Time) (int, error)

Time encodes time.Time value to voltdb wire protocol time.

func (*Encoder) Write

func (e *Encoder) Write(b []byte) (int, error)

Write implements io.Writer interface

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL