{"id":19854611,"url":"https://github.com/hasirciogli/hoffer","last_synced_at":"2025-10-06T20:53:30.188Z","repository":{"id":244806968,"uuid":"816328358","full_name":"hasirciogli/Hoffer","owner":"hasirciogli","description":"Hoffer.ts: Network Data Serialization and Deserialization Library  This TypeScript library, Hoffer.ts, provides a convenient and efficient way to serialize and deserialize various data types for network communication. It offers functionalities for both writing and reading data in a structured format, making it ideal for building network protocols.","archived":false,"fork":false,"pushed_at":"2024-06-17T14:37:03.000Z","size":6670,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-18T14:34:50.334Z","etag":null,"topics":["buffer","client","cloud","network","protocol","server","tcp","transfer","ttl"],"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/hasirciogli.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-06-17T14:14:39.000Z","updated_at":"2024-08-14T20:09:28.000Z","dependencies_parsed_at":"2024-06-17T15:59:20.770Z","dependency_job_id":"cfa4a8f4-e11f-4d46-bc62-2448ea6892ae","html_url":"https://github.com/hasirciogli/Hoffer","commit_stats":null,"previous_names":["hasirciogli/hoffer"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/hasirciogli/Hoffer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hasirciogli%2FHoffer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hasirciogli%2FHoffer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hasirciogli%2FHoffer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hasirciogli%2FHoffer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hasirciogli","download_url":"https://codeload.github.com/hasirciogli/Hoffer/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hasirciogli%2FHoffer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278678902,"owners_count":26027052,"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-10-06T02:00:05.630Z","response_time":65,"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":["buffer","client","cloud","network","protocol","server","tcp","transfer","ttl"],"created_at":"2024-11-12T14:09:56.308Z","updated_at":"2025-10-06T20:53:30.150Z","avatar_url":"https://github.com/hasirciogli.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Hoffer Library\n\n**Hoffer.ts: Network Data Serialization and Deserialization Library**\n\nThis TypeScript library, `Hoffer.ts`, provides a convenient and efficient way to serialize and deserialize various data types for network communication. It offers functionalities for both writing and reading data in a structured format, making it ideal for building network protocols or exchanging data between applications.\n\n**Key Features:**\n\n- **Supported Data Types:** Handles numbers, strings, doubles, bytes, and byte arrays.\n- **Write Methods:**\n    - `putNumber(value: number)`: Writes an integer value.\n    - `putString(value: string)`: Writes a string, preceded by its length.\n    - `putDouble(value: number)`: Writes a double-precision floating-point number.\n    - `putByte(value: number)`: Writes a single byte value.\n    - `putByteArray(value: number[])`: Writes an array of bytes.\n    - `putValue(type: string, value: any)`: Generic method for writing data based on type.\n- **Read Methods:**\n    - `getNumber()`: Reads an integer value.\n    - `getString()`: Reads a string, respecting its preceding length.\n    - `getDouble()`: Reads a double-precision floating-point number.\n    - `getByte()`: Reads a single byte value.\n    - `getByteArray()`: Reads an array of bytes.\n    - `getValue(type: string)`: Generic method for reading data based on type.\n- **Buffer Management:**\n    - `reset()`: Clears the internal buffer for reuse.\n    - `getData()`: Retrieves the current data buffer for sending.\n    - `setData(data: Buffer)`: Sets the internal buffer with received data for reading.\n- **Network Integration:**\n    - `sendData(socket: net.Socket)`: Sends the data buffer through a provided socket connection (example usage provided, but requires `net` module import).\n\n## Installation\n\nEnsure you have Node.js and TypeScript installed. You can install the required dependencies using npm or yarn:\n\n```\nnpm install\n# or\nyarn install\n```\n\n## Usage\n\n### Importing the Class\n\nFirst, import the `Hoffer` class in your TypeScript file:\n\n```typescript\nimport { Hoffer } from 'hoffer';\n```\nor\n```js\nconst { Hoffer } = require(\"hoffer\")\n```\n\n### Writing Data\n\nYou can write various data types to the buffer using the provided methods:\n\n```typescript\nconst hoffer = new Hoffer();\n\nhoffer.putNumber(123);\nhoffer.putString(\"John Doe\");\nhoffer.putDouble(4567.89);\nhoffer.putByte(0x1F);\nhoffer.putByteArray([0x01, 0x02, 0x03, 0x04]);\n\n// Using putValue for dynamic type handling\nhoffer.putValue('number', 42);\nhoffer.putValue('string', \"Hello, World!\");\nhoffer.putValue('double', 3.14159);\nhoffer.putValue('byte', 0x2A);\nhoffer.putValue('byteArray', [0x10, 0x20, 0x30]);\n```\n\n### Reading Data\n\nRead the data back from the buffer:\n\n```typescript\nconst readHoffer = new Hoffer();\nreadHoffer.setData(data); // the data == buffer\n\nconst id = readHoffer.getNumber();\nconst name = readHoffer.getString();\nconst balance = readHoffer.getDouble();\nconst byteValue = readHoffer.getByte();\nconst byteArrayValue = readHoffer.getByteArray();\n\nconsole.log(\"ID:\", id);\nconsole.log(\"Name:\", name);\nconsole.log(\"Balance:\", balance);\nconsole.log(\"Byte Value:\", byteValue);\nconsole.log(\"Byte Array Value:\", byteArrayValue);\n\n// Using getValue for dynamic type handling\nconsole.log(\"Generic Number:\", readHoffer.getValue('number'));\nconsole.log(\"Generic String:\", readHoffer.getValue('string'));\nconsole.log(\"Generic Double:\", readHoffer.getValue('double'));\nconsole.log(\"Generic Byte:\", readHoffer.getValue('byte'));\nconsole.log(\"Generic Byte Array:\", readHoffer.getValue('byteArray'));\n```\n\n### Sending Data Over a Socket\n\nTo send data over a network socket, use the `sendData` method:\n\n```typescript\nconst client = new net.Socket();\nclient.connect(12345, 'localhost', () =\u003e {\n    readHoffer.sendData(client);\n    client.end();\n});\n```\n\n## API\n\n### Methods\n\n#### `putNumber(value: number): void`\nWrites a 32-bit integer to the buffer.\n\n#### `putString(value: string): void`\nWrites a UTF-8 encoded string to the buffer.\n\n#### `putDouble(value: number): void`\nWrites a 64-bit double to the buffer.\n\n#### `putByte(value: number): void`\nWrites a single byte to the buffer.\n\n#### `putByteArray(value: number[]): void`\nWrites an array of bytes to the buffer.\n\n#### `putValue(type: string, value: any): void`\nDynamically writes a value to the buffer based on the specified type.\n\n#### `getNumber(): number`\nReads a 32-bit integer from the buffer.\n\n#### `getString(): string`\nReads a UTF-8 encoded string from the buffer.\n\n#### `getDouble(): number`\nReads a 64-bit double from the buffer.\n\n#### `getByte(): number`\nReads a single byte from the buffer.\n\n#### `getByteArray(): number[]`\nReads an array of bytes from the buffer.\n\n#### `getValue(type: string): any`\nDynamically reads a value from the buffer based on the specified type.\n\n#### `reset(): void`\nResets the buffer and read offset.\n\n#### `getData(): Buffer`\nReturns the current buffer.\n\n#### `setData(data: Buffer): void`\nSets the buffer with the provided data and resets the read offset.\n\n#### `sendData(socket: net.Socket): void`\nSends the buffer data over the provided network socket.\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhasirciogli%2Fhoffer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhasirciogli%2Fhoffer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhasirciogli%2Fhoffer/lists"}