@@ -36,29 +36,15 @@ export const instantiateWasm = async (
36
36
) ;
37
37
} ;
38
38
39
- export const readResponse = ( pointer : number , buffer : Uint8Array ) => {
40
- let nullHits = 0 ;
41
- const data = [ ] ;
42
-
43
- for ( let i = pointer ; i < buffer . length ; i ++ ) {
44
- //
45
- // Have three nulls in a row, can quit
46
- if ( nullHits === 3 ) {
47
- break ;
48
- }
49
-
50
- // Don't have a length, have to see if we hit three sequential terminators
51
- if ( buffer [ i ] === 166 ) {
52
- nullHits ++ ;
53
- continue ;
54
- }
55
-
56
- // Not a terminator, reset null hits
57
- nullHits = 0 ;
58
- data . push ( buffer [ i ] ) ;
59
- }
60
-
61
- return new Uint8Array ( data ) ;
39
+ export const readResponse = ( pointer : bigint , buffer : Uint8Array ) : any => {
40
+ //
41
+ // Shift right by 32 bits to get the start value
42
+ const start = Number ( pointer >> BigInt ( 32 ) ) ;
43
+
44
+ //
45
+ // Bitwise AND operation with 0xFFFFFFFF to get the length
46
+ const length = Number ( pointer & BigInt ( 0xffffffff ) ) ;
47
+ return buffer . slice ( start , start + length ) ;
62
48
} ;
63
49
64
50
export const runWasm = ( {
@@ -87,9 +73,7 @@ export const runWasm = ({
87
73
const mem = new Uint8Array ( memory . buffer , ptr , requestBytes . length ) ;
88
74
mem . set ( requestBytes ) ;
89
75
90
- const returnPtr = f ( ptr , requestBytes . length ) ;
91
-
92
- const completeBufferFromMemory = new Uint8Array ( memory . buffer ) ;
93
- const response = readResponse ( returnPtr , completeBufferFromMemory ) ;
76
+ const returnPtr = BigInt ( f ( ptr , requestBytes . length ) ) ;
77
+ const response = readResponse ( returnPtr , new Uint8Array ( memory . buffer ) ) ;
94
78
return WASMResponse . fromBinary ( response ) ;
95
79
} ;
0 commit comments