|
From: Sam S. <sd...@gn...> - 2005-05-12 17:29:00
|
> * Bruno Haible <oe...@py...> [2005-05-12 18:17:09 +0200]:
>
> Sam wrote:
>> I think we are having a problem with I_to_LEbytes/LEbytes_to_I.
>> (berkeley-db tests fail).
>> The problems boil down to the following issues:
>>
>> 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.
>> not the byte size of the buffer (as for LEbytes_to_I()) which means
>> that the caller has to call memset() or equivalent on the buffer.
>
> Show me a test case where you pass 8*N as 2nd argument to I_to_LEbytes()
> and it does not fill exactly N bytes.
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);
which is simple and symmetric wrt LEbytes_to_I.
>> This is a simple interface bug and I hope you will fix this soon.
>
> I cannot see an interface bug, and you have yet to show that the
> implementation has a bug.
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.
so the normal use case is:
foo_t object;
byte buffer[64];
serialize_foo(object,buffer,64);
....
deserialize_foo(&object,buffer,64);
....
or
foo_t object;
int size = foo_size(object);
byte *buffer = alloca(size);
serialize_foo(object,buffer,size);
....
deserialize_foo(&object,buffer,size);
....
the current interface is highly unusual:
1. an extra argument to serialize_foo()
2. user has to do the padding, not serialize_foo()
--
Sam Steingold (http://www.podval.org/~sds) running w2k
<http://www.memri.org/> <http://www.iris.org.il>
<http://ffii.org/> <http://www.honestreporting.com> <http://pmw.org.il/>
The plural of "anecdote" is not "data".
|