fn decode_parser<'a, Input>(
) -> impl Parser<Input, Output = JournalRecord, PartialState = AnyPartialState> + 'a
where
    Input: RangeStream<Token = u8, Range = &'a [u8]> + 'a,
    // Necessary due to rust-lang/rust#24159
    Input::Error: ParseError<Input::Token, Input::Range, Input::Position>,
{
    /*
    Two journal entries that follow each other are separated by a double newline.

     Journal fields consisting only of valid non-control UTF-8 codepoints are serialized as they are:
         field name, followed by '=', followed by field data, followed by a newline as separator to the next field.
     Other journal fields are serialized in a special binary safe way:
         field name, followed by newline, followed by a binary 64bit little endian size value, followed by the binary field data,
         followed by a newline as separator to the next field.
     Entry metadata that is not actually a field is serialized like it was a field, but beginning with two underscores.
     More specifically, __CURSOR=, __REALTIME_TIMESTAMP=, __MONOTONIC_TIMESTAMP= are introduced this way.
     The order in which fields appear in an entry is undefined and might be different for each entry that is serialized.

     And that's it.
     */

    any_partial_state(
        (
            many1::<std::collections::HashMap<_, _>, _, _>(
                (
                    // Get the key
                    recognize(skip_many1(choice((alpha_num(), token(b'_'))))).and_then(
                        |bytes: &[u8]| {
                            std::str::from_utf8(bytes)
                                .map(|s| s.to_string())
                                .map_err(StreamErrorFor::<Input>::other)
                        },
                    ),
                    // Get the Value
                    one_of(b"=\n"[..].iter().copied()).then_partial(|&mut c| {
                        // If the k/v separator is a = it's just utf8
                        if c == b'=' {
                            recognize(skip_many(none_of(b"\n".iter().copied())))
                                .and_then(|bytes: &[u8]| {
                                    std::str::from_utf8(bytes)
                                        .map(|s| FieldValue::Utf8(s.to_string()))
                                        .map_err(StreamErrorFor::<Input>::other)
                                })
                                .left()
                        } else {
                            // else it must be a newline, therefor treat it as bytes
                            le_u64()
                                .then_partial(|vlen: &mut u64| {
                                    let vlen: usize = (*vlen).try_into().unwrap();
                                    take(vlen)
                                        .map(|bytes: &[u8]| FieldValue::Bytes(bytes.to_owned()))
                                })
                                .right()
                        }
                    }),
                    // lines within an entry are line separated
                    token(b'\n'),
                )
                    .map(|(key, value, _)| (key, value)),
            ),
            // entries are line separated
            token(b'\n'),
        )
            .map(|(kvs, _)| kvs),
    )
}
// The actual parser for the journald export format
The actual parser for the journald export format
The actual parser for the journald export format
fn decode_parser<'a, Input>(
) -> impl Parser<Input, Output = JournalRecord, PartialState = AnyPartialState> + 'a
where
    Input: RangeStream<Token = u8, Range = &'a [u8]> + 'a,
    // Necessary due to rust-lang/rust#24159
    Input::Error: ParseError<Input::Token, Input::Range, Input::Position>,
{
    /*
    Two journal entries that follow each other are separated by a double newline.
     Journal fields consisting only of valid non-control UTF-8 codepoints are serialized as they are:
         field name, followed by '=', followed by field data, followed by a newline as separator to the next field.
     Other journal fields are serialized in a special binary safe way:
         field name, followed by newline, followed by a binary 64bit little endian size value, followed by the binary field data,
         followed by a newline as separator to the next field.
     Entry metadata that is not actually a field is serialized like it was a field, but beginning with two underscores.
     More specifically, __CURSOR=, __REALTIME_TIMESTAMP=, __MONOTONIC_TIMESTAMP= are introduced this way.
     The order in which fields appear in an entry is undefined and might be different for each entry that is serialized.
     And that's it.
     */
    any_partial_state(
        (
            many1::<std::collections::HashMap<_, _>, _, _>(
                (
                    // Get the key
                    recognize(skip_many1(choice((alpha_num(), token(b'_'))))).and_then(
                        |bytes: &[u8]| {
                            std::str::from_utf8(bytes)
                                .map(|s| s.to_string())
                                .map_err(StreamErrorFor::<Input>::other)
                        },
                    ),
                    // Get the Value
                    one_of(b"=\n"[..].iter().copied()).then_partial(|&mut c| {
                        // If the k/v separator is a = it's just utf8
                        if c == b'=' {
                            recognize(skip_many(none_of(b"\n".iter().copied())))
                                .and_then(|bytes: &[u8]| {
                                    std::str::from_utf8(bytes)
                                        .map(|s| FieldValue::Utf8(s.to_string()))
                                        .map_err(StreamErrorFor::<Input>::other)
                                })
                                .left()
                        } else {
                            // else it must be a newline, therefor treat it as bytes
                            le_u64()
                                .then_partial(|vlen: &mut u64| {
                                    let vlen: usize = (*vlen).try_into().unwrap();
                                    take(vlen)
                                        .map(|bytes: &[u8]| FieldValue::Bytes(bytes.to_owned()))
                                })
                                .right()
                        }
                    }),
                    // lines within an entry are line separated
                    token(b'\n'),
                )
                    .map(|(key, value, _)| (key, value)),
            ),
            // entries are line separated
            token(b'\n'),
        )
            .map(|(kvs, _)| kvs),
    )
}
fn decode_parser < ' a , Input > ( ) -> impl Parser < Input , Output = JournalRecord , PartialState = AnyPartialState > + ' a where Input : RangeStream < Token = u8 , Range = & ' a [ u8 ] > + ' a , // Necessary due to rust-lang/rust#24159 Input :: Error : ParseError < Input :: Token , Input :: Range , Input :: Position > , { /*
    Two journal entries that follow each other are separated by a double newline.

     Journal fields consisting only of valid non-control UTF-8 codepoints are serialized as they are:
         field name, followed by '=', followed by field data, followed by a newline as separator to the next field.
     Other journal fields are serialized in a special binary safe way:
         field name, followed by newline, followed by a binary 64bit little endian size value, followed by the binary field data,
         followed by a newline as separator to the next field.
     Entry metadata that is not actually a field is serialized like it was a field, but beginning with two underscores.
     More specifically, __CURSOR=, __REALTIME_TIMESTAMP=, __MONOTONIC_TIMESTAMP= are introduced this way.
     The order in which fields appear in an entry is undefined and might be different for each entry that is serialized.

     And that's it.
     */ any_partial_state ( ( many1 :: < std :: collections :: HashMap < _ , _ > , _ , _ > ( ( // Get the key recognize ( skip_many1 ( choice ( ( alpha_num ( ) , token ( b'_' ) ) ) ) ) . and_then ( | bytes : & [ u8 ] | { std :: str :: from_utf8 ( bytes ) . map ( | s | s . to_string ( ) ) . map_err ( StreamErrorFor :: < Input > :: other ) } , ) , // Get the Value one_of ( b" \n " [ .. ] . iter ( ) . copied ( ) ) . then_partial ( | & mut c | { // If the k/v separator is a = it's just utf8 if c == b'=' { recognize ( skip_many ( none_of ( b" \n " . iter ( ) . copied ( ) ) ) ) . and_then ( | bytes : & [ u8 ] | { std :: str :: from_utf8 ( bytes ) . map ( | s | FieldValue :: Utf8 ( s . to_string ( ) ) ) . map_err ( StreamErrorFor :: < Input > :: other ) } ) . left ( ) } else { // else it must be a newline, therefor treat it as bytes le_u64 ( ) . then_partial ( | vlen : & mut u64 | { let vlen : usize = ( * vlen ) . try_into ( ) . unwrap ( ) ; take ( vlen ) . map ( | bytes : & [ u8 ] | FieldValue :: Bytes ( bytes . to_owned ( ) ) ) } ) . right ( ) } } ) , // lines within an entry are line separated token ( b'\n' ) , ) . map ( | ( key , value , _ ) | ( key , value ) ) , ) , // entries are line separated token ( b'\n' ) , ) . map ( | ( kvs , _ ) | kvs ) , ) }
The actual parser for the journald export format
The actual parser for the journald export format