-
-
Notifications
You must be signed in to change notification settings - Fork 77
Fixed Stream decode C0 byte (nil) processing error #68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
after C0 byte (nil) stream switched to "End of stream state", added test. Minor changes made in modules formatting to satisfy modules formatting rules checked in tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the proper fix is to add a new option to the streams ‘wrap: true’, that will wrap any incoming and outgoing message in an object { value }. In this way, null could be correctly decoded.
lib/streams.js
Outdated
} | ||
|
||
Base.prototype.emit.apply(this, arguments) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a very bad practice, and it will only work for on(‘data’) handlers and not piped streams.
…ility reasons. When wrap is true decoded items are passed in form of {value: data} instead of data. Using wrap=true for decoder stream allows decoding of C0 byte (nil).
test/streams.js
Outdated
|
||
var pack = msgpack() | ||
var decoder = pack.decoder() | ||
decoder.wrap = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you pass this as an option instead?
Can you also add the same for the encoder? |
Sorry, to confirm for encoder. Using this option we can pass decoder output to encoder. |
The overall goal is to have source.pipe(encoder).pipe(decoder).pipe(sink) have the same input/output sata. I would keep the name of the option the same, but do what make sense to you. |
Sorry, don't understand how to get same input and output data in this scanario: For example when I pass null to encoder it will translate it to C0 byte, then Can you explain please? |
What I mean is that the encode takes objects in the form of |
When wrap = true decoder stream outputs {value:data} instead of data, encoder stream encodes data extracted from {value:data}.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a test for the encoder as well? Also something that exercise both at the same time in a pipeline.
Can you also add the doc for this feature?
Good work!
encoder/decoder streams chain with wrap options. Wrap option for encoder/decoder streams documented in readme.md
lib/streams.js
Outdated
} | ||
|
||
Base.call(this, opts) | ||
this._unwrap = ('wrap' in opts) && opts.wrap |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if the option is wrap
, the property should be ._wrap
.
README.md
Outdated
Builds a stream in object mode that encodes msgpack. | ||
|
||
Supported options: | ||
wrap. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you make this a list:
Supported options:
* `wrap`, put the text inline.
README.md
Outdated
Builds a stream in object mode that decodes msgpack. | ||
|
||
Supported options: | ||
wrap. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as the encoder.
Minor changes in documentation for wrap option of encoder/decoder.
Can you please rebase? This now conflicts with master. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Fixed Stream decode processing error:
after C0 byte (nil) stream switched to "End of stream state",
added test.
Minor changes made in modules formatting to satisfy modules
formatting rules checked in tests.