@@ -8,51 +8,51 @@ export const decodeRelayShard = (bytes: Uint8Array): ShardInfo => {
8
8
if ( bytes . length < 3 ) throw new Error ( "Insufficient data" ) ;
9
9
10
10
const view = new DataView ( bytes . buffer ) ;
11
- const cluster = view . getUint16 ( 0 ) ;
11
+ const clusterId = view . getUint16 ( 0 ) ;
12
12
13
- const indexList = [ ] ;
13
+ const shards = [ ] ;
14
14
15
15
if ( bytes . length === 130 ) {
16
16
// rsv format (Bit Vector)
17
17
for ( let i = 0 ; i < 1024 ; i ++ ) {
18
18
const byteIndex = Math . floor ( i / 8 ) + 2 ; // Adjusted for the 2-byte cluster field
19
19
const bitIndex = 7 - ( i % 8 ) ;
20
20
if ( view . getUint8 ( byteIndex ) & ( 1 << bitIndex ) ) {
21
- indexList . push ( i ) ;
21
+ shards . push ( i ) ;
22
22
}
23
23
}
24
24
} else {
25
25
// rs format (Index List)
26
26
const numIndices = view . getUint8 ( 2 ) ;
27
27
for ( let i = 0 , offset = 3 ; i < numIndices ; i ++ , offset += 2 ) {
28
28
if ( offset + 1 >= bytes . length ) throw new Error ( "Unexpected end of data" ) ;
29
- indexList . push ( view . getUint16 ( offset ) ) ;
29
+ shards . push ( view . getUint16 ( offset ) ) ;
30
30
}
31
31
}
32
32
33
- return { cluster , indexList } ;
33
+ return { clusterId , shards } ;
34
34
} ;
35
35
36
36
export const encodeRelayShard = ( shardInfo : ShardInfo ) : Uint8Array => {
37
- const { cluster , indexList } = shardInfo ;
38
- const totalLength = indexList . length >= 64 ? 130 : 3 + 2 * indexList . length ;
37
+ const { clusterId , shards } = shardInfo ;
38
+ const totalLength = shards . length >= 64 ? 130 : 3 + 2 * shards . length ;
39
39
const buffer = new ArrayBuffer ( totalLength ) ;
40
40
const view = new DataView ( buffer ) ;
41
41
42
- view . setUint16 ( 0 , cluster ) ;
42
+ view . setUint16 ( 0 , clusterId ) ;
43
43
44
- if ( indexList . length >= 64 ) {
44
+ if ( shards . length >= 64 ) {
45
45
// rsv format (Bit Vector)
46
- for ( const index of indexList ) {
46
+ for ( const index of shards ) {
47
47
const byteIndex = Math . floor ( index / 8 ) + 2 ; // Adjusted for the 2-byte cluster field
48
48
const bitIndex = 7 - ( index % 8 ) ;
49
49
view . setUint8 ( byteIndex , view . getUint8 ( byteIndex ) | ( 1 << bitIndex ) ) ;
50
50
}
51
51
} else {
52
52
// rs format (Index List)
53
- view . setUint8 ( 2 , indexList . length ) ;
54
- for ( let i = 0 , offset = 3 ; i < indexList . length ; i ++ , offset += 2 ) {
55
- view . setUint16 ( offset , indexList [ i ] ) ;
53
+ view . setUint8 ( 2 , shards . length ) ;
54
+ for ( let i = 0 , offset = 3 ; i < shards . length ; i ++ , offset += 2 ) {
55
+ view . setUint16 ( offset , shards [ i ] ) ;
56
56
}
57
57
}
58
58
0 commit comments