<commit_before>#include "zwsdecoder.h"

typedef enum
{
	opcode_continuation = 0, opcode_text = 0x01, opcode_binary = 0x03, opcode_close = 0x08, opcode_ping = 0x09, opcode_pong = 0xA
} opcode_t;

typedef enum
{
	new_message, second_byte, short_size, short_size_2,
	long_size, long_size_2, long_size_3, long_size_4, long_size_5, long_size_6, long_size_7, long_size_8,
	mask, mask_2, mask_3, mask_4, more_byte, begin_payload, payload, error
} state_t;

struct _zwsdecoder_t
{
	state_t state;

	opcode_t opcode;
	bool is_masked;
	byte mask[4];
	bool more;
	char *payload;
	int payload_length;
	int payload_index;
	void *tag;
	message_callback_t message_cb;
	close_callback_t close_cb;
	ping_callback_t ping_cb;
	pong_callback_t pong_cb;
};

// private methods
void zwsdecoder_process_byte(zwsdecoder_t *self, byte b);
state_t zwsdecoder_next_state(zwsdecoder_t *self);
void invoke_new_message(zwsdecoder_t *self);


zwsdecoder_t* zwsdecoder_new(void *tag, message_callback_t message_cb, close_callback_t close_cb, ping_callback_t ping_cb, pong_callback_t pong_cb)
{
	zwsdecoder_t *self = zmalloc(sizeof(zwsdecoder_t));

	self->state = new_message;
	self->tag = tag;
	self->message_cb = message_cb;
	self->close_cb = close_cb;
	self->ping_cb = ping_cb;
	self->pong_cb = pong_cb;

	return self;
}

void zwsdecoder_destroy(zwsdecoder_t **self_p)
{
	zwsdecoder_t *self = *self_p;

	free(self);

	self_p = NULL;
}

void zwsdecoder_process_buffer(zwsdecoder_t *self, zframe_t* data)
{
	int i = 0;

	byte* buffer = zframe_data(data);
	int buffer_length = zframe_size(data);

	int bytes_to_read;

	while (i < buffer_length)
	{<commit_msg>zwsdecoder_destroy(): actually zero the reference<commit_after>#include "zwsdecoder.h"

typedef enum
{
	opcode_continuation = 0, opcode_text = 0x01, opcode_binary = 0x03, opcode_close = 0x08, opcode_ping = 0x09, opcode_pong = 0xA
} opcode_t;

typedef enum
{
	new_message, second_byte, short_size, short_size_2,
	long_size, long_size_2, long_size_3, long_size_4, long_size_5, long_size_6, long_size_7, long_size_8,
	mask, mask_2, mask_3, mask_4, more_byte, begin_payload, payload, error
} state_t;

struct _zwsdecoder_t
{
	state_t state;

	opcode_t opcode;
	bool is_masked;
	byte mask[4];
	bool more;
	char *payload;
	int payload_length;
	int payload_index;
	void *tag;
	message_callback_t message_cb;
	close_callback_t close_cb;
	ping_callback_t ping_cb;
	pong_callback_t pong_cb;
};

// private methods
void zwsdecoder_process_byte(zwsdecoder_t *self, byte b);
state_t zwsdecoder_next_state(zwsdecoder_t *self);
void invoke_new_message(zwsdecoder_t *self);


zwsdecoder_t* zwsdecoder_new(void *tag, message_callback_t message_cb, close_callback_t close_cb, ping_callback_t ping_cb, pong_callback_t pong_cb)
{
	zwsdecoder_t *self = zmalloc(sizeof(zwsdecoder_t));

	self->state = new_message;
	self->tag = tag;
	self->message_cb = message_cb;
	self->close_cb = close_cb;
	self->ping_cb = ping_cb;
	self->pong_cb = pong_cb;

	return self;
}

void zwsdecoder_destroy(zwsdecoder_t **self_p)
{
	zwsdecoder_t *self = *self_p;
	free(self);
	*self_p = NULL;
}

void zwsdecoder_process_buffer(zwsdecoder_t *self, zframe_t* data)
{
	int i = 0;

	byte* buffer = zframe_data(data);
	int buffer_length = zframe_size(data);

	int bytes_to_read;

	while (i < buffer_length)
	{
{'fraction_non_alphanumeric': 0.09674475205354427, 'fraction_numerical': 0.016428354122299968, 'mean_word_length': 6.194748358862144, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, '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': '494232', 'n_tokens_mistral': 1422, 'n_tokens_neox': 1338, 'n_words': 278}