|
From: Sam S. <sd...@gn...> - 2005-06-06 18:13:51
|
> * Bruno Haible <oe...@py...> [2005-05-30 14:47:28 +0200]:
>
> Sam wrote:
>> >> 1. I_to_LEbytes() interface is counterintuitive: the size argument is
>> >> the bit size of the object (which can be computed by I_to_LEbytes() -
>> >> actually, it must be 1+I_integer_length(obj) for positive obj!),
>> >
>> > The I_to_LEbytes() interface is made for the cases where you know in
>> > advance the maximum size of the integers
>>
>> no, I have no idea about the maximum size of the integers.
>> ...
>> I want to be able to simply do
>>
>> byte buffer[64];
>> I_to_LEbytes(fixnum(7),buffer,64);
>
> Where do you know that a buffer of size 64 will be sufficient, if
> you don't know about the maximum size of the integers?
I don't - I want I_to_LEbytes() to find that out and return an error
code if the buffer space is insufficient.
>> suppose I have fixed size records in the database, e.g., 64 bytes.
>> suppose I want to write number 7 (3 bits) there.
>> right now I have to do this:
>>
>> byte buffer[64];
>> memset(buffer,0,64);
>> I_to_LEbytes(fixnum(7),1+I_integer_length(fixnum(7)),buffer,64);
>>
>> I want to be able to simply do
>>
>> byte buffer[64];
>> I_to_LEbytes(fixnum(7),buffer,64);
>
> The current interface allows you to do this through
>
> byte buffer[64];
> I_to_LEbytes(fixnum(7),8*64,buffer);
if you remove memset() from modules/berkeley-db/bdb.c:fill_dbt(), the
tests will fail.
> Which is - except for the multiplication by 8 - exactly what you are
> asking for.
what is "8"?
how do I know it's not "3" or "17"?
>> the normal way to interface with a serializing facility is:
>>
>> int serialize_foo (foo_t object, int buffer_size, byte* buffer);
>> int deserialize_foo (foo_t *object, int buffer_size, byte* buffer);
>> int foo_size (foo_t object);
>>
>> and serialize_foo() should take care of padding.
>
> Yes. This is why I_to_LEbytes()'s implementation ends with a memset.
no I_to_LEbytes does not pad, see the bdb above.
>> the current interface is highly unusual:
>>
>> 1. an extra argument to serialize_foo()
>
> No. It takes the usual 3 arguments: the object, the buffer, and the
> buffer's size.
the size is in the wrong units.
there is no function that returns the size, like foo_size() above.
how do I write
int size = foo_size(x);
byte buf = malloc(size);
serialize_foo(x,size,buf);
>> 2. user has to do the padding, not serialize_foo()
> No.
see above.
if the I_to_LEbytes does padding, it is broken.
--
Sam Steingold (http://www.podval.org/~sds) running w2k
<http://www.mideasttruth.com/> <http://www.openvotingconsortium.org/>
<http://www.jihadwatch.org/> <http://pmw.org.il/>
cogito cogito ergo cogito sum
|