<commit_before>/*
 * librdkafka - Apache Kafka C library
 *
 * Copyright (c) 2012,2013 <NAME>
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met: 
 * 
 * 1. Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer. 
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution. 
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#pragma once


#include "rdendian.h"
/*
 * Kafka protocol definitions.
 */

#define RD_KAFKA_PORT      9092
#define RD_KAFKA_PORT_STR "9092"


#pragma pack(push, 1)
/**
 * Request header
 */
struct rd_kafkap_reqhdr {
	int32_t  Size;
	int16_t  ApiKey;
#define RD_KAFKAP_Produce       0
#define RD_KAFKAP_Fetch         1
#define RD_KAFKAP_Offset        2
#define RD_KAFKAP_Metadata      3
#define RD_KAFKAP_LeaderAndIsr  4
#define RD_KAFKAP_StopReplica   5
#define RD_KAFKAP_OffsetCommit  8
#define RD_KAFKAP_OffsetFetch   9
#define RD_KAFKAP_ConsumerMetadata 10
	int16_t  ApiVersion;
	int32_t  CorrId;
	/* ClientId follows */
} RD_PACKED;

/**
 * Response header
 */
struct rd_kafkap_reshdr {
	int32_t  Size;
	int32_t  CorrId;
} RD_PACKED;

#pragma pack(pop)


static RD_UNUSED
const char *rd_kafka_ApiKey2str (int16_t ApiKey) {
	static const char *names[] = {
		[RD_KAFKAP_Produce] = "Produce",
		[RD_KAFKAP_Fetch] = "Fetch",
		[RD_KAFKAP_Offset] = "Offset",
		[RD_KAFKAP_Metadata] = "Metadata",
		[RD_KAFKAP_LeaderAndIsr] = "LeaderAndIsr",
		[RD_KAFKAP_StopReplica] = "StopReplica",
		[RD_KAFKAP_OffsetCommit] = "OffsetCommit",
		[RD_KAFKAP_OffsetFetch] = "OffsetFetch",
		[RD_KAFKAP_ConsumerMetadata] = "ConsumerMetadata"
	};
	static RD_TLS char ret[32];

	if (ApiKey < 0 || ApiKey >= RD_ARRAYSIZE(names)) {
		rd_snprintf(ret, sizeof(ret), "Unknown-%hd?", ApiKey);
		return ret;
	}

	return names[ApiKey];
}




/**
 *
 * Kafka protocol string representation: { uint16, data.. }
 *
 */
#pragma pack(push, 1)
typedef struct rd_kafkap_str_s {
	int16_t len;    /* big endian */
	char    str[0]; /* allocated dynamically */
} RD_PACKED rd_kafkap_str_t;
#pragma pack(pop)

#define RD_KAFKAP_STR_LEN_NULL -1
/* Returns the actual size of a kafka protocol string representation. */
#define RD_KAFKAP_STR_SIZE(kstr) (int16_t)(sizeof((kstr)->len) +	\
					   ((int16_t)be16toh((kstr)->len) == \
					    RD_KAFKAP_STR_LEN_NULL ?	\
					    0 : be16toh((kstr)->len)))
/* Returns the length of the string of a kafka protocol string representation */
#define RD_KAFKAP_STR_LEN(kstr) (int)((be16toh((kstr)->len) ==		\
				       RD_KAFKAP_STR_LEN_NULL ?		\
				       0 : (int16_t)be16toh((kstr)->len)))


/* Macro suitable for "%.*s" printing. */
#define RD_KAFKAP_STR_PR(kstr)  \
	((int16_t)be16toh((kstr)->len) == RD_KAFKAP_STR_LEN_NULL ?	\
	 0 : (int)be16toh((kstr)->len)), (kstr)->str

#define RD_KAFKAP_STR_IS_NULL(kstr) \
	((int16_t)be16toh((kstr)->len) == RD_KAFKAP_STR_LEN_NULL)

static __inline int rd_kafkap_str_cmp (const rd_kafkap_str_t *a,
				     const rd_kafkap_str_t *b) RD_UNUSED;
static __inline int rd_kafkap_str_cmp (const rd_kafkap_str_t *a,
				     const rd_kafkap_str_t *b) {
	if (a->len != b->len)
		return -1;
	return memcmp(a->str, b->str, be16toh(a->len));
}

static __inline int rd_kafkap_str_cmp_str (const rd_kafkap_str_t *a,
					 const char *str) RD_UNUSED;
