{"bugs":{"url":"https://github.com/streamr-dev/network-monorepo/issues"},"dist":{"shasum":"37f00357702675191cddbd0fe41b35359c794017","tarball":"https://registry.npmjs.org/@streamr/protocol/-/protocol-7.0.0-beta.3.tgz","fileCount":150,"integrity":"sha512-TnlszuCxxcgqf6Ww+z8UeGkV2ungyYmYIPeeHKVkFIfDAMdflzhHYoWSQ+KWR5o1L4367PI7VypvYbPAdhNdDg==","signatures":[{"sig":"MEYCIQDo1y1BYU9+oDZh8blGab+02Ddv5D+7l4C/3wBhBaOJOAIhALK/FU89HUuRo9/53DCitrgf1N2gmn0ESOyBhQm/rBqz","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\nwsFzBAEBCAAGBQJja41uACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqP2A/+PFZtRnEY8AzUrWMsknOCc9J/JsCJ1Io7FYU+swscca8PYpKi\r\ndy9beW7TPFwjOiZz4zMHN7PZeA90hX3ZP08h/1iLfp25fCZRrsgHcoDpculX\r\njrQ7H3HEQjLdmeKZTrTgihBITFimReFfQkyGalniLhubJcOcPIQN2czGEGub\r\nyL4l5MbyiUC51UtFXomIyzGc77uSrvinRbuKdqgL4/PeZR+G6VSmEpRW4eGr\r\n1UDTj63NyoV5iJsxPMORJjQZ85bsFou2JTtY6qJBcC/xtCNQaumgdNEI4NsW\r\nmH88jO6ny8ihy7oCEu77MAf3IOQnmXzR6txmS0vxOmuzgZiS//wMUURgP/8j\r\nRafYfgxhqo7wBMXsjNDW1lIGtHSXR5K6BsGHjsWHaAT5w7u/c60Ny+6zRqt6\r\neBaQl7HoZFS0OKChjGjeObhOK04MiF4OxvzNSVBVPd7IrSfIgp7NZthbLwh4\r\npl7WgZ0VN/9HkmoQ3OI40SirlcPR6cknxvqJaDcrBwQsbjiopYS/hqlLwdr/\r\nLGLumyHrKNZAmcJGaSm1OR1KPHhNe1/DHDpuPt7SuLmL7gKt3mBQpI3IeMZE\r\n7cYjJIMLIolSdeQyFrEj2aRoWIKsUD288Zwx6NqjcrQveK9iyDoYZP2Ty+BD\r\nmvYmzALFBUwc9rGghCE62wKKpncsYBIckOA=\r\n=KCIz\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":"01a3634ff15876f33540edbc6594752502b61518","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.3"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"sinon":"^11.1.2","@types/sinon":"^10.0.4","@streamr/test-utils":"7.0.0-beta.3"},"_npmOperationalInternal":{"tmp":"tmp/protocol_7.0.0-beta.3_1667992941915_0.6720705521980146","host":"s3://npm-registry-packages"},"_id":"@streamr/protocol@7.0.0-beta.3","version":"7.0.0-beta.3"}