Class ldns_buffer

Class ldns_buffer

class ldns.ldns_buffer(capacity)

LDNS buffer.

at(at)

Returns a pointer to the data at the indicated position.

Parameters:at (positive integer) – position
Throws TypeError:
 When at of non-integer type.
Returns:(uint8_t *) The pointer to the data.
available(count)

Checks whether the buffer has count bytes available at the current position.

Parameters:count (integer) – How much is available.
Throws TypeError:
 When count of non-integer type.
Returns:(bool) True or False.
available_at(at, count)

Checks if the buffer has at least count more bytes available.

Before reading or writing the caller needs to ensure that enough space is available!

Parameters:
  • at (positive integer) – Indicated position.
  • count (positive integer) – How much is available.
Throws TypeError:
 

When at or count of non-integer type.

Returns:

(bool) True or False.

begin()

Returns a pointer to the beginning of the buffer (the data at position 0).

Returns:(uint8_t *) Pointer.
capacity()

Returns the number of bytes the buffer can hold.

Returns:(size_t) The number of bytes.
clear()

Clears the buffer and make it ready for writing.

The buffer’s limit is set to the capacity and the position is set to 0.

copy(bfrom)

Copy contents of the other buffer to this buffer.

Silently truncated if this buffer is too small.

Parameters:bfrom (ldns_buffer) – Source buffer.
Throws TypeError:
 When bfrom of non-ldns_buffer type.
current()

Returns a pointer to the data at the buffer’s current position.

Returns:(uint8_t *) A pointer.
end()

Returns a pointer to the end of the buffer (the data at the buffer’s limit).

Returns:(uint8_t *) Pointer.
export()

Makes the buffer fixed and returns a pointer to the data.

The caller is responsible for freeing the result.

Returns:(void *) Void pointer.
flip()

Makes the buffer ready for reading the data that has been written to the buffer.

The buffer’s limit is set to the current position and the position is set to 0.

getc()

Returns the next character from a buffer.

Advances the position pointer with 1. When end of buffer is reached returns EOF. This is the buffer’s equivalent for getc().

Returns:(integer) EOF on failure otherwise return the character.
invariant()

Performs no action.

In debugging mode this method performs a buffer settings check. It asserts if something is wrong.

limit()

Returns the maximum size of the buffer.

Returns:(size_t) The size.
position()

Returns the current position in the buffer (as a number of bytes).

Returns:(size_t) The current position.
printf(string, *args)

Prints to the buffer, increasing the capacity if required using buffer_reserve().

The buffer’s position is set to the terminating ‘’. Returns the number of characters written (not including the terminating ‘’) or -1 on failure.

Parameters:string (string) – A string to be written.
Throws :TypeError when string not a string.
Returns:(int) Number of written characters or -1 on failure.
read(data, count)

Copies count bytes of data at the current position to the given data-array

Parameters:
  • data (void *) – Target buffer to copy to.
  • count (size_t) – The length of the data to copy.
read_at(at, data, count)

Copies count bytes of data at the given position to the given data-array.

Parameters:
  • at (size_t) – The position in the buffer to start reading.
  • data (void *) – Target buffer to copy to.
  • count (size_t) – The length of the data to copy.
read_u16()

Returns the 2-byte integer value at the current position from the buffer.

Returns:(uint16_t) Word.
read_u16_at(at)

Returns the 2-byte integer value at the given position from the buffer.

Parameters:at (positive integer) – Position in the buffer.
Throws TypeError:
 When at of non-integer type.
Returns:(uint16_t) Word.
read_u32()

Returns the 4-byte integer value at the current position from the buffer.

Returns:(uint32_t) Double-word.
read_u32_at(at)

Returns the 4-byte integer value at the given position from the buffer.

Parameters:at (positive integer) – Position in the buffer.
Throws TypeError:
 When at of non-integer type.
Returns:(uint32_t) Double-word.
read_u8()

Returns the byte value at the current position from the buffer.

Returns:(uint8_t) A byte (not a character).
read_u8_at(at)

Returns the byte value at the given position from the buffer.

Parameters:at (positive integer) – The position in the buffer.
Throws TypeError:
 When at of non-integer type.
Returns:(uint8_t) Byte value.
remaining()

