NAME

Kafka::Int64 - Functions to work with 64 bit elements of the protocol on 32 bit systems.

VERSION

This documentation refers to Kafka::Int64 version 1.08 .

SYNOPSIS

use 5.010;
use strict;
use warnings;

use Scalar::Util qw(
    blessed
);
use Try::Tiny;

use Kafka qw(
    $BITS64
);

try {

    # Apache Kafka Protocol: FetchOffset, Time

    my $offset = 123;

    my $encoded = $BITS64
        ? pack( 'q>', $offset )
        : Kafka::Int64::packq( $offset );

    my $response = chr( 0 ) x 8;

    $offset = $BITS64
        ? unpack( 'q>', substr( $response, 0, 8 ) )
        : Kafka::Int64::unpackq( substr( $response, 0, 8 ) );

    my $next_offset = $BITS64
        ? $offset + 1
        : Kafka::Int64::intsum( $offset, 1 );

} catch {
    my $error = $_;
    if ( blessed( $error ) && $error->isa( 'Kafka::Exception' ) ) {
        warn 'Error: (', $error->code, ') ',  $error->message, "\n";
        exit;
    } else {
        die $error;
    }
};

DESCRIPTION

This module is not intended to be used by end user.

In order to achieve better performance, functions of this module do not perform validation of arguments.

Transparent BigInteger support on 32-bit platforms where native integer type is limited to 32 bits and slow bigint must be used instead. Use functions from this module in such case.

The main features of the Kafka::Int64 module are:

  • Support for working with 64 bit elements of the Kafka protocol on 32 bit systems.

FUNCTIONS

The following functions are available for the Kafka::Int64 module.

intsum( $bint, $int )

Adds two numbers to emulate bigint adding 64-bit integers in 32-bit systems.

The both arguments must be a number. That is, it is defined and Perl thinks it's a number. Arguments may be a Math::BigInt integers.

Returns the value as a Math::BigInt integer.

packq( $bint )

Emulates pack( q{q>}, $bint ) to 32-bit systems - assumes decimal string or integer input.

An argument must be a positive number. That is, it is defined and Perl thinks it's a number. The argument may be a Math::BigInt integer.

The special values -1, -2 are allowed ($Kafka::RECEIVE_LATEST_OFFSET, $Kafka::RECEIVE_EARLIEST_OFFSETS).

Returns the value as a packed binary string.

unpackq( $bstr )

Emulates unpack( q{q>}, $bstr ) to 32-bit systems - assumes binary input.

The argument must be a binary string of 8 bytes length.

Returns the value as a Math::BigInt integer.

DIAGNOSTICS

When error is detected, an exception, represented by object of Kafka::Exception::Int64 class, is thrown (see Kafka::Exceptions).

Any error functions is FATAL. FATAL errors will cause the program to halt (confess), since the problem is so severe that it would be dangerous to continue.

code and a more descriptive message provide information about thrown exception. Consult documentation of the Kafka::Exceptions for the list of all available methods.

Authors suggest using of Try::Tiny's try and catch to handle exceptions while working with Kafka package.

Invalid argument

This means that you didn't give the right argument to some of the functions.

SEE ALSO

The basic operation of the Kafka package modules:

Kafka - constants and messages used by the Kafka package modules.

Kafka::Connection - interface to connect to a Kafka cluster.

Kafka::Producer - interface for producing client.

Kafka::Consumer - interface for consuming client.

Kafka::Message - interface to access Kafka message properties.

Kafka::Int64 - functions to work with 64 bit elements of the protocol on 32 bit systems.

Kafka::Protocol - functions to process messages in the Apache Kafka's Protocol.

Kafka::IO - low-level interface for communication with Kafka server.

Kafka::Exceptions - module designated to handle Kafka exceptions.

Kafka::Internals - internal constants and functions used by several package modules.

A wealth of detail about the Apache Kafka and the Kafka Protocol:

Main page at http://kafka.apache.org/

Kafka Protocol at https://cwiki.apache.org/confluence/display/KAFKA/A+Guide+To+The+Kafka+Protocol

SOURCE CODE

Kafka package is hosted on GitHub: https://github.com/TrackingSoft/Kafka

AUTHOR

Sergey Gladkov

Please use GitHub project link above to report problems or contact authors.

CONTRIBUTORS

Alexander Solovey

Jeremy Jordan

Sergiy Zuban

Vlad Marchenko

COPYRIGHT AND LICENSE

Copyright (C) 2012-2017 by TrackingSoft LLC.

This package is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic at http://dev.perl.org/licenses/artistic.html.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.