>> No, sorry to be unclear. The get_* methods have to respect the order in
>> which data was placed into the buffer by the put_* methods. So, for example,
>> this is true:
> 
> But what happens if I call the functions out of order?

Then you get incorrect data. Which is, perhaps, not the best way of doing
things, at least all the time. In certain circumstances, though--where both
users of the buffer have agreed upon a certain protocol--it's exactly what
you want. An example is Net::SSH::Perl, which is where this module
originally came from; I just thought it could have general purpose use, so I
broke it out. The idea with Net::SSH::Perl is that the client and server
both *know*--based on the type of the packet sent--what every buffer
contains, and in what order. That's part of the protocol.

So in that case, there's really no need for additional information. But I
can see that it might be nice, at certain times, for the buffer to "know"
what's inside of it.

I could introduce an optional feature that would fill the first couple of
bytes with information about the data contained in the rest of the buffer,
and in what order the data must be retrieved. And then perhaps a 'get_all'
method, which would read the buffer information bytes, then extract
*everything* out of the buffer and return it. Something like this, maybe:

    my $buffer = Data::Buffer->new(info_header => 1);
    $buffer->put_int32(39299);
    $buffer->put_str("foo");

    ... later ...

    my($int32, $str) = $buffer->get_all;

Thoughts?

bye,
Ben

Reply via email to