Returns the number of bytes remaining between the buffer’s position and limit.

Returns:(size_t) The number of bytes.
remaining_at(at)

Returns the number of bytes remaining between the indicated position and the limit.

Parameters:at (positive integer) – Indicated position.
Throws TypeError:
 When at of non-integer type.
Returns:(size_t) number of bytes
reserve(amount)

Ensures that the buffer can contain at least amount more bytes.

The buffer’s capacity is increased if necessary using buffer_set_capacity().

The buffer’s limit is always set to the (possibly increased) capacity.

Parameters:amount (positive integer) – Amount to use.
Throws TypeError:
 When amount of non-integer type.
Returns:(bool) hether this failed or succeeded.
rewind()

Make the buffer ready for re-reading the data.

The buffer’s position is reset to 0.

set_capacity(capacity)

Changes the buffer’s capacity.

The data is reallocated so any pointers to the data may become invalid. The buffer’s limit is set to the buffer’s new capacity.

Parameters:capacity (positive integer) – The capacity to use.
Throws TypeError:
 When capacity of non-integer type.
Returns:(bool) whether this failed or succeeded
set_limit(limit)

Changes the buffer’s limit.

If the buffer’s position is greater than the new limit then the position is set to the limit.

Parameters:limit (positive integer) – The new limit.
Throws TypeError:
 When limit of non-integer type.
set_position(mark)

Sets the buffer’s position to mark.

The position must be less than or equal to the buffer’s limit.

Parameters:mark (positive integer) – The mark to use.
Throws TypeError:
 When mark of non-integer type.
skip(count)

Changes the buffer’s position by count bytes.

The position must not be moved behind the buffer’s limit or before the beginning of the buffer.

Parameters:count (integer) – The count to use.
Throws TypeError:
 When count of non-integer type.
status()

Returns the status of the buffer.

Returns:(ldns_status) The status.
status_ok()

Returns True if the status of the buffer is LDNS_STATUS_OK, False otherwise.

Returns:(bool) True or False.
write(data, count)

Writes count bytes of data to the current position of the buffer.

Parameters:
  • data (void *) – The data to write.
  • count (size_t) – The length of the data to write.
write_at(at, data, count)

Writes the given data to the buffer at the specified position by at.

Parameters:
  • at – The position (in number of bytes) to write the data at.
  • data – Pointer to the data to write to the buffer.
  • count – The number of bytes of data to write.
write_string(string)

Copies the given (null-delimited) string to the current position into the buffer.

Parameters:string (string) – The string to write.
Throws TypeError:
 When string not a string.
write_string_at(at, string)

Copies the given (null-delimited) string to the specified position at into the buffer.

Parameters:
  • at (positive integer) – The position in the buffer.
  • string (string) – The string to write.
Throws TypeError:
 

When types mismatch.

write_u16(data)

Writes the given 2 byte integer at the current position in the buffer.

Parameters:data (uint16_t) – The word to write.
Throws TypeError:
 When data of non-integer type.
write_u16_at(at, data)

Writes the given 2 byte integer at the given position in the buffer.

Parameters:
  • at (positive integer) – The position in the buffer.
  • data (uint16_t) – The word to write.
Throws TypeError:
 

When at or data of non-integer type.

write_u32(data)

Writes the given 4 byte integer at the current position in the buffer.

Parameters:data (uint32_t) – The double-word to write.
Throws TypeError:
 When data of non-integer type.
write_u32_at(at, data)

Writes the given 4 byte integer at the given position in the buffer.

Parameters:
  • at (positive integer) – The position in the buffer.
  • data (uint32_t) – The double-word to write.
Throws TypeError:
 

When at or data of non-integer type.

write_u8(data)

Writes the given byte of data at the current position in the buffer.

Parameters:data (uint8_t) – The byte to write.
Throws TypeError:
 When data of non-integer type.
write_u8_at(at, data)

Writes the given byte of data at the given position in the buffer.

Parameters:
  • at (positive integer) – The position in the buffer.
  • data (uint8_t) – The byte to write.
Throws TypeError:
 

When at or data of non-integer type.

Table Of Contents

Previous topic

Class ldns_key_list

Next topic

Class ldns_dnssec_zone