{"id":51406216,"url":"https://github.com/italonery/zero-alloc-tcp-gateway","last_synced_at":"2026-07-04T11:02:25.994Z","repository":{"id":368983385,"uuid":"1287810253","full_name":"italonery/zero-alloc-tcp-gateway","owner":"italonery","description":"A high-performance, zero allocation TCP gateway for .NET. Built with System.IO.Pipelines and memory pooling to parse continuous binary telemetry streams without Garbage Collector pressure.","archived":false,"fork":false,"pushed_at":"2026-07-03T03:24:21.000Z","size":7,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-07-03T05:13:05.309Z","etag":null,"topics":["csharp","dotnet","high-performance","iot-gateway","memory-management","system-io-pipelines","tcp-server","zero-allocation"],"latest_commit_sha":null,"homepage":"","language":"C#","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/italonery.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-07-03T03:00:47.000Z","updated_at":"2026-07-03T03:24:25.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/italonery/zero-alloc-tcp-gateway","commit_stats":null,"previous_names":["italonery/zero-alloc-tcp-gateway"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/italonery/zero-alloc-tcp-gateway","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/italonery%2Fzero-alloc-tcp-gateway","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/italonery%2Fzero-alloc-tcp-gateway/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/italonery%2Fzero-alloc-tcp-gateway/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/italonery%2Fzero-alloc-tcp-gateway/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/italonery","download_url":"https://codeload.github.com/italonery/zero-alloc-tcp-gateway/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/italonery%2Fzero-alloc-tcp-gateway/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35118971,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-04T02:00:05.987Z","response_time":113,"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":["csharp","dotnet","high-performance","iot-gateway","memory-management","system-io-pipelines","tcp-server","zero-allocation"],"created_at":"2026-07-04T11:02:25.327Z","updated_at":"2026-07-04T11:02:25.985Z","avatar_url":"https://github.com/italonery.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Zero-Allocation TCP Gateway\n\nDesigned to handle continuous binary telemetry streams (e.g., IoT sensors, vehicle trackers) while completely eliminating Garbage Collector (GC) pressure using `System.IO.Pipelines`.\n\nTraditional TCP servers in C# often rely on allocating new `byte[]` arrays for every incoming network read. In high-throughput scenarios (thousands of devices sending telemetry every second), this naive approach causes massive Heap allocations, forcing the Garbage Collector to freeze the CPU to clean up short-lived objects.\n\nAdditionally, standard servers often fail to properly handle **TCP Fragmentation**—where a single logical message is split across multiple network packets.\n\n## Architecture\n\nThis gateway solves these critical infrastructure problems by leveraging modern .NET memory primitives:\n\n* **`System.IO.Pipelines`:** Replaces standard stream reading with a producer-consumer model that recycles contiguous blocks of memory from an internal `ArrayPool`.\n* **`ReadOnlySequence\u003cbyte\u003e`:** Acts as a virtual window over the network buffers, allowing us to slice and inspect TCP payloads without ever copying them into a new array.\n* **`SequenceReader\u003cbyte\u003e`:** Traverses the memory segments to safely extract binary headers, enforcing strict *Little-Endian* byte-order decoding while remaining completely allocated on the Stack (`ref struct`).\n\n## Binary Protocol Specification\n\nTo handle framing efficiently, the gateway enforces a strict 4-byte zero-allocation header for all incoming streams:\n\n| Offset | Size    | Type     | Description |\n| :---   | :---    | :---     | :--- |\n| `0`    | 1 byte  | `byte`   | **Magic Byte:** Fixed at `0xAA` to reject network noise/port scans. |\n| `1`    | 1 byte  | `byte`   | **Message Type:** Telemetry category (1 = Heartbeat, 2 = Location). |\n| `2`    | 2 bytes | `ushort` | **Payload Length:** Size of the upcoming payload (Little-Endian). |\n\n## Testing TCP Fragmentation\n\nThe repository includes a byte-level `xUnit` test suite to mathematically prove Little-Endian parsing, as well as a real-time `Simulator` project.\n\nThe simulator explicitly generates severe TCP fragmentation by writing half a packet, pausing the thread, and writing the rest. The `GatewayServer` catches the incomplete buffer, waits without allocating memory, and perfectly slices the payload once the remaining bytes arrive.\n\n**Run the Simulator:**\n```bash\ndotnet run --project ZeroAlloc.TcpGateway.Simulator/ZeroAlloc.TcpGateway.Simulator.csproj\n```\n\n## License\nMIT © [Ítalo Nery](https://github.com/italonery)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitalonery%2Fzero-alloc-tcp-gateway","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fitalonery%2Fzero-alloc-tcp-gateway","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitalonery%2Fzero-alloc-tcp-gateway/lists"}