MCPcopy Create free account
hub / github.com/Marus/cortex-debug / fromBuffer

Method fromBuffer

src/frontend/swo/sources/socket.ts:189–211  ·  view source on GitHub ↗
(buffer: Buffer)

Source from the content-addressed store, hash-verified

187 }
188
189 public static fromBuffer(buffer: Buffer): PeMicroHeader {
190 const cls = new PeMicroHeader();
191 const header = new Uint32Array(8);
192 for (let i = 0; i < 8; i++) {
193 header[i] = buffer.readUInt32BE(i * 4);
194 }
195 // Check to see if the header is valid. If its not we might have gotten out of sync.
196 if (header[0] !== 1 || header[1] !== 1) {
197 throw new Error('Invalid PeMicro header start');
198 }
199 cls.type = header[2];
200 cls.sequence = header[3];
201 const messageLength = header[4];
202 if (messageLength < PeMicroHeader.headerLength)
203 {
204 throw new Error('Message length smaller than header');
205 }
206 cls.dataLength = messageLength - PeMicroHeader.headerLength;
207 if (header[5] !== 0 || header[6] !== 0 || header[7] !== 0) {
208 throw new Error('Invalid PeMicro header end');
209 }
210 return cls;
211 }
212
213 public getTxString(): string {
214 const header = Buffer.alloc(32);

Callers 1

processDataMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected