cracode 1.0.1

A binary serialization / deserialization strategy for transforming structs into bytes and vice versa!
Documentation
// https://github.com/cracode-org/cracode/issues/618

use cracode::{Decode, Encode};
use criterion::{criterion_group, criterion_main, Criterion};
use serde::{Deserialize, Serialize};
use std::hint::black_box;

#[derive(Serialize, Deserialize, Default, Encode, Decode)]
pub struct MyStruct {
    pub v: Vec<String>,
    pub string: String,
    pub number: usize,
}

impl MyStruct {
    #[inline]
    pub fn new(v: Vec<String>, string: String, number: usize) -> Self {
        Self {
            v,
            string,
            number,
        }
    }
}

fn build_data(size: usize) -> Vec<MyStruct> {
    (0..size)
        .map(|i| {
            let vec: Vec<String> = (0..i).map(|i| i.to_string().repeat(100)).collect();
            MyStruct::new(vec, size.to_string(), size)
        })
        .collect()
}

fn index_item_decode(c: &mut Criterion) {
    let data = build_data(100);

    let config = cracode::config::standard();
    c.bench_function("bench v2 (standard)", |b| {
        b.iter(|| {
            let _ = black_box(cracode::encode_to_vec(black_box(&data), config)).unwrap();
        });
    });

    let config = cracode::config::legacy();
    c.bench_function("bench v2 (legacy)", |b| {
        b.iter(|| {
            let _ = black_box(cracode::encode_to_vec(black_box(&data), config)).unwrap();
        });
    });

    let encodedv2 = cracode::encode_to_vec(&data, config).unwrap();

    c.bench_function("bench v2 decode (legacy)", |b| {
        b.iter(|| {
            let _: (Vec<MyStruct>, _) = std::hint::black_box(cracode::decode_from_slice(
                std::hint::black_box(&encodedv2),
                config,
            ))
            .unwrap();
        });
    });
}

criterion_group!(benches, index_item_decode);
criterion_main!(benches);