Background
It is the first time I am trying reactive programming. I have a stream that receives buffers of data from time to time.
When a buffer starts with 02 it means the start of a message, and when it ends with 03 it means the end of the message.
Example:
- - - 02 53 44 5a - - - 52 6a 72 7a - - - 62 32 62 0d - 0a 03 - - - - >
Objective
My objective is to fire an event every time I detect a message is completed, with who whole message as an argument.
Research
After reading several tutorials on reactive programming and reading RxJS, I know I want to create a hot observable.
With my research, I believe I want to create a "meta-observable" or a "meta-stream", i.e., an observable of observables or a stream of streams (confusing as this may be ... ).
My plan is the following:
1 - create an observable for all buffer messages that come in
2 - subscribe to step 1, and create an observable that detects the beginning of a message ( 02 ) and the end of a message ( 03 )
3 - subscribe something to step 2 that will take care of the data.
So, my diagram would look like the following:
- 05 34 43 31 - - - 12 23 43 - - 02 53 44 5a - - - 52 6a 72 7a - - - 62 32 62 0d - 0a 03 - - - - >
- - 02 53 44 5a - - - 52 6a 72 7a - - - 62 32 62 0d - 0a 03 - - |
Questions
1 - Since I am receiving this data via a socket in node.js:
socket = net.createConnection( { host: "localhost", port: 8080}, () => {
socket.on( "data", console.log );
} );
I don't think I can use the EventEmmiter bridge that rxjs offers. I would have to use Observer.create, correct ?
2 - Even if I solve problem 1, I have no idea whatsoever on how I would create a stream of streams for this effect. Could someone post a code snippet as an example?