• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

rokucommunity / roku-debug / #2026

02 Nov 2022 02:41PM UTC coverage: 56.194% (+7.0%) from 49.18%
#2026

push

TwitchBronBron
0.17.0

997 of 1898 branches covered (52.53%)

Branch coverage included in aggregate %.

2074 of 3567 relevant lines covered (58.14%)

15.56 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

58.97
/src/debugProtocol/responses/VariableResponse.ts
1
/* eslint-disable no-bitwise */
2
import { SmartBuffer } from 'smart-buffer';
1✔
3
import { VARIABLE_FLAGS, VARIABLE_TYPES } from '../Constants';
1✔
4
import { util } from '../../util';
1✔
5

6
export class VariableResponse {
1✔
7

8
    constructor(buffer: Buffer) {
9
        // Minimum variable request response size
10
        if (buffer.byteLength >= 13) {
3✔
11
            try {
1✔
12
                let bufferReader = SmartBuffer.fromBuffer(buffer);
1✔
13
                this.requestId = bufferReader.readUInt32LE();
1✔
14

15
                // Any request id less then one is an update and we should not process it here
16
                if (this.requestId > 0) {
1!
17
                    this.errorCode = bufferReader.readUInt32LE();
1✔
18
                    this.numVariables = bufferReader.readUInt32LE();
1✔
19

20
                    // iterate over each variable in the buffer data and create a Variable Info object
21
                    for (let i = 0; i < this.numVariables; i++) {
1✔
22
                        let variableInfo = new VariableInfo(bufferReader);
3✔
23
                        if (variableInfo.success) {
3!
24
                            // All the necessary variable data was present. Push to the variables array.
25
                            this.variables.push(variableInfo);
3✔
26
                        }
27
                    }
28

29
                    this.readOffset = bufferReader.readOffset;
1✔
30
                    this.success = (this.variables.length === this.numVariables);
1✔
31
                }
32
            } catch (error) {
33
                // Could not process
34
            }
35
        }
36
    }
37
    public success = false;
3✔
38
    public readOffset = 0;
3✔
39

40
    // response fields
41
    public requestId = -1;
3✔
42
    public errorCode = -1;
3✔
43
    public numVariables = -1;
3✔
44
    public variables = [] as VariableInfo[];
3✔
45
}
46

47
export class VariableInfo {
1✔
48

49
    constructor(bufferReader: SmartBuffer) {
50
        if (bufferReader.length >= 13) {
3!
51
            let bitwiseMask = bufferReader.readUInt8();
3✔
52

53
            // Determine the different variable properties
54
            this.isChildKey = (bitwiseMask & VARIABLE_FLAGS.isChildKey) > 0;
3✔
55
            this.isConst = (bitwiseMask & VARIABLE_FLAGS.isConst) > 0;
3✔
56
            this.isContainer = (bitwiseMask & VARIABLE_FLAGS.isContainer) > 0;
3✔
57
            this.isNameHere = (bitwiseMask & VARIABLE_FLAGS.isNameHere) > 0;
3✔
58
            this.isRefCounted = (bitwiseMask & VARIABLE_FLAGS.isRefCounted) > 0;
3✔
59
            this.isValueHere = (bitwiseMask & VARIABLE_FLAGS.isValueHere) > 0;
3✔
60

61
            this.variableType = VARIABLE_TYPES[bufferReader.readUInt8()];
3✔
62

63
            if (this.isNameHere) {
3!
64
                // YAY we have a name. Pull it out of the buffer.
65
                this.name = util.readStringNT(bufferReader);
3✔
66
            }
67

68
            if (this.isRefCounted) {
3!
69
                // This variables reference counts are tracked and we can pull it from the buffer.
70
                this.refCount = bufferReader.readUInt32LE();
3✔
71
            }
72

73
            if (this.isContainer) {
3✔
74
                // It is a form of container object.
75
                // Are the key strings or integers for example
76
                this.keyType = VARIABLE_TYPES[bufferReader.readUInt8()];
1✔
77
                // Equivalent to length on arrays
78
                this.elementCount = bufferReader.readUInt32LE();
1✔
79
            }
80

81
            // Pull out the variable data based on the type if that type returns a value
82
            switch (this.variableType) {
3!
83
                case 'Interface':
84
                case 'Object':
85
                case 'String':
86
                case 'Subroutine':
87
                case 'Function':
88
                    this.value = util.readStringNT(bufferReader);
1✔
89
                    this.success = true;
1✔
90
                    break;
1✔
91
                case 'Subtyped_Object':
92
                    let names = [];
×
93
                    for (let i = 0; i < 2; i++) {
×
94
                        names.push(util.readStringNT(bufferReader));
×
95
                    }
96

97
                    if (names.length === 2) {
×
98
                        this.value = names.join('; ');
×
99
                        this.success = true;
×
100
                    }
101
                    break;
×
102
                case 'Boolean':
103
                    this.value = (bufferReader.readUInt8() > 0);
×
104
                    this.success = true;
×
105
                    break;
×
106
                case 'Double':
107
                    this.value = bufferReader.readDoubleLE();
×
108
                    this.success = true;
×
109
                    break;
×
110
                case 'Float':
111
                    this.value = bufferReader.readFloatLE();
×
112
                    this.success = true;
×
113
                    break;
×
114
                case 'Integer':
115
                    this.value = bufferReader.readInt32LE();
×
116
                    this.success = true;
×
117
                    break;
×
118
                case 'LongInteger':
119
                    this.value = bufferReader.readBigInt64LE();
×
120
                    this.success = true;
×
121
                    break;
×
122
                case 'Uninitialized':
123
                    this.value = 'Uninitialized';
×
124
                    this.success = true;
×
125
                    break;
×
126
                case 'Unknown':
127
                    this.value = 'Unknown';
×
128
                    this.success = true;
×
129
                    break;
×
130
                case 'Invalid':
131
                    this.value = 'Invalid';
1✔
132
                    this.success = true;
1✔
133
                    break;
1✔
134
                case 'AA':
135
                case 'Array':
136
                case 'List':
137
                    this.value = null;
1✔
138
                    this.success = true;
1✔
139
                    break;
1✔
140
                default:
141
                    this.value = null;
×
142
                    this.success = false;
×
143
            }
144
        }
145
    }
146
    public success = false;
3✔
147

148
    // response flags
149
    public isChildKey: boolean;
150
    public isConst: boolean;
151
    public isContainer: boolean;
152
    public isNameHere: boolean;
153
    public isRefCounted: boolean;
154
    public isValueHere: boolean;
155

156
    // response fields
157
    public variableType: string;
158
    public name: string;
159
    public refCount = -1;
3✔
160
    public keyType: string;
161
    public elementCount = -1;
3✔
162
    public value: number | string | boolean | bigint | null;
163
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc