NAME

Protocol::Dqlite - Dqlite in Perl

SYNOPSIS

use autodie;

my $dqlite = Protocol::Dqlite->new();

my $socket = IO::Socket::INET->new('127.0.0.1:9001') or die;

syswrite $s, Protocol::Dqlite::handshake();

# Register ourselves as a Dqlite client:
syswrite $s, Protocol::Dqlite::request( Protocol::Dqlite::REQUEST_CLIENT, 0 );

# Await the server’s acknowledgement:
while (sysread $s, my $buf, 512) {
    my ($msg) = $dqlite->feed($buf);
    next if !$msg;

    last if $msg isa Protocol::Dqlite::Response::WELCOME;

    # An unexpected response. Better bail out …
    #
    require Data::Dumper;
    die Data::Dumper::Dumper($msg);
}

… and now you can exchange messages as you wish.

DESCRIPTION

This module implements message parsing and creation for Dqlite clients. To use this module you’ll need to write the I/O logic yourself.

CHARACTER ENCODING

Strings designated as “blob”s are byte strings.

All other strings into & out of this module are character strings.

Decode & encode accordingly.

CONSTANTS

The following derive from the documentation of Dqlite’s wire protocol as well as protocol.h in Dqlite’s source code.

Role Codes

ROLE_VOTER, ROLE_STANDBY, ROLE_SPARE

Tuple Member Types

Request Message Types

Other

STATIC FUNCTIONS

$bytes = request( $TYPE, @ARGUMENTS )

Returns a byte buffer of a Dqlite message. $TYPE is one of the REQUEST_* constants listed above.

@ARGUMENTS are as Dqlite’s wire protocol documentation indicates. Dqlite tuples are expressed as type/value pairs.

Example:

my $bytes = Protocol::Dqlite::request(
    Protocol::Dqlite::REQUEST_PREPARE,
    12,
    "SELECT ?, ?",
    Protocol::Dqlite::TUPLE_INT64 => 12345,
    Protocol::Dqlite::TUPLE_BLOB => "\x00\x01\x02",
);

METHODS

$obj = CLASS->new()

Instantiates CLASS.

@messages = OBJ->feed( $BYTES )

Give new input to OBJ. Returns any messages parsed out of $BYTES as Protocol::Dqlite::Response instances.

RESPONSE CLASSES

All of the below extend Protocol::Dqlite::Response. They expose various accessors as documented below: