From: Not Zed Date: Fri, 3 May 2019 00:01:11 +0000 (+0930) Subject: A more sane way of writing sub-int32 arrays, even if it isn't XDR. X-Git-Url: https://code.zedzone.au/cvs?a=commitdiff_plain;h=e90125f01e582e17532248aa9bf680f8950a0b45;p=libeze A more sane way of writing sub-int32 arrays, even if it isn't XDR. --- diff --git a/ez-blob-xdrn.c b/ez-blob-xdrn.c index 057ff49..4c87819 100644 --- a/ez-blob-xdrn.c +++ b/ez-blob-xdrn.c @@ -27,7 +27,7 @@ single singlep vector vectorp list listp cstring ?null 1 ?null ?null - int8 x x 2 x 3 + int8 x x 2 x 3 int16 x x 2 int32 x x int64 x x @@ -37,9 +37,9 @@ 1. Nullable fields are optional and must be properly annotated. They are written as Optional-Data. - 2. These are written as Variable-Length Opaque Data rather than - Variable-Length Array. The size is the byte size not - the element count. + 2. These aren't XDR compatible, it's written as a Variable-Length Array + but with 2-byte elements and end-padding. Well int8 is identical + to Opaque Data. 3. These are 8-bit strings (e.g. UTF-8), not necessarily ASCII as specified by String. @@ -63,16 +63,13 @@ static __inline__ size_t roundup(size_t v) { } /* - Arrays of byte and short are encoded as 'opquate data' for - compactness, the count is the number of bytes. - - Arrays of int32/int64/float/double are written as arrays, - the count is the number of elements. + Arrays of byte and short are encoded as if they were Variable-Length + Array but with natural sized elements, followed by padding. */ static void xdrio_writev(struct ez_blobio *io, const ez_blob *data, size_t elshift) { size_t size = data->eb_size << elshift; - int32_t count = elshift <= 1 ? size : data->eb_size; + int32_t count = data->eb_size; void *v; blobio_write32(io, count); @@ -85,7 +82,7 @@ static void xdrio_writev(struct ez_blobio *io, const ez_blob *data, size_t elshi static void xdrio_readv(struct ez_blobio *io, ez_blob *data, size_t elshift) { int32_t count = blobio_readi32(io); - size_t size = elshift <= 1 ? count : count << elshift; + size_t size = count << elshift; void *src = blobio_take(io, size); if (src) { @@ -94,7 +91,7 @@ static void xdrio_readv(struct ez_blobio *io, ez_blob *data, size_t elshift) { if (mem) { memcpy(mem, src, size); data->eb_data = mem; - data->eb_size = size >> elshift; + data->eb_size = count; blobio_read_align(io, 4); } else { io->error = ENOMEM;