in sdk/src/azure/core/az_json_writer.c [158:199]
static AZ_NODISCARD bool _az_is_appending_container_end_valid(
az_json_writer const* json_writer,
uint8_t byte)
{
_az_PRECONDITION_NOT_NULL(json_writer);
az_json_token_kind kind = json_writer->_internal.token_kind;
// Cannot write an end of a container without a matching start.
// This includes writing the end token as the first token in the JSON or right after a property
// name.
if (json_writer->_internal.bit_stack._internal.current_depth <= 0
|| kind == AZ_JSON_TOKEN_PROPERTY_NAME)
{
return false;
}
_az_json_stack_item stack_item = _az_json_stack_peek(&json_writer->_internal.bit_stack);
if (byte == ']')
{
// If inside a JSON object, then appending an end bracket is invalid:
if (stack_item)
{
_az_PRECONDITION(kind != AZ_JSON_TOKEN_NONE);
return false;
}
}
else
{
_az_PRECONDITION(byte == '}');
// If not inside a JSON object, then appending an end brace is invalid:
if (!stack_item)
{
return false;
}
}
// JSON writer state is valid and an end of a container can be appended.
return true;
}