1- // start demo data
2- // taken from @fails -components/webtransport tests
3- // by the original author
4- function createBytesChunk ( length ) {
5- const workArray = new Array ( length / 2 ) ;
6- for ( let i = 0 ; i < length / 4 ; i ++ ) {
7- workArray [ 2 * i + 1 ] = length % 0xffff ;
8- workArray [ 2 * i ] = i ;
9- }
10- const helper = new Uint16Array ( workArray ) ;
11- const toreturn = new Uint8Array (
12- helper . buffer ,
13- helper . byteOffset ,
14- helper . byteLength
15- ) ;
16- return toreturn ;
17- }
18-
19- // The number in the comments, help you identify the chunk, as it is the length first two bytes
20- // this is helpful, when debugging buffer passing
21- export const KNOWN_BYTES_LONG = [
22- createBytesChunk ( 60000 ) , // 96, 234
23- createBytesChunk ( 12 ) , // 0, 12
24- createBytesChunk ( 50000 ) , // 195, 80
25- createBytesChunk ( 1600 ) . buffer , // 6, 64 we use buffer here to increae test coverage
26- createBytesChunk ( 20000 ) , // 78, 32
27- createBytesChunk ( 30000 ) , // 117, 48
28- ] ;
29-
30- // end demo data
31-
32- export function uint8concat ( arrays ) {
33- const length = arrays . reduce ( ( acc , curr ) => acc + curr . length , 0 ) ;
34- const result = new Uint8Array ( length ) ;
35- let pos = 0 ;
36- let array = 0 ;
37- while ( pos < length ) {
38- const curArr = arrays [ array ] ;
39- const curLen = curArr . byteLength ;
40- const dest = new Uint8Array ( result . buffer , result . byteOffset + pos , curLen ) ;
41- dest . set ( curArr ) ;
42- array ++ ;
43- pos += curArr . byteLength ;
44- }
45- }
1+ // start demo data
2+ // taken from @fails -components/webtransport tests
3+ // by the original author
4+ function createBytesChunk ( length ) {
5+ const workArray = new Array ( length / 2 ) ;
6+ for ( let i = 0 ; i < length / 4 ; i ++ ) {
7+ workArray [ 2 * i + 1 ] = length % 0xffff ;
8+ workArray [ 2 * i ] = i ;
9+ }
10+ const helper = new Uint16Array ( workArray ) ;
11+ const toreturn = new Uint8Array (
12+ helper . buffer ,
13+ helper . byteOffset ,
14+ helper . byteLength ,
15+ ) ;
16+ return toreturn ;
17+ }
18+
19+ // The number in the comments, help you identify the chunk, as it is the length first two bytes
20+ // this is helpful, when debugging buffer passing
21+ export const KNOWN_BYTES_LONG = [
22+ createBytesChunk ( 60000 ) , // 96, 234
23+ createBytesChunk ( 12 ) , // 0, 12
24+ createBytesChunk ( 50000 ) , // 195, 80
25+ createBytesChunk ( 1600 ) . buffer , // 6, 64 we use buffer here to increae test coverage
26+ createBytesChunk ( 20000 ) , // 78, 32
27+ createBytesChunk ( 30000 ) , // 117, 48
28+ ] ;
29+
30+ // end demo data
31+
32+ export function uint8concat ( arrays ) {
33+ const length = arrays . reduce ( ( acc , curr ) => acc + curr . length , 0 ) ;
34+ const result = new Uint8Array ( length ) ;
35+ let pos = 0 ;
36+ let array = 0 ;
37+ while ( pos < length ) {
38+ const curArr = arrays [ array ] ;
39+ const curLen = curArr . byteLength ;
40+ const dest = new Uint8Array ( result . buffer , result . byteOffset + pos , curLen ) ;
41+ dest . set ( curArr ) ;
42+ array ++ ;
43+ pos += curArr . byteLength ;
44+ }
45+ }
0 commit comments