<commit_before>#ifndef PROTOBUF_H__
#define PROTOBUF_H__

#include "types.h"
#include "compiler.h"
#include "util.h"

/*
 * ATTENTION
 *
 * This typdefs represent "generic" prototypes for
 * pack/unpack/getsize functions generated by PB
 * engine, thus (!!!) if PB engine change arguments
 * order or their number we may meet serious problems.
 *
 * FIXME
 *
 * Find a way to verify PB generated functions statemens
 * to match this typedefs.
 */

typedef size_t (*pb_getpksize_t)(void *obj);
typedef size_t (*pb_pack_t)(void *obj, void *where);
typedef void  *(*pb_unpack_t)(void *allocator, size_t size, void *from);

extern int pb_read_object_with_header(int fd, void **pobj,
				      pb_unpack_t unpack,
				      bool eof);

#define PB_UNPACK_TYPECHECK(__op, __fn)	({ if (0) *__op = __fn(NULL, 0, NULL); (pb_unpack_t)&__fn; })
#define PB_PACK_TYPECHECK(__o, __fn)	({ if (0) __fn(__o, NULL); (pb_pack_t)&__fn; })
#define PB_GPS_TYPECHECK(__o, __fn)	({ if (0) __fn(__o); (pb_getpksize_t)&__fn; })

#define pb_read(__fd, __obj_pptr, __proto_message_name)					\
	pb_read_object_with_header(__fd, (void **)__obj_pptr,				\
		PB_UNPACK_TYPECHECK(__obj_pptr, __proto_message_name ##__unpack), false)

#define pb_read_eof(__fd, __obj_pptr, __proto_message_name)				\
	pb_read_object_with_header(__fd, (void **)__obj_pptr,				\
		PB_UNPACK_TYPECHECK(__obj_pptr, __proto_message_name ##__unpack), true)

extern int pb_write_object_with_header(int fd, void *obj,
				       pb_getpksize_t getpksize,
				       pb_pack_t pack);

#define pb_write(__fd, __obj, __proto_message_name)					\
	pb_write_object_with_header(__fd, __obj,					\
		PB_GPS_TYPECHECK(__obj, __proto_message_name ##__get_packed_size),	\
		PB_PACK_TYPECHECK(__obj, __proto_message_name ##__pack))

#define pb_pksize(__obj, __proto_message_name)						\
	(__proto_message_name ##__get_packed_size(__obj) + sizeof(u32))

#define pb_repeated_size(__obj, __member)						\
	(sizeof(*(__obj)->__member) * (__obj)->n_ ##__member)

extern void pb_show_msg(const void *msg, const void *msg_desc);

#endif /* PROTOBUF_H__ */<commit_msg>pb: Clean _TYPECHECK name generation<commit_after>#ifndef PROTOBUF_H__
#define PROTOBUF_H__

#include "types.h"
#include "compiler.h"
#include "util.h"

/*
 * ATTENTION
 *
 * This typdefs represent "generic" prototypes for
 * pack/unpack/getsize functions generated by PB
 * engine, thus (!!!) if PB engine change arguments
 * order or their number we may meet serious problems.
 *
 * FIXME
 *
 * Find a way to verify PB generated functions statemens
 * to match this typedefs.
 */

typedef size_t (*pb_getpksize_t)(void *obj);
typedef size_t (*pb_pack_t)(void *obj, void *where);
typedef void  *(*pb_unpack_t)(void *allocator, size_t size, void *from);

extern int pb_read_object_with_header(int fd, void **pobj,
				      pb_unpack_t unpack,
				      bool eof);

#define PB_UNPACK_TYPECHECK(__op, __fn)	({ if (0) *__op = __fn##__unpack(NULL, 0, NULL); (pb_unpack_t)&__fn##__unpack; })
#define PB_PACK_TYPECHECK(__o, __fn)	({ if (0) __fn##__pack(__o, NULL); (pb_pack_t)&__fn##__pack; })
#define PB_GPS_TYPECHECK(__o, __fn)	({ if (0) __fn##__get_packed_size(__o); (pb_getpksize_t)&__fn##__get_packed_size; })

#define pb_read(__fd, __obj_pptr, __proto_message_name)					\
	pb_read_object_with_header(__fd, (void **)__obj_pptr,				\
		PB_UNPACK_TYPECHECK(__obj_pptr, __proto_message_name), false)

#define pb_read_eof(__fd, __obj_pptr, __proto_message_name)				\
	pb_read_object_with_header(__fd, (void **)__obj_pptr,				\
		PB_UNPACK_TYPECHECK(__obj_pptr, __proto_message_name), true)

extern int pb_write_object_with_header(int fd, void *obj,
				       pb_getpksize_t getpksize,
				       pb_pack_t pack);

#define pb_write(__fd, __obj, __proto_message_name)					\
	pb_write_object_with_header(__fd, __obj,					\
		PB_GPS_TYPECHECK(__obj, __proto_message_name),				\
		PB_PACK_TYPECHECK(__obj, __proto_message_name))

#define pb_pksize(__obj, __proto_message_name)						\
	(__proto_message_name ##__get_packed_size(__obj) + sizeof(u32))

#define pb_repeated_size(__obj, __member)						\
	(sizeof(*(__obj)->__member) * (__obj)->n_ ##__member)

extern void pb_show_msg(const void *msg, const void *msg_desc);

#endif /* PROTOBUF_H__ */
{'fraction_non_alphanumeric': 0.12094674556213018, 'fraction_numerical': 0.0028402366863905324, 'mean_word_length': 5.214705882352941, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '1156700', 'n_tokens_mistral': 1729, 'n_tokens_neox': 1628, 'n_words': 342}