Re: bytea internal encoding

From: Ron Peterson <rpeterso(at)mtholyoke(dot)edu>
To: Michael Fuhr <mike(at)fuhr(dot)org>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: bytea internal encoding
Date: 2004-12-16 14:04:41
Message-ID: 20041216140440.GB2250@mtholyoke.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Dec 15, 2004 at 10:22:07PM -0700, Michael Fuhr wrote:
> On Wed, Dec 15, 2004 at 11:08:29PM -0500, Ron Peterson wrote:
>
> > How are bytea values encoded internally?
> >
> > Or maybe a better question would be what is the proper way to access
> > bytea data from within a C function? Are there utility functions for
> > reading the bytea data as a stream of scalar values, for example?
>
> Do you mean a C function on the server side or on the client side?
>
> For examples of server-side code, take a look at functions in the
> PostgreSQL source that handle BYTEA, e.g., byteacat() in
> src/backend/utils/adt/varlena.c. See also the comments concerning
> variable-length data and the relevant examples in the "C-Language
> Functions" section of the "Extending SQL" chapter in the documentation.

Thanks.

I was just looking at byteacat. Because byteacat concatenates two bytea
arguments, it then seems safe enough to use memcpy in conjunction with
VARSIZE to move the data around (they're both the same type, so they'll
map one to one).

I guess maybe what I'm asking is whether or not it's safe to assume that
bytea data will always consist of a string of VARSIZE-VARHDRSZ eight bit
bytes, i.e. it's safe to assume 'byte' will always refer to 8 bit values
in the range 0..255.

--
Ron Peterson
Network & Systems Manager
Mount Holyoke College
http://www.mtholyoke.edu/~rpeterso

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Csaba Nagy 2004-12-16 14:09:20 Re: Scheduler in Postgres
Previous Message Malcolm Warren 2004-12-16 14:03:14 Re: Serial column has suddenly stopped working