<commit_before>-module(vmq_parser).
-include("vmq_types.hrl").
-export([parse/1, serialise/1]).

-export([gen_connect/2,
         gen_connack/0,
         gen_connack/1,
         gen_publish/4,
         gen_puback/1,
         gen_pubrec/1,
         gen_pubrel/1,
         gen_pubcomp/1,
         gen_subscribe/3,
         gen_suback/2,
         gen_unsubscribe/2,
         gen_unsuback/1,
         gen_pingreq/0,
         gen_pingresp/0,
         gen_disconnect/0]).

%% frame types
-define(CONNECT,      1).
-define(CONNACK,      2).
-define(PUBLISH,      3).
-define(PUBACK,       4).
-define(PUBREC,       5).
-define(PUBREL,       6).
-define(PUBCOMP,      7).
-define(SUBSCRIBE,    8).
-define(SUBACK,       9).
-define(UNSUBSCRIBE, 10).
-define(UNSUBACK,    11).
-define(PINGREQ,     12).
-define(PINGRESP,    13).
-define(DISCONNECT,  14).

-define(RESERVED, 0).
-define(PROTOCOL_MAGIC_31, <<"MQIsdp">>).
-define(PROTOCOL_MAGIC_311, <<"MQTT">>).
-define(MAX_LEN, 16#fffffff).
-define(HIGHBIT, 2#10000000).
-define(LOWBITS, 2#01111111).

-define(MAX_PACKET_SIZE, 266338304).

-spec parse(binary()) -> {mqtt_frame(), binary()} | {error, binary()} | more.
parse(<<Fixed:1/binary, 0:1, L1:7, Data:L1/binary, Rest/binary>>) ->
    {parse(Fixed, Data), Rest};
parse(<<Fixed:1/binary, 1:1, L1:7, 0:1, L2:7, Data/binary>>) ->
    DataSize = L1 + (L2 bsl 7),
    case Data of
        <<Var:DataSize/binary, Rest/binary>> -> {parse(Fixed, Var), Rest};
        _ -> more
    end;
parse(<<Fixed:1/binary, 1:1, L1:7, 1:1, L2:7, 0:1, L3:7, Data/binary>>) ->
    DataSize = L1 + (L2 bsl 7) + (L3 bsl 14),
    case Data of
        <<Var:DataSize/binary, Rest/binary>> -> {parse(Fixed, Var), Rest};
        _ -> more<commit_msg>fixed parser for very small TCP segments<commit_after>-module(vmq_parser).
-include("vmq_types.hrl").
-export([parse/1, serialise/1]).

-export([gen_connect/2,
         gen_connack/0,
         gen_connack/1,
         gen_publish/4,
         gen_puback/1,
         gen_pubrec/1,
         gen_pubrel/1,
         gen_pubcomp/1,
         gen_subscribe/3,
         gen_suback/2,
         gen_unsubscribe/2,
         gen_unsuback/1,
         gen_pingreq/0,
         gen_pingresp/0,
         gen_disconnect/0]).

%% frame types
-define(CONNECT,      1).
-define(CONNACK,      2).
-define(PUBLISH,      3).
-define(PUBACK,       4).
-define(PUBREC,       5).
-define(PUBREL,       6).
-define(PUBCOMP,      7).
-define(SUBSCRIBE,    8).
-define(SUBACK,       9).
-define(UNSUBSCRIBE, 10).
-define(UNSUBACK,    11).
-define(PINGREQ,     12).
-define(PINGRESP,    13).
-define(DISCONNECT,  14).

-define(RESERVED, 0).
-define(PROTOCOL_MAGIC_31, <<"MQIsdp">>).
-define(PROTOCOL_MAGIC_311, <<"MQTT">>).
-define(MAX_LEN, 16#fffffff).
-define(HIGHBIT, 2#10000000).
-define(LOWBITS, 2#01111111).

-define(MAX_PACKET_SIZE, 266338304).

-spec parse(binary()) -> {mqtt_frame(), binary()} | {error, binary()} | more.
parse(<<Fixed:1/binary, 0:1, L1:7, Data/binary>>) ->
    case Data of
        <<Var:L1/binary, Rest/binary>> -> {parse(Fixed, Var), Rest};
        _ -> more
    end;
parse(<<Fixed:1/binary, 1:1, L1:7, 0:1, L2:7, Data/binary>>) ->
    DataSize = L1 + (L2 bsl 7),
    case Data of
        <<Var:DataSize/binary, Rest/binary>> -> {parse(Fixed, Var), Rest};
        _ -> more
    end;
parse(<<Fixed:1/binary, 1:1, L1:7, 1:1, L2:7, 0:1, L3:7, Data/binary>>) ->
    DataSize = L1 + (L2 bsl 7) + (L3 bsl 14),
    case Data of
        <<Var:DataSize/binary, Rest/binary>> -> {parse(Fixed, Var), Rest};
        _ -> more
{'fraction_non_alphanumeric': 0.1866137266023823, 'fraction_numerical': 0.061259217243335225, 'mean_word_length': 2.5662285136501515, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 6, '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': '307081', 'n_tokens_mistral': 1511, 'n_tokens_neox': 1422, 'n_words': 259}