Repeat buffer reads as long as there is data
ci/woodpecker/tag/ociImageTag Pipeline was successful
Details
ci/woodpecker/tag/ociImageTag Pipeline was successful
Details
This commit is contained in:
parent
5f4ab23b8d
commit
a060a1ad29
|
@ -60,37 +60,39 @@ async function getRpcClient(): Promise<Socket> {
|
|||
client.on("data", (recv) => {
|
||||
buf.writeBuffer(recv);
|
||||
|
||||
if (buf.length < 1 + 4 + 8) {
|
||||
return;
|
||||
}
|
||||
|
||||
const header = String.fromCharCode(buf.readUInt8());
|
||||
if (!["M", "F"].includes(header)) {
|
||||
logger.error(`Invalid header: ${header}`);
|
||||
return;
|
||||
}
|
||||
|
||||
const serial = buf.readBigUInt64BE();
|
||||
|
||||
let dataDecoded;
|
||||
if (header === "M") {
|
||||
const dataLen = buf.readUInt32BE();
|
||||
if (buf.remaining() < dataLen) {
|
||||
buf.readOffset = 0;
|
||||
while (true) {
|
||||
if (buf.length < 1 + 4 + 8) {
|
||||
return;
|
||||
}
|
||||
const data = buf.readBuffer(dataLen);
|
||||
dataDecoded = decode(data);
|
||||
} else {
|
||||
dataDecoded = {success: false, data: "RPC returned failure"};
|
||||
|
||||
const header = String.fromCharCode(buf.readUInt8());
|
||||
if (!["M", "F"].includes(header)) {
|
||||
logger.error(`Invalid header: ${header}`);
|
||||
return;
|
||||
}
|
||||
|
||||
const serial = buf.readBigUInt64BE();
|
||||
|
||||
let dataDecoded;
|
||||
if (header === "M") {
|
||||
const dataLen = buf.readUInt32BE();
|
||||
if (buf.remaining() < dataLen) {
|
||||
buf.readOffset = 0;
|
||||
return;
|
||||
}
|
||||
const data = buf.readBuffer(dataLen);
|
||||
dataDecoded = decode(data);
|
||||
} else {
|
||||
dataDecoded = {success: false, data: "RPC returned failure"};
|
||||
}
|
||||
|
||||
// Move the rest of the data to the beginning of the buffer
|
||||
const rest = buf.readBuffer();
|
||||
buf.clear();
|
||||
buf.writeBuffer(rest);
|
||||
|
||||
client!.emit(`mag-data:${serial}`, dataDecoded);
|
||||
}
|
||||
|
||||
// Move the rest of the data to the beginning of the buffer
|
||||
const rest = buf.readBuffer();
|
||||
buf.clear();
|
||||
buf.writeBuffer(rest);
|
||||
|
||||
client!.emit(`mag-data:${serial}`, dataDecoded);
|
||||
});
|
||||
|
||||
client.connect(port, host);
|
||||
|
@ -154,6 +156,7 @@ async function rpcCall<D, T>(method: string, data: D): Promise<T> {
|
|||
|
||||
if (!data.success) {
|
||||
reject(data.data);
|
||||
return;
|
||||
}
|
||||
|
||||
resolve(data.data);
|
||||
|
|
Loading…
Reference in New Issue