@@ -27,35 +27,34 @@ const Transform = require('stream').Transform;
2727 * emits 'message' with the data for that message. All socket
2828 * communications should be piped through this.
2929 */
30- function DeserializeStream ( options ) {
31- if ( ! ( this instanceof DeserializeStream ) ) {
32- return new DeserializeStream ( options ) ;
33- }
30+ class DeserializeStream extends Transform {
3431
35- Transform . call ( this , options ) ;
36- // true once we've pulled off the message length
37- // for the next message we'll need to deserialize
38- this . _inBody = false ;
32+ constructor ( options ) {
33+ super ( options ) ;
3934
40- // track how many bytes of this message we've received so far
41- this . _messageConsumed = 0 ;
35+ // Transform.call(this, options);
36+ // true once we've pulled off the message length
37+ // for the next message we'll need to deserialize
38+ this . _inBody = false ;
4239
43- // how long this message will be
44- this . _messageLen = - 1 ;
40+ // track how many bytes of this message we've received so far
41+ this . _messageConsumed = 0 ;
4542
46- // as bytes of this message arrive, store them in this
47- // buffer until we have the whole thing
48- this . _messageBuffer = [ ] ;
43+ // how long this message will be
44+ this . _messageLen = - 1 ;
4945
50- // TODO: These are specific to parsing a service response...
51- // don't use them everywhere
52- // the first byte in a service response is true/false service success/fail
53- this . _deserializeServiceResp = false ;
46+ // as bytes of this message arrive, store them in this
47+ // buffer until we have the whole thing
48+ this . _messageBuffer = [ ] ;
5449
55- this . _serviceRespSuccess = null ;
56- }
50+ // TODO: These are specific to parsing a service response...
51+ // don't use them everywhere
52+ // the first byte in a service response is true/false service success/fail
53+ this . _deserializeServiceResp = false ;
54+
55+ this . _serviceRespSuccess = null ;
56+ }
5757
58- DeserializeStream . prototype = {
5958 _transform ( chunk , encoding , done ) {
6059 let pos = 0 ;
6160 let chunkLen = chunk . length ;
@@ -124,7 +123,7 @@ DeserializeStream.prototype = {
124123 }
125124 }
126125 done ( ) ;
127- } ,
126+ }
128127
129128 emitMessage ( buffer ) {
130129 if ( this . _deserializeServiceResp ) {
@@ -134,14 +133,13 @@ DeserializeStream.prototype = {
134133 else {
135134 this . emit ( 'message' , buffer ) ;
136135 }
137- } ,
136+ }
138137
139138 setServiceRespDeserialize ( ) {
140139 this . _deserializeServiceResp = true ;
141140 }
142141} ;
143142
144- util . inherits ( DeserializeStream , Transform ) ;
145143
146144//-----------------------------------------------------------------------
147145
0 commit comments