Data-FastPack

 view release on metacpan or  search on metacpan

lib/Data/FastPack.pm  view on Meta::CPAN

package Data::FastPack;
use strict;
use warnings;

our $VERSION="v0.3.0";

use feature ":all";
no warnings "experimental";
use Export::These qw<decode_fastpack encode_fastpack decode_message encode_message create_namespace name_for_id id_for_name FP_MSG_TIME FP_MSG_ID FP_MSG_PAYLOAD FP_MSG_TOTAL_LEN>;



use constant::more <FP_MSG_{TIME=0,ID,PAYLOAD,TOTAL_LEN}>;

use constant::more <FP_NS_{ID=0,SPACE,PARENT,NAME,USER}>;
use constant::more qw<N2E=0 I2E NEXT_ID FREE_ID>;

use constant::more DEBUG=>0;

# routine indicating the required size of a buffer to store the requested
# payload length
#
sub size_message {
  my $payload_size=shift;
		my$padding=($payload_size%8);
    $padding= 8-$padding  if $padding;

    #return the total length of the head, payload and padding
    16+$payload_size+$padding;
}

#passing arrays of arrays, [time, info, payload] Computes padding, appends
#the serialized data to the supplied buffer, and sets the length.  If id
#has MORE bit set, at least one more messags to follow (at some point).
#$buf, [$time, $id, $data]
#
my $pbuf= pack "x8";


=over 

=item encode_message

=item encode_fastpack

Encodes an array of fast pack message structures into an buffer

Buffer is aliased and is an in/out parameter. Encoded data is appended to the buffer.

Inputs is an array of message structure (also array refs). Array is consumed 

An optional limit can be sepecified on how many messages to encode in a single call

Returns the number of bytes encoded


=back

=cut

my @_ids;  #original name cache
my $i;

sub encode_message;
sub encode_message {
  \my $buf=\$_[0]; shift;
  my $inputs=shift;



( run in 1.365 second using v1.01-cache-2.11-cpan-39bf76dae61 )