{"id":22680487,"url":"https://github.com/andrehrferreira/typescript-bytebuffer","last_synced_at":"2025-04-12T15:52:56.548Z","repository":{"id":244793405,"uuid":"786883009","full_name":"andrehrferreira/typescript-bytebuffer","owner":"andrehrferreira","description":"Class for reading and writing binary communication","archived":false,"fork":false,"pushed_at":"2024-08-23T19:20:15.000Z","size":20,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-26T10:21:24.646Z","etag":null,"topics":["byte","bytebuffer","bytebufferpool","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/andrehrferreira.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":"2024-04-15T13:36:50.000Z","updated_at":"2024-10-11T23:06:33.000Z","dependencies_parsed_at":"2024-08-23T20:15:19.504Z","dependency_job_id":"e4d38f17-1e2c-4549-b75b-2ff5508db461","html_url":"https://github.com/andrehrferreira/typescript-bytebuffer","commit_stats":null,"previous_names":["andrehrferreira/typescript-bytebuffer"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrehrferreira%2Ftypescript-bytebuffer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrehrferreira%2Ftypescript-bytebuffer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrehrferreira%2Ftypescript-bytebuffer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrehrferreira%2Ftypescript-bytebuffer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andrehrferreira","download_url":"https://codeload.github.com/andrehrferreira/typescript-bytebuffer/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248592085,"owners_count":21130175,"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":["byte","bytebuffer","bytebufferpool","typescript"],"created_at":"2024-12-09T19:13:50.507Z","updated_at":"2025-04-12T15:52:56.523Z","avatar_url":"https://github.com/andrehrferreira.png","language":"TypeScript","readme":"# @tos/bytebuffer\r\n\r\n`@tos/bytebuffer` is a lightweight and efficient library for managing binary data in TypeScript. It provides functionalities for reading, writing, queuing, and pooling buffers, along with support for generic network connectors (TCP, UDP, WebSocket).\r\n\r\n## Installation\r\n\r\nTo install the library via npm, run:\r\n\r\n```bash\r\nnpm install @tos/bytebuffer\r\n```\r\n\r\n## Features\r\n\r\n- Efficient binary data manipulation with `ByteBuffer`.\r\n- Buffer aggregation with `QueueBuffer` to reduce header overhead.\r\n- Buffer pooling with `ByteBufferPool` to optimize memory allocation in high-frequency systems.\r\n- Interface for generic network connectors supporting TCP, UDP, and WebSocket.\r\n\r\n## Usage Example\r\n\r\nHere is a basic example of how to use the API provided by the library for binary buffer manipulation:\r\n\r\n```typescript\r\nimport { ByteBuffer, ByteBufferPool, QueueBuffer } from '@tos/bytebuffer';\r\n\r\n// Initializing a ByteBuffer\r\nconst buffer = new ByteBuffer();\r\nbuffer.putInt32(1234).putString(\"Hello, ByteBuffer!\");\r\n\r\nconst num = buffer.getInt32();\r\nconst str = buffer.getString();\r\n\r\nconsole.log(num);  // 1234\r\nconsole.log(str);  // \"Hello, ByteBuffer!\"\r\n\r\n// Using ByteBufferPool to manage buffers\r\nconst pool = new ByteBufferPool();\r\nconst pooledBuffer = pool.acquire();\r\npooledBuffer.putFloat(3.14);\r\npool.release(pooledBuffer);\r\n\r\n// Aggregating buffers with QueueBuffer\r\nconst queue = new QueueBuffer();\r\nqueue.enqueue(buffer);\r\nqueue.enqueue(pooledBuffer);\r\n\r\nconst combinedBuffer = queue.combine();\r\n```\r\n\r\n## API\r\n\r\n### `ByteBuffer`\r\n\r\nThe main class for managing binary data. It provides methods for reading and writing various types of binary data.\r\n\r\n- **`putInt32(value: number): ByteBuffer`**: Inserts a 32-bit integer into the buffer.\r\n- **`getInt32(): number`**: Reads a 32-bit integer from the buffer.\r\n- **`putString(value: string): ByteBuffer`**: Inserts a UTF-8 encoded string into the buffer.\r\n- **`getString(): string`**: Reads a UTF-8 encoded string from the buffer.\r\n- **`reset(): void`**: Resets the buffer's position for reuse.\r\n\r\n### `QueueBuffer`\r\n\r\nAggregates multiple binary buffers to reduce header overhead in packet transmissions.\r\n\r\n- **`enqueue(buffer: ByteBuffer): void`**: Adds a buffer to the queue.\r\n- **`combine(): ByteBuffer`**: Combines all enqueued buffers into a single buffer.\r\n\r\n### `ByteBufferPool`\r\n\r\nManages a pool of `ByteBuffer` instances to avoid frequent memory allocations, optimizing performance in high-load systems.\r\n\r\n- **`acquire(): ByteBuffer`**: Retrieves a buffer from the pool or creates a new one if necessary.\r\n- **`release(buffer: ByteBuffer): void`**: Returns a buffer to the pool, making it available for reuse.\r\n\r\n### Generic Connector Interface\r\n\r\nInterface for creating generic network adapters that support TCP, UDP, and WebSocket.\r\n\r\n- Supports socket creation and handling binary data packets.\r\n- Integration with `ByteBuffer` for easy manipulation of network data.\r\n\r\n## Contribution\r\n\r\nContributions are welcome! If you encounter any issues or have suggestions for improvements, feel free to open an issue or submit a pull request.\r\n\r\n## License\r\n\r\nThis project is licensed under the [MIT License](LICENSE).\r\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrehrferreira%2Ftypescript-bytebuffer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandrehrferreira%2Ftypescript-bytebuffer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrehrferreira%2Ftypescript-bytebuffer/lists"}