{"id":20056201,"url":"https://github.com/devgru/node-tarantool-transport","last_synced_at":"2025-07-21T00:35:10.884Z","repository":{"id":65514561,"uuid":"9752611","full_name":"devgru/node-tarantool-transport","owner":"devgru","description":"A node.js transport for Tarantool","archived":false,"fork":false,"pushed_at":"2014-04-24T22:06:24.000Z","size":238,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-09T00:07:08.133Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"CoffeeScript","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/devgru.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}},"created_at":"2013-04-29T16:31:07.000Z","updated_at":"2014-04-24T22:06:24.000Z","dependencies_parsed_at":"2023-01-26T21:05:10.995Z","dependency_job_id":null,"html_url":"https://github.com/devgru/node-tarantool-transport","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"purl":"pkg:github/devgru/node-tarantool-transport","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devgru%2Fnode-tarantool-transport","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devgru%2Fnode-tarantool-transport/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devgru%2Fnode-tarantool-transport/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devgru%2Fnode-tarantool-transport/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devgru","download_url":"https://codeload.github.com/devgru/node-tarantool-transport/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devgru%2Fnode-tarantool-transport/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266221473,"owners_count":23894966,"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-13T12:52:26.119Z","updated_at":"2025-07-21T00:35:10.868Z","avatar_url":"https://github.com/devgru.png","language":"CoffeeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"#Transport - low-level [Tarantool](http://tarantool.org) driver\n\nTransport incapsulates socket, manages callbacks, composes request headers, parses response headers, and composes response from several data packets.\n\n**Use [Connector](https://github.com/devgru/node-tarantool)** as a high-level driver or create your own.\n\n## NPM\n\n```shell\nnpm install tarantool-transport\n```\n## API and usage\nCall `Transport.connect port, host, callback` or `new Transport socket` to instantiate `transport`.\nFirst way is common and preferrable while second allows to prepare `socket`, mock it or hack it.\n\nCall `transport.request type, body, callback` to send request.\n\n- `type` must be Number, any [valid request type](https://github.com/mailru/tarantool/blob/master/doc/box-protocol.txt#L46): 0x0D, 0x11, 0x13, 0x15, 0x16 or 0xFF00.\n- `body` must be Buffer (preferrable) or String (empty string is usable, see example below).\n- `callback` will receive response body as Buffer, maybe empty, never `null` or `undefined`.\n \n**All arguments are obligatory.**\n\n### Example\n\n```coffee\nTransport = require 'tarantool-transport'\n\nPING = 0xFF00 # ping request type\n\ntransport = Transport.connect port, host, -\u003e # on connection\n    transport.request PING, '', -\u003e # on response\n        console.log 'got ping response'\n    \n    console.log 'sent ping request'\n\n# the other way, if you want to prepare socket somehow\n# net = require 'net'\n# socket = net.connect port, host, -\u003e\n#     # on connection\n# transport = new Transport socket\n```\n\n# Hacking\n\n## Implementation notes\n\nBefore reading source please note that:\n- In Tarantool, request and response headers are sequences of unsigned little-endian 32-bit integers.\n- Tarantool allows to set `request_id`. Server will just white this value into `response`, it won't check or compare it with anything. In `transport` we call this field `callback_id` — we pass callbacks and one response calls means one callback here.\n\n## Interaction with Socket\n\nConstructed `transport` sets up `socket` in this way:\n- `socket.unref()` to let `node.js` exit if we're not awaiting responses\n- `socket.setNoDelay()` to reduce latency (added in 0.2.3)\n- `socket.on('data', cb)` to parse and process responses\n\n`transport` does `socket.ref()` on request and `socket.unref()` on last awaited response. Thus, `socket` prevents `node.js` from shutting down until it receives all responses.\n\nThis is the most common use case, but you can play with `socket` in any way, at your own risk.\n\n## Inner variables\n\nFor those who want to hack Transport — list of inner variables:\n- `socket` — `net` socket or Object you passed to constructor\n- `remainder` — Buffer, will prepend next data chunk in order to compose responses from several data packets\n- `callbacks` — Hash (Object), keys are numeric response ids, values are passed callbacks\n- `nextCallbackId` — non-negative Number, incremented on request, when reaches 4294967296 overflows to 0, you can use it to describe request frequency\n- `responsesAwaiting` — non-negative Number, incremented on request, decremented on response, stored to know when `ref()` and `unref()` the `socket`\n\n## Bugs and issues\nBug reports and pull requests are welcome.\n\nLICENSE\n-------\nTarantool Transport for node.js is published under MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevgru%2Fnode-tarantool-transport","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevgru%2Fnode-tarantool-transport","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevgru%2Fnode-tarantool-transport/lists"}