Skip to content

Commit

Permalink
1.1.1: Added limited StreamingAbstractor documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
ethan7g committed Dec 26, 2018
1 parent bd15fd4 commit 7147b03
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
50 changes: 48 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
`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
})
```
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down

0 comments on commit 7147b03

Please sign in to comment.