{"id":15373063,"url":"https://github.com/vi/simple_cbor_stream_parse","last_synced_at":"2025-09-09T06:55:08.891Z","repository":{"id":137140207,"uuid":"107887262","full_name":"vi/simple_cbor_stream_parse","owner":"vi","description":"Simple low-level streamed callback-based CBOR push parser in C and C++","archived":false,"fork":false,"pushed_at":"2017-10-23T14:11:02.000Z","size":52,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-15T14:13:41.777Z","etag":null,"topics":["callbacks","cbor","parser","push-parser","rfc-7049"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-10-22T17:27:20.000Z","updated_at":"2025-01-16T08:21:47.000Z","dependencies_parsed_at":null,"dependency_job_id":"c51e28ca-49c7-44fb-89d7-6c27c4f2bb12","html_url":"https://github.com/vi/simple_cbor_stream_parse","commit_stats":{"total_commits":23,"total_committers":1,"mean_commits":23.0,"dds":0.0,"last_synced_commit":"4530d546d441359f3345ecab40131161b3d1aa8a"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/vi/simple_cbor_stream_parse","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vi%2Fsimple_cbor_stream_parse","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vi%2Fsimple_cbor_stream_parse/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vi%2Fsimple_cbor_stream_parse/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vi%2Fsimple_cbor_stream_parse/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vi","download_url":"https://codeload.github.com/vi/simple_cbor_stream_parse/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vi%2Fsimple_cbor_stream_parse/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274259114,"owners_count":25251631,"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","status":"online","status_checked_at":"2025-09-09T02:00:10.223Z","response_time":80,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["callbacks","cbor","parser","push-parser","rfc-7049"],"created_at":"2024-10-01T13:54:12.274Z","updated_at":"2025-09-09T06:55:08.826Z","avatar_url":"https://github.com/vi.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# scsp - simple_cbor_stream_parse\n\nA simple low-level streamed callback-based [CBOR](https://cbor.io/) push parser in C.\n\nLicense = MIT or Apache 2.0\n\n## Features\n\n* No memory allocations, embedded-friendly.\n* Should work with 32-bit or 16-bit registers. Float support is also opt-out.\n* No buffering at all in low-level mode. You are in charge for buffering. Parse function expects [write(2)](http://man7.org/linux/man-pages/man2/write.2.html) semantics and process less bytes than you have pushed into it (including 0 bytes if there is not enough data).\n* Helper function to parse from a FD (with buffering) or from memory.\n* There is C++ binding. istream version has unavoidable buffering, low-level version requires allocation.\n\n## Concerns/Notes:\n\n* Nesting depth is statically limited\n* Unsigned numbers are represented as signed =\u003e can't handle access some extreme values\n* Not validating. Bytestrings and strings are handled similarly.\n* Strings and bytestrings are delivered in chunks which depend on how you push the data to the parser. String chunks may split UTF-8 characters in pieces.\n* There is no CBOR generator here, only parser\n* Not entire \"Appenfix A\" testsuite passes due to forced signed numbers\n\n## How to use\n\n### C\n\n1. Copy source files (`scsp.c` and `scsp.h`) into your project\n2. Define your callback functions (copy from some example). Note that strings may arrive in arbitrary chunks.\n3. Fill in `scsp_callbacks` structure (copy from some example)\n4. If you need to parse from entire file or from memory buffer, use `scsp_parse_from_fd` or `scsp_parse_from_memory`.\n5. If you need flexible parsing, create `scsp_state` structure, initialize it with zeroes and call `scsp_parse_lowlevel` in a loop. It will consume data bit by bit. One call corresponds to a few callbacks.\n\n### C++\n\n1. Copy source files `scsp.c`, `scsp_cpp.cpp`, `scsp.h` and `scsp_cpp.hpp` into your project\n2. Inherit from `scsp::Callbacks` interface or `scsp::CallbacksEmpty` class\n3. Override events you need to listen to\n4. For simple mode, use `parse_from_istream` / `parse_from_memory` / `parse_from_fd` functions. Note that istream version does buffering inside.\n5. For flexible mode, create `scsp::State` object with `new_state`, use `parse_lowlevel` (see fifth point in \"C\" version of \"How to use\") in a loop, then delete state object with delete_state.\n\n## Examples\n\n* cbor_to_jsonesque - read cbor from a file or stdin and dump something similar to JSON or CBOR diagnostic.\n* dump_scsp_events - dump each event in a separate line\n* [simple_example](/simple_example.c) - parse from memory and assert it works\n* [extract_strings](/extract_strings.cpp) - a C++ example. Prints all encountered strings.\n* roundtrip - a C++ example of copying a cbor file. Resulting CBOR is uncanonical.\n\n\n## Configurable parameters\n\n\n* SCSP_MAXDEPTH - maximum nesting depth of CBOR objects or strings. Should probably be 2-3 more than you plan to do. Defaults to 16.\n* SCSP_DEBUG, SCSP_DEBUG_STDERR - enable debugging output\n* SCSP_USERDATA - data passed to each callback. Defaults to `void*`\n* SCSP_EXPORT - just resides in signature of user-facing functions\n* SCSP_INT - primary data type for integers, lengths and return values. Defaults to int64_t.\n* SCSP_ENABLE_HELPERS - Enable some helper functions.\n* SCSP_ENABLE_FLOAT\n* SCSP_ENABLE_32BIT\n* SCSP_ENABLE_64BIT\n* SCSP_ENABLE_IOSTREAM - Enable additional features in C++ binding\n\n## Example of an scsp event stream\n\n`{\"bytes\": h'0102030405', 4: -6, true: 23.45, \"array\": [1, 1, 1]}`\n\n```\n00000000  a4 65 62 79 74 65 73 45  01 02 03 04 05 04 25 f5  |.ebytesE......%.|\n00000010  fb 40 37 73 33 33 33 33  33 65 61 72 72 61 79 83  |.@7s33333earray.|\n00000020  01 01 01                                          |...|\n00000023\n```\n\n```\nmap_opened(4)\nmap_key\nstring_open(5)\nstring_chunk(\"\\x62\\x79\\x74\\x65\\x73\")\nstring_close\nmap_value\nbytestring_open(5)\nbytestring_chunk(\"\\x01\\x02\\x03\\x04\\x05\")\nbytestring_close\nmap_key\ninteger(4)\nmap_value\ninteger(-6)\nmap_key\nsimple(T)\nmap_value\nnoninteger(23.45)\nmap_key\nstring_open(5)\nstring_chunk(\"\\x61\\x72\\x72\\x61\\x79\")\nstring_close\nmap_value\narray_opened(3)\narray_item\ninteger(1)\narray_item\ninteger(1)\narray_item\ninteger(1)\narray_closed\nmap_closed\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvi%2Fsimple_cbor_stream_parse","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvi%2Fsimple_cbor_stream_parse","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvi%2Fsimple_cbor_stream_parse/lists"}