{"id":16005385,"url":"https://github.com/64kramsystem/serdine","last_synced_at":"2025-04-05T02:13:20.726Z","repository":{"id":57794676,"uuid":"527926569","full_name":"64kramsystem/serdine","owner":"64kramsystem","description":"Tiny serialization library for de/serializing instances in a binary, serial format; useful for example to easily interface with C program data files","archived":false,"fork":false,"pushed_at":"2022-09-06T17:47:38.000Z","size":524,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-11T02:25:00.545Z","etag":null,"topics":["c","derive","memory","rust","serialization"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/64kramsystem.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-08-23T09:48:16.000Z","updated_at":"2022-09-04T20:35:13.000Z","dependencies_parsed_at":"2022-08-24T09:41:21.329Z","dependency_job_id":null,"html_url":"https://github.com/64kramsystem/serdine","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/64kramsystem%2Fserdine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/64kramsystem%2Fserdine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/64kramsystem%2Fserdine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/64kramsystem%2Fserdine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/64kramsystem","download_url":"https://codeload.github.com/64kramsystem/serdine/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247276189,"owners_count":20912288,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","derive","memory","rust","serialization"],"created_at":"2024-10-08T11:04:19.632Z","updated_at":"2025-04-05T02:13:20.707Z","avatar_url":"https://github.com/64kramsystem.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Logo](/images/serdine.jpg?raw=true)\n\n# Serdine\n\nSerdine is a tiny serialization library for de/serializing instances in a binary, serial format, focused on ease of use.\n\nThis is convenient for example, when interfacing with data files belonging to C programs, where the files are often the image of the in-memory instances.\n\n## Status\n\nThis library is currently used by another project of mine ([Catacomb II-64k](https://github.com/64kramsystem/catacomb_ii-64k)), so I don't need to add any new feature, however, if anybody happened to find it useful, I can easily extend it.\n\nSome ideas:\n\n- [ ] Add support for tuple structs support\n- [ ] Add support for unions\n- [ ] Add support for packed structs\n- [ ] Add support for big endian (as feature)\n- [ ] Make `no_std`\n- [ ] Automatically implement `Vec\u003c_\u003e` when it's the last field\n\n## Design and examples\n\nThe crate provides de/serialization implementations for the numeric primites and arrays, in little endian format; any field, particularly those of user-defined types, can use a custom de/serialization function.\nDe/serialization is recursive, so any type can be nested.\n\nThe de/serialization traits are extremely simple:\n\n```rs\npub trait Serialize {\n    fn serialize\u003cW: Write\u003e(\u0026self, w: W) -\u003e Result\u003c(), std::io::Error\u003e;\n}\n\npub trait Deserialize {\n    fn deserialize\u003cR: Read\u003e(r: R) -\u003e Result\u003cSelf, std::io::Error\u003e;\n}\n```\n\nThe following are examples of de/serialization:\n\n```rs\nuse serdine_derive::Deserialize;\n\n#[derive(Deserialize)]\npub struct MyNamedFieldsStruct {\n    pub my_i16: i16,\n    pub my_u32: u32,\n    pub my_f32: f32,\n    pub my_f64: f64,\n    pub my_arr: [u16; 2],\n    pub my_bool: bool,\n    #[deserialize = \"deserialize_vec\"]\n    pub my_vec: Vec\u003cu8\u003e,\n}\n\nfn deserialize_vec\u003cR: std::io::Read\u003e(mut r: R) -\u003e Result\u003cVec\u003cu8\u003e, std::io::Error\u003e {\n    let mut buffer = Vec::new();\n    r.read_to_end(\u0026mut buffer)?;\n    Ok(buffer)\n}\n\nfn deserialize_named_fields_struct() {\n    let serialized_bytes: \u0026[u8] = \u0026[\n        0x80, 0x00,\n        0xBE, 0xBA, 0xFE, 0xCA,\n        0xC9, 0x3E, 0x7B, 0x44,\n        0x0C, 0x07, 0x42, 0xB2, 0x80, 0x19, 0x24, 0x40,\n        0x00, 0x01, 0x02, 0x03,\n        0xCA,\n        0x04, 0x05, 0x06\n    ];\n\n    let instance = MyNamedFieldsStruct::deserialize(serialized_bytes).unwrap();\n\n    assert_eq!(0x80,                        instance.my_i16);\n    assert_eq!(0xCAFEBABE,          instance.my_u32);\n    assert_eq!(1004.981_f32,        instance.my_f32);\n    assert_eq!(10.04981_f64,        instance.my_f64);\n    assert_eq!([0x0100, 0x0302], instance.my_arr);\n    assert_eq!(true,                          instance.my_bool);\n    assert_eq!(vec![4, 5, 6],           instance.my_vec);\n}\n```\n\n```rs\n// Enums are supported, as long as they declare their representation.\n\n#[derive(Serialize)]\n#[repr(u16)]\nenum MyEnum {\n    VarA = 0,\n    VarB = 1,\n    VarC = 65534,\n}\n\nfn serialize_enum() {\n    let mut serialized_instance = Vec::new();\n\n    MyEnum::VarA.serialize(\u0026mut serialized_instance).unwrap();\n    MyEnum::VarC.serialize(\u0026mut serialized_instance).unwrap();\n    MyEnum::VarB.serialize(\u0026mut serialized_instance).unwrap();\n\n    let expected_bytes: \u0026[u8] = \u0026[\n        0x00, 0x00,\n        0xFE, 0xFF,\n        0x01, 0x00,\n    ];\n\n    assert_eq!(expected_bytes, serialized_instance);\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F64kramsystem%2Fserdine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F64kramsystem%2Fserdine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F64kramsystem%2Fserdine/lists"}