{"id":21188174,"url":"https://github.com/dev1an/simple-framer","last_synced_at":"2025-07-29T21:40:49.480Z","repository":{"id":90135064,"uuid":"302480540","full_name":"Dev1an/Simple-Framer","owner":"Dev1an","description":"Delimiting NWProtocolFramer example","archived":false,"fork":false,"pushed_at":"2020-10-08T23:19:58.000Z","size":7,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-21T13:09:33.268Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Swift","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/Dev1an.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":"2020-10-08T23:01:57.000Z","updated_at":"2024-06-25T16:57:18.000Z","dependencies_parsed_at":null,"dependency_job_id":"da00eb3b-791b-4024-b763-bcc2abc9ad12","html_url":"https://github.com/Dev1an/Simple-Framer","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/Dev1an%2FSimple-Framer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dev1an%2FSimple-Framer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dev1an%2FSimple-Framer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dev1an%2FSimple-Framer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Dev1an","download_url":"https://codeload.github.com/Dev1an/Simple-Framer/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243640712,"owners_count":20323712,"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":[],"created_at":"2024-11-20T18:42:53.328Z","updated_at":"2025-03-14T20:24:21.915Z","avatar_url":"https://github.com/Dev1an.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# How to write a NWProtocolFramer for Network.framework that splits streams into frames using a delimiter?\n\nI tried to create a framer that splits a stream of ASCII bytes into frames separated by the pipe ascii character: `\"|\"`. This framer is located in [/Sources/SimpleFramer/SimpleFramer.swift](/Sources/SimpleFramer/SimpleFramer.swift)\n\nThe problem is that from the moment I get a chunk that does not end with `\"|\"`, the framer gets stuck on that chunk. So the other chunks that come after this incomplete chunk never fully arrive in the `framer.parseInput(...)` call. Because it always parses chunks of `minimumIncompleteLength` and hence never arrives to the point where the next `\"|\"` is.\n\nHere is a simple reproduction of this problem:\n\n 1. Create a TCP server\n 2. Setup the server so that it sends chunks of messages when a client connects.\n 3. Connect to the server (created in 1.) using the framer from above.\n 4. Start receiving messages.\n\nThe code for this reproduction is located in [/Tests/SimpleFramerTests/SimpleFramerTests.swift](/Tests/SimpleFramerTests/SimpleFramerTests.swift) and can be run using the following command in the terminal\n\n```shell\nswift test\n```\n\nAnd produces the following console output:\n\n```\n🖲 server: waiting(POSIXErrorCode: Network is down)\n🖲 server: ready\n🖲 server: listening on 54907\n👨‍💻 client: preparing\n👨‍💻 client: ready\n👨‍💻 client: receiving\n🖲 server: new connection from ::1.52957\n🖲 server (client ::1.52957): state setup\n🖲 server (client ::1.52957): state ready\n🖲 server: sending\n🖲 server: sending \"A|Be||Split in\" 🖲\n👨‍💻 client: handle input\n👨‍💻 client:\t\tparsing buffer: \"A|Be||Split in\"\n👨‍💻 client:\t\tminLength set to 1\n👨‍💻 client:\t\tparsing buffer: \"Be||Split in\"\n👨‍💻 client:\t\tminLength set to 1\n👨‍💻 client:\t\tparsing buffer: \"|Split in\"\n👨‍💻 client:\t\tminLength set to 1\n👨‍💻 client:\t\tparsing buffer: \"Split in\"\n👨‍💻 client:\t\tminLength set to 9\n👨‍💻 client: handle input\n👨‍💻 client:\t\tparsing buffer: \"\"\n👨‍💻 client:\t\tminLength set to 1\n👨‍💻 client: received \"A\" Optional(Network.NWConnection.ContentContext) true No error\n👨‍💻 client: received \"Be\" Optional(Network.NWConnection.ContentContext) true No error\n👨‍💻 client: received \"\u003cno data\u003e\" Optional(Network.NWConnection.ContentContext) true No error\n👨‍💻 client: handle input\n👨‍💻 client:\t\tparsing buffer: \"Split in\"\n👨‍💻 client:\t\tminLength set to 9\n🖲 server: sending \" the middle|\" 🖲\n👨‍💻 client: handle input\n👨‍💻 client:\t\tparsing buffer: \"Split in \"\n👨‍💻 client:\t\tminLength set to 10\n👨‍💻 client: handle input\n👨‍💻 client:\t\tparsing buffer: \"Split in t\"\n👨‍💻 client:\t\tminLength set to 11\n🖲 server: sending \"0|Done\" 🖲\n👨‍💻 client: handle input\n👨‍💻 client:\t\tparsing buffer: \"Split in th\"\n👨‍💻 client:\t\tminLength set to 12\n👨‍💻 client: handle input\n👨‍💻 client:\t\tparsing buffer: \"Split in the\"\n👨‍💻 client:\t\tminLength set to 13\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdev1an%2Fsimple-framer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdev1an%2Fsimple-framer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdev1an%2Fsimple-framer/lists"}