gpt4 book ai didi

javascript - 如何处理nodejs缓冲区(长度不确定)

转载 作者:行者123 更新时间:2023-12-03 10:22:12 26 4
gpt4 key购买 nike

这是示例数据流(在缓冲区中)。 0x81是每个 block 的结束,需要处理逻辑直到下一个0x81

00:15:04:00:00:30:04:54:52:55:45:05:14:00:00:00:04:4b:30:01:00:64:81:00:14:04:00:00:10:03:42:57:47:03:0c:00:14:00:04:4b:31:01:01:f4:81:00:1a:04:00:00:14:07:44:43:4f:4e:2d:57:32:00:80:00:03:00:04:4b:33:02:07:08:20:08:81:00:15:04:00:00:20:04:49:52:50:43:01:ba:00:00:00:04:4b:34:01:00:64:81:00:15:04:00:00:00:04:42:44:4d:53:07:e4:00:1e:00:04:4b:35:01:03:20:81

我需要处理完整的流,但不知道如何处理每个 block 的不确定长度。

最佳答案

您可以尝试使用以下内容:

var bytes = "00:15:04:00:00:81:00:01:81:51:81".split(":");
var buffer = new Buffer(bytes);

function getNextBlock(buffer, pos) {
if (pos >= buffer.length)
return false;

var block = [];
while (pos < buffer.length && buffer[pos] != "81")
block.push(buffer[pos++]);

return block.length ? block : false;

}

var block;
var pos = 0;
while(block = getNextBlock(buffer, pos)) {
console.log(block);
pos += 1 + block.length;
}

关于javascript - 如何处理nodejs缓冲区(长度不确定),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29574909/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com