{"id":20975848,"url":"https://github.com/banyc/field_block","last_synced_at":"2025-10-25T05:47:18.533Z","repository":{"id":60412939,"uuid":"542638208","full_name":"Banyc/field_block","owner":"Banyc","description":"A definition language for buffer parsing. No code gen. Restrict business code to outside of the codec.","archived":false,"fork":false,"pushed_at":"2022-10-02T14:54:03.000Z","size":49,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-28T13:17:05.664Z","etag":null,"topics":["codec","network","parsing","runtime","zero-copy"],"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/Banyc.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-09-28T14:39:25.000Z","updated_at":"2022-10-02T14:35:15.000Z","dependencies_parsed_at":"2022-09-29T07:40:22.820Z","dependency_job_id":null,"html_url":"https://github.com/Banyc/field_block","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Banyc%2Ffield_block","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Banyc%2Ffield_block/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Banyc%2Ffield_block/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Banyc%2Ffield_block/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Banyc","download_url":"https://codeload.github.com/Banyc/field_block/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243374326,"owners_count":20280661,"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":["codec","network","parsing","runtime","zero-copy"],"created_at":"2024-11-19T04:47:48.274Z","updated_at":"2025-10-25T05:47:13.504Z","avatar_url":"https://github.com/Banyc.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Field Block\n\nA definition language for buffer parsing.\n\n## Usage\n\nAdding this crate to a project:\n\n```bash\ncargo add field_block\n```\n\nDefining fields for a buffer:\n\n```rust\nfn get_block() -\u003e Block\u003cName\u003e {\n    let mut block = Block::new();\n    block.add_field(\n        Name::FixedVarInt, //\n        Def::VarInt(U64::Fixed(0xdeadbeef)),\n    );\n    block.add_field(\n        Name::VarInt, //\n        Def::VarInt(U64::Var),\n    );\n    block.add_field(\n        Name::BytesFixedLen, //\n        Def::Bytes(Len::Fixed(1)),\n    );\n    block.add_field(\n        Name::BytesVarLen, //\n        Def::Bytes(Len::Var),\n    );\n    block.add_field(\n        Name::FixedBytes, //\n        Def::FixedBytes(vec![0xba, 0xad, 0xf0, 0x0d]),\n    );\n    block\n}\n\n#[derive(Debug, PartialEq, Eq, Hash, Clone)]\nenum Name {\n    FixedVarInt,\n    VarInt,\n    BytesFixedLen,\n    BytesVarLen,\n    FixedBytes,\n}\n\nimpl FieldName for Name {}\n```\n\nEncoding a buffer:\n\n```rust\nlet block = get_block();\n\nlet mut values = HashMap::new();\nvalues.insert(Name::VarInt, Val::VarInt(0x1234));\nlet vec = vec![1];\nvalues.insert(Name::BytesFixedLen, Val::Bytes(\u0026vec));\nlet vec = vec![1, 2, 3];\nvalues.insert(Name::BytesVarLen, Val::Bytes(\u0026vec));\n\nlet mut vec = vec![0; 1024];\n\nlet end = block.to_bytes(\u0026values, \u0026mut vec).unwrap();\n```\n\nDecoding a buffer:\n\n```rust\nlet block = get_block();\n\nlet vec = vec![0 | 0xc0, 0, 0, 0, 0xde, 0xad, 0xbe, 0xef, 0x12 | 0x40, 0x34, 1, 3, 1, 2, 3, 0xba, 0xad, 0xf0, 0x0d];\n\nlet mut values = HashMap::new();\n\nlet end = block.to_values(\u0026vec, \u0026mut values).unwrap();\n\nlet ValInfo { value, pos } = values.get(\u0026Name::VarInt).unwrap();\nlet value = value.varint().unwrap();\n\nprintln!(\"Field VarInt has a value {} at pos {}\", value, pos);\n```\n\nSee unit tests for examples.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbanyc%2Ffield_block","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbanyc%2Ffield_block","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbanyc%2Ffield_block/lists"}