Subject | Re: [Firebird-Architect] Data Stream Encoding |
---|---|
Author | Jim Starkey |
Post date | 2005-04-30T01:31:19Z |
Geoff Worboys wrote:
const UCHAR* EncodedDataStream::decode(UCHAR *ptr, Value *value)
{
const UCHAR *p = ptr;
UCHAR code = *p++;
switch(code)
{
case edsNull:
value->setNull();
break;
case edsIntMinus10:
case edsIntMinus9:
...
case edsInt30:
case edsInt31:
value->setValue((short) (code - edsInt0));
break;
case edsUtf8Len0:
case edsUtf8Len1:
...
case edsUtf8Len38:
case edsUtf8Len39:
{
int len = code - edsUtf8Len0;
value->setString(len, (const char*) p, false);
p += len;
}
break;
Yes, there are a huge number of a cases. But they fall into relatively
small number of classes, each is which can be handled with a small,
efficient piece of code.
In practice, an encoded data stream will always be prefaced by a version
number. At the expense of maintaining a variety of different historical
encodings, we can tweak the sizes of the various classes as we gain
experience.
[Non-text portions of this message have been removed]
>Sure, there's method to my madness. Consider:
>On second thought you have presumably considered such schemes
>and discarded them for some reason. Still I think the code
>would be cleaner without such a huge enumeration.
>
>
>
const UCHAR* EncodedDataStream::decode(UCHAR *ptr, Value *value)
{
const UCHAR *p = ptr;
UCHAR code = *p++;
switch(code)
{
case edsNull:
value->setNull();
break;
case edsIntMinus10:
case edsIntMinus9:
...
case edsInt30:
case edsInt31:
value->setValue((short) (code - edsInt0));
break;
case edsUtf8Len0:
case edsUtf8Len1:
...
case edsUtf8Len38:
case edsUtf8Len39:
{
int len = code - edsUtf8Len0;
value->setString(len, (const char*) p, false);
p += len;
}
break;
Yes, there are a huge number of a cases. But they fall into relatively
small number of classes, each is which can be handled with a small,
efficient piece of code.
In practice, an encoded data stream will always be prefaced by a version
number. At the expense of maintaining a variety of different historical
encodings, we can tweak the sizes of the various classes as we gain
experience.
[Non-text portions of this message have been removed]