static __inline int rd_kafkap_str_cmp_str (const rd_kafkap_str_t *a,
					 const char *str) {<commit_msg>Added RD_KAFKAP_STR_DUPA() (alloca) and .._STR_INIT_NULL<commit_after>/*
 * librdkafka - Apache Kafka C library
 *
 * Copyright (c) 2012,2013 <NAME>
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met: 
 * 
 * 1. Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer. 
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution. 
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#pragma once


#include "rdendian.h"
/*
 * Kafka protocol definitions.
 */

#define RD_KAFKA_PORT      9092
#define RD_KAFKA_PORT_STR "9092"


#pragma pack(push, 1)
/**
 * Request header
 */
struct rd_kafkap_reqhdr {
	int32_t  Size;
	int16_t  ApiKey;
#define RD_KAFKAP_Produce       0
#define RD_KAFKAP_Fetch         1
#define RD_KAFKAP_Offset        2
#define RD_KAFKAP_Metadata      3
#define RD_KAFKAP_LeaderAndIsr  4
#define RD_KAFKAP_StopReplica   5
#define RD_KAFKAP_OffsetCommit  8
#define RD_KAFKAP_OffsetFetch   9
#define RD_KAFKAP_ConsumerMetadata 10
	int16_t  ApiVersion;
	int32_t  CorrId;
	/* ClientId follows */
} RD_PACKED;

/**
 * Response header
 */
struct rd_kafkap_reshdr {
	int32_t  Size;
	int32_t  CorrId;
} RD_PACKED;

#pragma pack(pop)


static RD_UNUSED
const char *rd_kafka_ApiKey2str (int16_t ApiKey) {
	static const char *names[] = {
		[RD_KAFKAP_Produce] = "Produce",
		[RD_KAFKAP_Fetch] = "Fetch",
		[RD_KAFKAP_Offset] = "Offset",
		[RD_KAFKAP_Metadata] = "Metadata",
		[RD_KAFKAP_LeaderAndIsr] = "LeaderAndIsr",
		[RD_KAFKAP_StopReplica] = "StopReplica",
		[RD_KAFKAP_OffsetCommit] = "OffsetCommit",
		[RD_KAFKAP_OffsetFetch] = "OffsetFetch",
		[RD_KAFKAP_ConsumerMetadata] = "ConsumerMetadata"
	};
	static RD_TLS char ret[32];

	if (ApiKey < 0 || ApiKey >= RD_ARRAYSIZE(names)) {
		rd_snprintf(ret, sizeof(ret), "Unknown-%hd?", ApiKey);
		return ret;
	}

	return names[ApiKey];
}




/**
 *
 * Kafka protocol string representation: { uint16, data.. }
 *
 */
#pragma pack(push, 1)
typedef struct rd_kafkap_str_s {
	int16_t len;    /* big endian */
	char    str[0]; /* allocated dynamically */
} RD_PACKED rd_kafkap_str_t;
#pragma pack(pop)

#define RD_KAFKAP_STR_LEN_NULL -1
/* Returns the actual size of a kafka protocol string representation. */
#define RD_KAFKAP_STR_SIZE(kstr) (int16_t)(sizeof((kstr)->len) +	\
					   ((int16_t)be16toh((kstr)->len) == \
					    RD_KAFKAP_STR_LEN_NULL ?	\
					    0 : be16toh((kstr)->len)))
/* Returns the length of the string of a kafka protocol string representation */
#define RD_KAFKAP_STR_LEN(kstr) (int)((be16toh((kstr)->len) ==		\
				       RD_KAFKAP_STR_LEN_NULL ?		\
				       0 : (int16_t)be16toh((kstr)->len)))


/* Macro suitable for "%.*s" printing. */
#define RD_KAFKAP_STR_PR(kstr)  \
	((int16_t)be16toh((kstr)->len) == RD_KAFKAP_STR_LEN_NULL ?	\
	 0 : (int)be16toh((kstr)->len)), (kstr)->str

#define RD_KAFKAP_STR_IS_NULL(kstr) \
	((int16_t)be16toh((kstr)->len) == RD_KAFKAP_STR_LEN_NULL)

/* strndupa() a Kafka string */
#define RD_KAFKAP_STR_DUPA(kstr) strndupa((kstr)->str, RD_KAFKAP_STR_LEN(kstr))

/* Initialize a kafka string to Null */
#define RD_KAFKAP_STR_INIT_NULL  { htobe16(RD_KAFKAP_STR_LEN_NULL) }


static __inline int rd_kafkap_str_cmp (const rd_kafkap_str_t *a,
				     const rd_kafkap_str_t *b) RD_UNUSED;
static __inline int rd_kafkap_str_cmp (const rd_kafkap_str_t *a,
				     const rd_kafkap_str_t *b) {
	if (a->len != b->len)
		return -1;
	return memcmp(a->str, b->str, be16toh(a->len));
}

static __inline int rd_kafkap_str_cmp_str (const rd_kafkap_str_t *a,
					 const char *str) RD_UNUSED;
static __inline int rd_kafkap_str_cmp_str (const rd_kafkap_str_t *a,
					 const char *str) {
{'fraction_non_alphanumeric': 0.10207214121258634, 'fraction_numerical': 0.01863830720315755, 'mean_word_length': 4.174134997163925, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 36, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6395545', 'n_tokens_mistral': 3713, 'n_tokens_neox': 3304, 'n_words': 905}