Skip to content

Commit 924e012

Browse files
committed
Fix ability to read UTF-8 from combined buffer
1 parent e016a87 commit 924e012

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

lib/graph-types.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class Node {
3434
}
3535

3636
toString() {
37-
let s = "(" + this.identity.split('/')[1];
37+
let s = "(" + this.identity;
3838
for (let i = 0; i < this.labels.length; i++) {
3939
s += ":" + this.labels[i];
4040
}

lib/internal/ch-websocket.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ class WebSocketChannel {
5050
};
5151
this._ws.onmessage = (event) => {
5252
if( self.onmessage ) {
53-
self.onmessage( new HeapBuffer( event.data ) );
53+
var b = new HeapBuffer( event.data );
54+
self.onmessage( b );
5455
}
5556
};
5657
}
@@ -67,7 +68,7 @@ class WebSocketChannel {
6768
} else if( buffer instanceof HeapBuffer ) {
6869
this._ws.send( buffer._buffer );
6970
} else {
70-
throw new Exception( "Don't know how to send buffer: " + buffer );
71+
throw new Error( "Don't know how to send buffer: " + buffer );
7172
}
7273
}
7374

lib/internal/connector.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ import WebSocketChannel from "./ch-websocket";
2121
import NodeChannel from "./ch-node";
2222
import chunking from "./chunking";
2323
import packstream from "./packstream";
24-
import {alloc} from "./buf";
24+
import {alloc, CombinedBuffer} from "./buf";
2525
import GraphType from '../graph-types';
26+
import {int, isInt} from '../integer';
2627

2728
let Channel;
2829
if( WebSocketChannel.available ) {

lib/internal/utf8.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,15 @@ try {
7272
if( buffer instanceof buf.HeapBuffer ) {
7373
return decoder.decode( buffer.readView( length ) );
7474
}
75-
else if( buffer instanceof buf.CombinedBuffer ) {
76-
let out = streamDecodeCombinedBuffer(buffer._buffers, length,
77-
(partBuffer) => {
78-
return decoder.decode(partBuffer.readView(partBuffer.length), {stream:true});
79-
},
80-
() => { return decoder.decode(); }
81-
);
82-
return out;
83-
}
8475
else {
85-
throw new Error( "Don't know how to decode strings from `" + buffer + "`.");
76+
// Decoding combined buffer is complicated. For simplicity, for now,
77+
// we simply copy the combined buffer into a regular buffer and decode that.
78+
var tmpBuf = buf.alloc( length );
79+
for (var i = 0; i < length; i++) {
80+
tmpBuf.writeUInt8( buffer.readUInt8() );
81+
};
82+
tmpBuf.reset();
83+
return decoder.decode( tmpBuf.readView( length ) );
8684
}
8785
}
8886
}

0 commit comments

Comments
 (0)