|
An az_span represents a contiguous byte buffer and is used for string manipulations, HTTP requests/responses, reading/writing JSON payloads, and more. More...
#include <azure/core/az_result.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <string.h>
#include <azure/core/_az_cfg_prefix.h>
#include <azure/core/_az_cfg_suffix.h>
Go to the source code of this file.
Data Structures | |
struct | az_span |
Represents a "view" over a byte buffer that represents a contiguous region of memory. It contains a pointer to the start of the byte buffer and the buffer's size. More... | |
struct | az_span_allocator_context |
Defines a container of required and user-defined fields that provide the necessary information and parameters for the implementation of the az_span_allocator_fn callback. More... | |
Macros | |
#define | AZ_SPAN_EMPTY |
An empty az_span. More... | |
#define | AZ_SPAN_LITERAL_FROM_STR(STRING_LITERAL) |
Returns a literal az_span over a literal string. The size of the az_span is equal to the length of the string. More... | |
#define | AZ_SPAN_FROM_STR(STRING_LITERAL) (az_span) AZ_SPAN_LITERAL_FROM_STR(STRING_LITERAL) |
Returns an az_span expression over a literal string. More... | |
#define | AZ_SPAN_FROM_BUFFER(BYTE_BUFFER) |
Returns an az_span expression over an uninitialized byte buffer. More... | |
Typedefs | |
typedef az_result(* | az_span_allocator_fn) (az_span_allocator_context *allocator_context, az_span *out_next_destination) |
Defines the signature of the callback function that the caller must implement to provide the potentially discontiguous destination buffers where output can be written into. More... | |
Functions | |
AZ_NODISCARD AZ_INLINE uint8_t * | az_span_ptr (az_span span) |
Returns the az_span byte buffer's starting memory address. More... | |
AZ_NODISCARD AZ_INLINE int32_t | az_span_size (az_span span) |
Returns the number of bytes within the az_span. More... | |
AZ_NODISCARD az_span | az_span_create (uint8_t *ptr, int32_t size) |
Returns an az_span over a byte buffer. More... | |
AZ_NODISCARD az_span | az_span_create_from_str (char *str) |
Returns an az_span from a 0-terminated array of bytes (chars). More... | |
AZ_NODISCARD az_span | az_span_slice (az_span span, int32_t start_index, int32_t end_index) |
Returns a new az_span which is a sub-span of the specified span . More... | |
AZ_NODISCARD az_span | az_span_slice_to_end (az_span span, int32_t start_index) |
Returns a new az_span which is a sub-span of the specified span . More... | |
AZ_NODISCARD AZ_INLINE bool | az_span_is_content_equal (az_span span1, az_span span2) |
Determines whether two spans are equal by comparing their bytes. More... | |
AZ_NODISCARD bool | az_span_is_content_equal_ignoring_case (az_span span1, az_span span2) |
Determines whether two spans are equal by comparing their characters, except for casing. More... | |
void | az_span_to_str (char *destination, int32_t destination_max_size, az_span source) |
Copies a source az_span containing a string (that is not 0-terminated) to a destination char buffer and appends the 0-terminating byte. More... | |
AZ_NODISCARD int32_t | az_span_find (az_span source, az_span target) |
Searches for target in source , returning an az_span within source if it finds it. More... | |
az_span | az_span_copy (az_span destination, az_span source) |
Copies the content of the source az_span to the destination az_span. More... | |
az_span | az_span_copy_u8 (az_span destination, uint8_t byte) |
Copies the uint8_t byte to the destination at its 0-th index. More... | |
AZ_INLINE void | az_span_fill (az_span destination, uint8_t value) |
Fills all the bytes of the destination az_span with the specified value. More... | |
AZ_NODISCARD az_result | az_span_atou64 (az_span source, uint64_t *out_number) |
Parses an az_span containing ASCII digits into a uint64_t number. More... | |
AZ_NODISCARD az_result | az_span_atoi64 (az_span source, int64_t *out_number) |
Parses an az_span containing ASCII digits into an int64_t number. More... | |
AZ_NODISCARD az_result | az_span_atou32 (az_span source, uint32_t *out_number) |
Parses an az_span containing ASCII digits into a uint32_t number. More... | |
AZ_NODISCARD az_result | az_span_atoi32 (az_span source, int32_t *out_number) |
Parses an az_span containing ASCII digits into an int32_t number. More... | |
AZ_NODISCARD az_result | az_span_atod (az_span source, double *out_number) |
Parses an az_span containing ASCII digits into a double number. More... | |
AZ_NODISCARD az_result | az_span_i32toa (az_span destination, int32_t source, az_span *out_span) |
Converts an int32_t into its digit characters (base 10) and copies them to the destination az_span starting at its 0-th index. More... | |
AZ_NODISCARD az_result | az_span_u32toa (az_span destination, uint32_t source, az_span *out_span) |
Converts an uint32_t into its digit characters (base 10) and copies them to the destination az_span starting at its 0-th index. More... | |
AZ_NODISCARD az_result | az_span_i64toa (az_span destination, int64_t source, az_span *out_span) |
Converts an int64_t into its digit characters (base 10) and copies them to the destination az_span starting at its 0-th index. More... | |
AZ_NODISCARD az_result | az_span_u64toa (az_span destination, uint64_t source, az_span *out_span) |
Converts a uint64_t into its digit characters (base 10) and copies them to the destination az_span starting at its 0-th index. More... | |
AZ_NODISCARD az_result | az_span_dtoa (az_span destination, double source, int32_t fractional_digits, az_span *out_span) |
Converts a double into its digit characters (base 10 decimal notation) and copies them to the destination az_span starting at its 0-th index. More... | |
An az_span represents a contiguous byte buffer and is used for string manipulations, HTTP requests/responses, reading/writing JSON payloads, and more.
#define AZ_SPAN_EMPTY |
#define AZ_SPAN_FROM_BUFFER | ( | BYTE_BUFFER | ) |
Returns an az_span expression over an uninitialized byte buffer.
For example:
uint8_t buffer[1024];
some_function(AZ_SPAN_FROM_BUFFER(buffer)); // Size = 1024
uint8_t buffer[10];
and not uint8_t* buffer
#define AZ_SPAN_FROM_STR | ( | STRING_LITERAL | ) | (az_span) AZ_SPAN_LITERAL_FROM_STR(STRING_LITERAL) |
Returns an az_span expression over a literal string.
For example:
some_function(AZ_SPAN_FROM_STR("Hello world"));
where
void some_function(const az_span span);
#define AZ_SPAN_LITERAL_FROM_STR | ( | STRING_LITERAL | ) |
Returns a literal az_span over a literal string. The size of the az_span is equal to the length of the string.
For example:
static const az_span hw = AZ_SPAN_LITERAL_FROM_STR("Hello world");
typedef az_result(* az_span_allocator_fn) (az_span_allocator_context *allocator_context, az_span *out_next_destination) |
Defines the signature of the callback function that the caller must implement to provide the potentially discontiguous destination buffers where output can be written into.
[in] | allocator_context | A container of required and user-defined fields that provide the necessary information and parameters for the implementation of the callback. |
[out] | out_next_destination | A pointer to an az_span that can be used as a destination to write data into, that is at least the required size specified within the allocator_context . |
AZ_OK | Success. |
other | Failure. |
out_next_destination
. Parses an az_span containing ASCII digits into a double
number.
[in] | source | The az_span containing the ASCII digits to be parsed. |
[out] | out_number | The pointer to the variable that is to receive the number. |
AZ_OK | Success. |
AZ_ERROR_UNEXPECTED_CHAR | A non-ASCII digit or an invalid character is found within the span, or the resulting out_number wouldn't be a finite double number. |
NaN
, INFINITY
, and those that would overflow a double
to +/-inf
are not allowed. Parses an az_span containing ASCII digits into an int32_t
number.
[in] | source | The az_span containing the ASCII digits to be parsed. |
[out] | out_number | The pointer to the variable that is to receive the number. |
AZ_OK | Success. |
AZ_ERROR_UNEXPECTED_CHAR | A non-ASCII digit is found within the span or if the source contains a number that would overflow or underflow int32_t . |
Parses an az_span containing ASCII digits into an int64_t
number.
[in] | source | The az_span containing the ASCII digits to be parsed. |
[out] | out_number | The pointer to the variable that is to receive the number. |
AZ_OK | Success. |
AZ_ERROR_UNEXPECTED_CHAR | A non-ASCII digit is found within the span or the source contains a number that would overflow or underflow int64_t . |
Parses an az_span containing ASCII digits into a uint32_t
number.
[in] | source | The az_span containing the ASCII digits to be parsed. |
[out] | out_number | The pointer to the variable that is to receive the number. |
AZ_OK | Success. |
AZ_ERROR_UNEXPECTED_CHAR | A non-ASCII digit is found within the span or the source contains a number that would overflow or underflow uint32_t . |
Parses an az_span containing ASCII digits into a uint64_t
number.
[in] | source | The az_span containing the ASCII digits to be parsed. |
[out] | out_number | The pointer to the variable that is to receive the number. |
AZ_OK | Success. |
AZ_ERROR_UNEXPECTED_CHAR | A non-ASCII digit is found within the span or the source contains a number that would overflow or underflow uint64_t . |
Copies the content of the source
az_span to the destination
az_span.
destination | The az_span whose bytes will be replaced by the bytes from source . | |
[in] | source | The az_span containing the bytes to copy to the destination. |
destination
az_span (i.e. the remainder) after the source bytes have been copied.destination
has a large enough size to hold the source
.source
into the destination
even if they overlap. source
is an empty az_span or AZ_SPAN_EMPTY, this function will just return destination
. Copies the uint8_t
byte
to the destination
at its 0-th index.
destination | The az_span where the byte should be copied to. | |
[in] | byte | The uint8_t to copy into the destination span. |
destination
az_span (i.e. the remainder) after the byte
has been copied.destination
has a large enough size to hold one more byte. AZ_NODISCARD az_span az_span_create | ( | uint8_t * | ptr, |
int32_t | size | ||
) |
Returns an az_span over a byte buffer.
[in] | ptr | The memory address of the first byte in the byte buffer. |
[in] | size | The total number of bytes in the byte buffer. |
AZ_NODISCARD az_span az_span_create_from_str | ( | char * | str | ) |
AZ_NODISCARD az_result az_span_dtoa | ( | az_span | destination, |
double | source, | ||
int32_t | fractional_digits, | ||
az_span * | out_span | ||
) |
Converts a double
into its digit characters (base 10 decimal notation) and copies them to the destination
az_span starting at its 0-th index.
destination | The az_span where the bytes should be copied to. | |
[in] | source | The double whose number is copied to the destination az_span as ASCII digits and characters. |
[in] | fractional_digits | The number of digits to write into the destination az_span after the decimal point and truncate the rest. |
[out] | out_span | A pointer to an az_span that receives the remainder of the destination az_span after the double has been copied. |
AZ_OK | Success. |
AZ_ERROR_NOT_ENOUGH_SPACE | The destination is not big enough to contain the copied bytes. |
AZ_ERROR_NOT_SUPPORTED | The source is not a finite decimal number or contains an integer component that is too large and would overflow beyond 2^53 - 1 . |
double
values are supported. Values such as NaN
and INFINITY
are not allowed.fractional_digits
is large enough to allow the zero padding.fractional_digits
must be between 0 and 15 (inclusive). Any value passed in that is larger will be clamped down to 15. AZ_INLINE void az_span_fill | ( | az_span | destination, |
uint8_t | value | ||
) |
Searches for target
in source
, returning an az_span within source
if it finds it.
[in] | source | The az_span with the content to be searched on. |
[in] | target | The az_span containing the tokens to be searched within source . |
target
in source
if source
contains the target
within it. 0 | target is empty (if its size is equal zero). |
-1 | target is not found in source OR source is empty (if its size is zero) and target is non-empty. |
>=0 | The position of target in source . |
Converts an int32_t
into its digit characters (base 10) and copies them to the destination
az_span starting at its 0-th index.
destination | The az_span where the bytes should be copied to. | |
[in] | source | The int32_t whose number is copied to the destination az_span as ASCII digits. |
[out] | out_span | A pointer to an az_span that receives the remainder of the destination az_span after the int32_t has been copied. |
AZ_OK | Success. |
AZ_ERROR_NOT_ENOUGH_SPACE | The destination is not big enough to contain the copied bytes. |
Converts an int64_t
into its digit characters (base 10) and copies them to the destination
az_span starting at its 0-th index.
destination | The az_span where the bytes should be copied to. | |
[in] | source | The int64_t whose number is copied to the destination az_span as ASCII digits. |
[out] | out_span | A pointer to an az_span that receives the remainder of the destination az_span after the int64_t has been copied. |
AZ_OK | Success. |
AZ_ERROR_NOT_ENOUGH_SPACE | The destination is not big enough to contain the copied bytes. |
Determines whether two spans are equal by comparing their characters, except for casing.
true
if the sizes of both spans are identical and the ASCII characters in both spans are also identical, except for casing.AZ_NODISCARD AZ_INLINE uint8_t* az_span_ptr | ( | az_span | span | ) |
AZ_NODISCARD AZ_INLINE int32_t az_span_size | ( | az_span | span | ) |
Returns a new az_span which is a sub-span of the specified span
.
[in] | span | The original az_span. |
[in] | start_index | An index into the original az_span indicating where the returned az_span will start. |
[in] | end_index | An index into the original az_span indicating where the returned az_span should stop. The byte at the end_index is NOT included in the returned az_span. |
void az_span_to_str | ( | char * | destination, |
int32_t | destination_max_size, | ||
az_span | source | ||
) |
Copies a source
az_span containing a string (that is not 0-terminated) to a destination
char buffer and appends the 0-terminating byte.
destination | A pointer to a buffer where the string should be copied into. | |
[in] | destination_max_size | The maximum available space within the buffer referred to by destination . |
[in] | source | The az_span containing the not-0-terminated string to copy into destination . |
destination
must have a size that is at least 1 byte bigger than the source
az_span for the destination
string to be zero-terminated. Content is copied from the source
buffer and then \0
is added at the end. Converts an uint32_t
into its digit characters (base 10) and copies them to the destination
az_span starting at its 0-th index.
destination | The az_span where the bytes should be copied to. | |
[in] | source | The uint32_t whose number is copied to the destination az_span as ASCII digits. |
[out] | out_span | A pointer to an az_span that receives the remainder of the destination az_span after the uint32_t has been copied. |
AZ_OK | Success. |
AZ_ERROR_NOT_ENOUGH_SPACE | The destination is not big enough to contain the copied bytes. |
Converts a uint64_t
into its digit characters (base 10) and copies them to the destination
az_span starting at its 0-th index.
destination | The az_span where the bytes should be copied to. | |
[in] | source | The uint64_t whose number is copied to the destination az_span as ASCII digits. |
[out] | out_span | A pointer to an az_span that receives the remainder of the destination az_span after the uint64_t has been copied. |
AZ_OK | Success. |
AZ_ERROR_NOT_ENOUGH_SPACE | The destination is not big enough to contain the copied bytes. |