From 7147b0318cc5695b26de68c971072a729b94a913 Mon Sep 17 00:00:00 2001 From: Ethan Davis Date: Tue, 25 Dec 2018 23:43:11 -0800 Subject: [PATCH] 1.1.1: Added limited StreamingAbstractor documentation. --- README.md | 50 ++++++++++++++++++++++++++++++++++++++++++++++++-- package.json | 2 +- 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3ced6e0..f3f5fe7 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ Here we've built a buffer from Ethan's data using the `personSchema` Schema. The ## Parse a Buffer from a Schema -``` +```js // ^ Let's say ethanBuf is a buffer created with the personSchema Schema const parsed = personSchema.parse(ethanBuf) @@ -123,4 +123,50 @@ const sanFranciscoBuf = citySchema.build({ const sanFrancisco = citySchema.parse(sanFranciscoBuf) ``` -`sanFrancisco` will be similar to the object we built `sanFranciscoBuf` from. It will have an array of building objects. \ No newline at end of file +`sanFrancisco` will be similar to the object we built `sanFranciscoBuf` from. It will have an array of building objects. + + +### Utilizing StreamingAbstractor + +StreamingAbstractors allow us to create duplex, event-based streaming systems for applications. + +Let's create a StreamingAbstractor. + +```js +const myAbstractor = new StreamingAbstractor() + +myAbstractor.register('login', new Schema([ + { + 'name': 'username', + 'type': 'string' + }, + { + 'name': 'number', + 'type': 'uint', + 'size': 16 + } +])) +``` + +Above we've registered an event called 'login' in our abstractor. Now it can recieve login events from a stream connected to another StreamingAbstractor. + +#### Recieving Events Through StreamingAbstractor + +Now that we have a StreamingAbstractor (`myAbstractor`) with the `login` event registered, we'll listen for `login` on our end. + +```js +myAbstractor.on('login', (data) => { + console.log('Login with username ' + data.username + ' and number ' + data.number + '.') +}) +``` + +#### Sending Events Through StreamingAbstractor + +Because we've registered the `login` event, we can send `login` events using `myAbstractor`. + +```js +myAbstractor.send('login', { + 'username': 'ethan', + 'number': 5135 +}) +``` \ No newline at end of file diff --git a/package.json b/package.json index 5a7c2e8..6547fe8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "protocore", - "version": "1.1.0", + "version": "1.1.1", "description": "Specify and deploy custom binary protocol structures in Node", "main": "index.js", "scripts": {