in sdk/src/azure/core/az_json_writer.c [932:978]
static AZ_NODISCARD az_result _az_json_writer_append_container_start(
az_json_writer* ref_json_writer,
uint8_t byte,
az_json_token_kind container_kind)
{
_az_PRECONDITION_NOT_NULL(ref_json_writer);
_az_PRECONDITION(
container_kind == AZ_JSON_TOKEN_BEGIN_OBJECT || container_kind == AZ_JSON_TOKEN_BEGIN_ARRAY);
_az_PRECONDITION(_az_is_appending_value_valid(ref_json_writer));
// The current depth is equal to or larger than the maximum allowed depth of 64. Cannot write the
// next JSON object or array.
if (ref_json_writer->_internal.bit_stack._internal.current_depth >= _az_MAX_JSON_STACK_SIZE)
{
return AZ_ERROR_JSON_NESTING_OVERFLOW;
}
int32_t required_size = 1; // For the start object or array byte.
if (ref_json_writer->_internal.need_comma)
{
required_size++; // For the leading comma separator.
}
az_span remaining_json = _get_remaining_span(ref_json_writer, required_size);
_az_RETURN_IF_NOT_ENOUGH_SIZE(remaining_json, required_size);
if (ref_json_writer->_internal.need_comma)
{
remaining_json = az_span_copy_u8(remaining_json, ',');
}
az_span_copy_u8(remaining_json, byte);
_az_update_json_writer_state(
ref_json_writer, required_size, required_size, false, container_kind);
if (container_kind == AZ_JSON_TOKEN_BEGIN_OBJECT)
{
_az_json_stack_push(&ref_json_writer->_internal.bit_stack, _az_JSON_STACK_OBJECT);
}
else
{
_az_json_stack_push(&ref_json_writer->_internal.bit_stack, _az_JSON_STACK_ARRAY);
}
return AZ_OK;
}