{"bugs":{"url":"https://github.com/streamr-dev/network-monorepo/issues"},"dist":{"shasum":"dd73045b5a2373a27d39e17557791a312d5524ab","tarball":"https://registry.npmjs.org/@streamr/protocol/-/protocol-7.0.0-beta.2.tgz","fileCount":150,"integrity":"sha512-ZEPhCQyRxWaBnfgGaP71TSDgcIFI/U6suW24LJ8dN5f3PEhKhXUKQKkhbLPYGQtlzHobW+2kepLhsQWF1ud6yg==","signatures":[{"sig":"MEUCIQCEM8a5nDxCRnm6aNVnWPQB/rugyxuNjATuzg2sdJzo+AIgNPgx6cEY2YeZ4yayurQSAKo+3HW2nPoUnW83csbTykY=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":179349,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjalmkACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmoRBA//TBA8bqhlXDct/LGT51347C/3q1wHmdMWCP+TBd4hKru2mEdh\r\nxFTZ7rytWK23h7ICO0ZUCAP+35OUuubbhOV4jb7HB60bwXWL2bVTVzpXND68\r\nGIpwZcS7vnriS9u61y7oxKbJQDThBMozwDbUqlSuE3K1hhnKgzt+xIilusxc\r\nK8lUzvhpe9qFQp68kfb1h8/xt0PJGeyySBTpyzYyru6awApN7VGSXtBHRsZf\r\nacreIiXJJm6ZCE6jBl2bWzSKB1ClipycSAwfOoWMb06YekUqvDKhvsUGNzEO\r\nazBI06L2OxT4iluqH6CxQGl7PAll14f3W3+EJHTEPKu8mIC6FqC/i1cQPs6D\r\nso1cvGdnRJAkERIuesfM1wmcvF9pyqDRJg5cfpLY5DGDUedvE6IetLt0PjXu\r\npKYyZaeQwqcv3Dr1poKI+neZxc2XPRmUOBRSCsyw2LNqZRIUqv2w8tGsBuAG\r\nOw7DY6Gmn9ebJRGt+O21r4Ou8o3NjvSPD1LByUe09Rz6i38P/12drfDRv5iK\r\nEfv1KDjAbLt6tE5/9kUlhhefAsIhnwl6EBftnyY2HcfvBixnklSYc2DRnqGy\r\nyaUzfhTpisZUTDgSUQVWdVe6Pa4mijCRQP0uCr55On9T/FifqFF3TqrP+7Kp\r\nigtlgYgUaDD6Rywlb7LiV1lkkIOuUQTOnGk=\r\n=e/NZ\r\n-----END PGP SIGNATURE-----\r\n"},"main":"dist/src/index.js","name":"@streamr/protocol","types":"dist/src/index.d.ts","author":{"name":"Streamr"},"readme":"# @streamr/protocol\n\nTypeScript implementations of [Streamr Protocol](https://github.com/streamr-dev/streamr-specs/blob/master/PROTOCOL.md) messages and their serialization and deserialization. This is shared code used by other packages in this monorepo.\n\nThe package is available on npm as `@streamr/protocol`.\n \n ## Table of Contents\n- [Use](#use)\n- [Release](#release)\n\n## Use\n\n#### Creating messages from arguments\n\nEvery message type from both the Control Layer and the Message Layer is defined as a class and has a static `create` method that takes class-specific arguments to build an instance of the latest version of the message type. The arguments for each message type are defined in the [protocol documentation](https://github.com/streamr-dev/streamr-specs/blob/master/PROTOCOL.md) and in the definition of the `create` method.\n\nThis example shows how to create a `StreamMessage` and encapsulate it in a `PublishRequest`.\n\n```javascript\nconst streamMessage = new StreamMessage({\n    messageId: new MessageID(...),\n    content\n})\nconst publishRequest = new PublishRequest({\n    requestId: 'requestId', \n    streamMessage, \n})\n```\n\n#### Serializing messages to strings\n\nEvery message type from both the Control Layer and the Message Layer has a `serialize` method, which takes as argument the version to serialize to. By default, it serializes to the latest version of the message type. The `serialize` methods return a string.\n\n```javascript\nconst streamMessage = new StreamMessage({...})\nstreamMessage.serialize() // to latest version\n// > '[31,[\"streamId\",0,1529549961116,\"publisherId\",\"msgChainId\"],null,27,0,{\"foo\":\"bar\"},0,null]'\nstreamMessage.serialize(30) // to MessageLayer version 30\n// > '[30,[\"streamId\",0,1529549961116,\"publisherId\",\"msgChainId\"],null,27,{\"foo\":\"bar\"},0,null]'\n\nconst subscribeRequest = new SubscribeRequest({\n    streamId: 'streamId', \n    streamPartition: 0, \n    sessionToken: 'sessionToken',\n})\nsubscribeRequest.serialize() // to latest version\n// > '[2,9,\"requestId\",\"streamId\",0,\"sessionToken\"]'\nsubscribeRequest.serialize(1) // to ControlLayer version 1\n// > '[1,9,\"streamId\",0,\"sessionToken\"]'\n```\n\n#### Parsing messages from strings\n\nFor deserialization, use the static `deserialize` method that is present in `ControlMessage` for the ControlLayer and `StreamMessage` for the Message Layer. The `deserialize` method accepts both strings and arrays as input.\n\n```javascript\nconst serializedStreamMessage = '[30,[\"streamId\",0,1529549961116,\"publisherId\",\"msgChainId\"],null,27,{\"foo\":\"bar\"},0,null]'\nconst streamMessage = StreamMessage.deserialize(serializedStreamMessage)\n``` \n\nOn the other hand, the Control Layer has many different message types. So we can only know that the `deserialize` method will return a `ControlMessage`. We can use the `type` field to differentiate.\n\n```javascript\nconst serializedMessage = '[1,9,\"streamId\",0,\"sessionToken\"]'\nconst controlMessage = ControlMessage.deserialize(serializedMessage)\nif (controlMessage.type === ControlMessage.TYPES.UnicastMessage) {\n    //treat it as a UnicastMessage\n} else if (controlMessage.type === ControlMessage.TYPES.SubscribeRequest) {\n    //treat it as a SubscribeRequest\n} else if (...) {\n    \n} else {\n    throw new Error(`Unknown type: ${controlMessage.type}`)\n}\n```\n","gitHead":"f1a913f4073da274fc1f85b0bde10c3e0b151649","license":"Apache-2.0","scripts":{"docs":"typedoc --options typedoc.js","test":"jest","build":"tsc -b tsconfig.node.json","check":"tsc -p ./tsconfig.jest.json --noEmit","clean":"jest --clearCache || true; rm -rf dist *.tsbuildinfo node_modules/.cache || true","watch":"tsc --watch","eslint":"eslint --cache --cache-location=node_modules/.cache/.eslintcache/ '*/**/*.{js,ts}'","coverage":"jest --coverage","benchmark":"jest test/benchmarks --detectOpenHandles","test-unit":"jest test/unit --detectOpenHandles","prepublishOnly":"npm run clean && NODE_ENV=production npm run build"},"_npmUser":{"name":"harbu","email":"harbuzen@gmail.com"},"homepage":"https://github.com/streamr-dev/network-monorepo#readme","repository":{"url":"git+https://github.com/streamr-dev/network-monorepo.git","type":"git","directory":"packages/protocol"},"_npmVersion":"8.7.0","description":"JavaScript classes implementing the Streamr client-to-node protocol","directories":{},"maintainers":[{"name":"samigabor","email":"samoila.gabor@yahoo.com"},{"name":"kare","email":"kare.nuorteva@me.com"},{"name":"fonty1","email":"mr.matto@gmail.com"},{"name":"hpihkala","email":"henri.pihkala@streamr.com"},{"name":"tumppi","email":"tuomas.koponen@streamr.com"},{"name":"harbu","email":"harbuzen@gmail.com"},{"name":"mariusz_io","email":"mariusz@mariusz.io"},{"name":"pzsavola","email":"petri.savolainen@spaceify.net"},{"name":"mmartinmo","email":"martin.moravek@streamr.com"},{"name":"juslesan","email":"santeri.juslenius@gmail.com"},{"name":"jtakalai","email":"juuso.takalainen@streamr.com"},{"name":"streamr-dev","email":"devtools@streamr.com"},{"name":"teogeb","email":"teo@streamr.com"},{"name":"samt1803","email":"samt1803@gmail.com"}],"_nodeVersion":"16.14.2","dependencies":{"@streamr/utils":"7.0.0-beta.2"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"sinon":"^11.1.2","@types/sinon":"^10.0.4","@streamr/test-utils":"7.0.0-beta.2"},"_npmOperationalInternal":{"tmp":"tmp/protocol_7.0.0-beta.2_1667914148487_0.10300210159285994","host":"s3://npm-registry-packages"},"_id":"@streamr/protocol@7.0.0-beta.2","version":"7.0.0-beta.2"}