From 01aa8b82dd0f8229355ffd2bb2bc8e8f496d2df6 Mon Sep 17 00:00:00 2001 From: Sverker Eriksson Date: Fri, 26 Apr 2019 19:43:53 +0200 Subject: erl_interface: Tweak bit string encode/decode API to support zero copy decoding and bit offset arguments for future unaligned bit strings. --- lib/erl_interface/doc/src/ei.xml | 60 ++++++++++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 21 deletions(-) (limited to 'lib/erl_interface/doc') diff --git a/lib/erl_interface/doc/src/ei.xml b/lib/erl_interface/doc/src/ei.xml index 254ae27cc8..7808bfd94f 100644 --- a/lib/erl_interface/doc/src/ei.xml +++ b/lib/erl_interface/doc/src/ei.xml @@ -183,28 +183,36 @@ typedef enum { - intei_decode_bitstring(const char *buf, int *index, void *p, size_t plen, size_t *bitsp) + intei_decode_bitstring(const char *buf, int *index, const char **pp, unsigned int *bitoffsp, size_t *nbitsp) Decode a bitstring. -

Decodes a bitstring from the binary format.

+

Decodes a bit string from the binary format.

- p -

Either NULL or points to a buffer where the bytes of the - bitstring will be written.

+ pp +

Either NULL or *pp returns a pointer to + the first byte of the bit string. The returned bit string is + readable as long as the buffer pointed to by buf is + readable and not written to.

- plen -

The max size of the bitstring in bytes, that is the - size of the buffer if p != NULL.

+ bitoffsp +

Either NULL or *bitoffsp returns the + number of unused bits in the first byte pointed to by + *pp. The value of *bitoffsp is between 0 and 7. + Unused bits in the first byte are the most significant bits.

- *bitsp -

If bitsp is not NULL, set to the actual - number of bits of the bitstring.

+ nbitsp +

Either NULL or *nbitsp returns the length + of the bit string in bits.

-

Returns 0 if it was a bitstring no longer than plen - bytes. The actual length of the bitstring will be - (*bitsp+7)/8 bytes. If (*bitsp % 8) > 0 only the high - (*bitsp % 8) bits of the last byte are significant.

+

Returns 0 if it was a bit string term.

+

The number of bytes pointed to by *pp, which are + part of the bit string, is (*bitoffsp + *nbitsp + 7)/8. If + (*bitoffsp + *bitsp)%8 > 0 then only (*bitoffsp + + *bitsp)%8 bits of the last byte are used. Unused bits in + the last byte are the least significant bits.

+

The values of unused bits in the first and last byte are undefined + and cannot be relied on.

Number of bits may be divisible by 8, which means a binary decodable by ei_decode_binary is also decodable by ei_decode_bitstring.

@@ -490,14 +498,24 @@ typedef enum {
- intei_encode_bitstring(char *buf, int *index, const void *p, size_t bits) - intei_x_encode_bitstring(ei_x_buff* x, const void *p, size_t bits) + int + ei_encode_bitstring(char *buf, int *index, const char *p, size_t bitoffs, size_t nbits) + int + ei_x_encode_bitstring(ei_x_buff* x, const char *p, size_t bitoffs, size_t nbits) Encode a bitstring. -

Encodes a bitstring in the binary format. The data is at - p. The size of the data is bits bits or - (bits+7)/8 bytes. If (bits%8) > 0 only the high - (bits%8) bits of the last byte are significant.

+

Encodes a bit string in the binary format.

+

The data is at p. The length of the bit string is nbits + bits. The first bitoffs bits of the data at p are unused. + The first byte which is part of the bit string is + p[bitoffs/8]. The bitoffs%8 most significant bits of + the first byte p[bitoffs/8] are unused.

+

The number of bytes which is part of the bit string is (bitoffs + + nbits + 7)/8. If (bitoffs + nbits)%8 > 0 then only (bitoffs + + nbits)%8 bits of the last byte are used. Unused bits in + the last byte are the least significant bits.

+

The values of unused bits are disregarded and does not need to be + cleared.

-- cgit v1.2.3