正在读取Javascript中的7BitEncodedInt



我正在读取javascript中的二进制文件。我认为这个文件是用C#编写的,二进制文件在C#中处理字符串的方式与中提到的处理方式有点不同

https://learn.microsoft.com/en-us/dotnet/api/system.io.binaryreader.readstring?view=net-7.0

问题是,我找不到任何允许我读取C#风格字符串或7bitEncodedInt的库。对任何允许我这样做的代码/包有什么建议吗?

实际上,我在其中一个库中找到了答案,并根据getString的样子进行了修改:

private GetString(buffer) {
try {
let length = this.Read7BitEncodedInt(buffer);
if (length < 0) {
this.toastrService.error('Error');
}
if (length == 0) {
return '';
} else {
return buffer.getNextString(length);
}
}
catch (exception){
this.toastrService.error('Error')
}

}
private Read7BitEncodedInt(buffer) {
let count = 0, shift = 0, b = 0, i = 0;
try {
do {
if (shift === 5 * 7) {
this.toastrService.error('Error');
}
//Get a single byte
b = buffer.getNextBytes(1);
// tslint:disable-next-line:no-bitwise
//Update the value of the int based on the byte that it belongs to(shift value)
count |= (b & 0x7F) << shift;
shift += 7;
i++;
// tslint:disable-next-line:triple-equals no-bitwise
//Exit if byte is empty
} while ((b & 0x80) != 0);
}
catch (exception){
this.toastrService.error('Error message');
}

最新更新