diff --git a/include/rabbitmq-c/amqp.h b/include/rabbitmq-c/amqp.h index dde976dd..2d6171df 100644 --- a/include/rabbitmq-c/amqp.h +++ b/include/rabbitmq-c/amqp.h @@ -849,6 +849,23 @@ AMQP_EXPORT void AMQP_CALL amqp_pool_alloc_bytes(amqp_pool_t *pool, size_t amount, amqp_bytes_t *output); +/** + * Wraps a c string literal in an amqp_bytes_t + * + * Takes a string literal, calculates its length and creates an + * amqp_bytes_t that points to it. The string literal is not duplicated. + * + * For a given input str, The amqp_bytes_t output.bytes is the + * same as str, output.len is the length of the string literal not including + * the \0 terminator + * + * \param [in] str the c string literal to wrap + * \return an amqp_bytes_t that describes the string literal + * + * \since v0.15 + */ +#define amqp_literal_bytes(str) (amqp_bytes_t){sizeof(str) - 1, str} + /** * Wraps a c string in an amqp_bytes_t * diff --git a/librabbitmq/amqp_socket.c b/librabbitmq/amqp_socket.c index 22e77e36..094ceb72 100644 --- a/librabbitmq/amqp_socket.c +++ b/librabbitmq/amqp_socket.c @@ -509,10 +509,10 @@ static amqp_bytes_t sasl_method_name(amqp_sasl_method_enum method) { switch (method) { case AMQP_SASL_METHOD_PLAIN: - res = amqp_cstring_bytes("PLAIN"); + res = amqp_literal_bytes("PLAIN"); break; case AMQP_SASL_METHOD_EXTERNAL: - res = amqp_cstring_bytes("EXTERNAL"); + res = amqp_literal_bytes("EXTERNAL"); break; default: @@ -1332,7 +1332,7 @@ static amqp_rpc_reply_t amqp_login_inner(amqp_connection_state_t state, s.client_properties = state->client_properties; s.mechanism = sasl_method_name(sasl_method); s.response = response_bytes; - s.locale = amqp_cstring_bytes("en_US"); + s.locale = amqp_literal_bytes("en_US"); res = amqp_send_method_inner(state, 0, AMQP_CONNECTION_START_OK_METHOD, &s, AMQP_SF_NONE, deadline);