[getdns-api] string from dict bindata
Tom Pusateri
pusateri at bangj.com
Mon May 2 03:39:27 UTC 2016
> On May 1, 2016, at 8:40 PM, Melinda Shore <melinda.shore at nomountain.net> wrote:
>
> On 5/1/16 12:14 PM, Tom Pusateri wrote:
>> Are we supposed to peek inside of bindata and assume the bytes and length are string data?
>
> Yes, unfortunately you need to know what type of data
> are being returned in each dictionary element, but if you
> do it's extremely reliable. bindata->size holds the
> string length. I've found that bindata strings do not
> always have a terminal \0, so in the Python bindings I'm
> doing string conversions using PyString_FromStringAndSize()
> rather than just PyString_FromString().
>
> Melinda
Ok, good to confirm.
I am using a special printf construct to avoid the need for ‘\0' terminated strings:
printf("getdns version: %.*s implementation: %.*s\n",
(int)version_bindata->size, version_bindata->data,
(int)impl_bindata->size, impl_bindata->data);
This seems a little dirty to be accessing the data/size which should be opaque.
It’s not a big deal but I guess I was hoping for something like:
char *
getdns_characters_from_bindata(getdns_bindata *bindata, int *lenp)
{
if (lenp) {
*lenp = (int)bindata->size;
}
return bindata->data;
}
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 495 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://lists.getdnsapi.net/pipermail/spec/attachments/20160501/aaffa7cd/attachment.bin>
More information about the spec
mailing list