EuEBCPnegwIQBBoGCAEQASgGIgIoAioLCAEYkvX1uwYgjBUyMQoQMS4wMiwwLjI1LDAuNzcsMBIMMS4wNCwxMyw2NywwGg8xLjM1LDEuNSwwLjU3LDA6ZAoECAEQAQoCCAQKAggbCgYIFRAFGAEKBAgNEAEKAggHCgYICRADGAMKAggDCgIIBgoGCBcQcRhVCgIICAoGCAIQBhgCCgYIGRA6GCoKBggWEAcYAgoCCCAKAggOCgYIGBA/GBpCJgoHMS0wLTEtMBIOCOwQGgkwLjM3LDAuMzYaCQEAz/X1uwaNFTAE
#这是需要解的数据
[JavaScript] 纯文本查看 复制代码 const protobuf = require('protobufjs');
const fs = require('fs');
class ProtobufHandler {
constructor(protoFilePath) {
try {
const nData = JSON.parse(fs.readFileSync(protoFilePath, 'utf8'));
this.prototypeRoot = protobuf.Root.fromJSON(nData);
this.protobufMap = this.createProtobufMap();
} catch (error) {
console.error('Failed to load Protobuf definitions:', error);
throw error;
}
}
createProtobufMap() {
const t = this.prototypeRoot;
return {
ApiResult: t.lookupType("tracker.ApiResult"),
FootballStaticDetail: t.lookupType("tracker.FootballStaticDetail"),
FootballVariableDetail: t.lookupType("tracker.FootballVariableDetail")
};
}
decodeMessage(type, data) {
try {
const decoded = type.decode(data);
return type.toObject(decoded, { defaults: true });
} catch (error) {
console.error(`Error decoding message of type ${type.name}:`, error);
throw error;
}
}
processApiResponse(buffer, detailType) {
try {
const apiResult = this.decodeMessage(this.protobufMap.ApiResult, buffer);
if (apiResult.code === 0) {
const resultObject = this.decodeMessage(detailType, apiResult.data);
console.log(JSON.stringify(resultObject));
} else {
console.warn('Unhandled API result code:', apiResult.code);
}
} catch (error) {
console.error('Error processing API response:', error);
}
}
}
try {
const handler = new ProtobufHandler('./599/695f.json');
const base64String = "EuEBCPnegwIQBBoGCAEQASgGIgIoAioLCAEYkvX1uwYgjBUyMQoQMS4wMiwwLjI1LDAuNzcsMBIMMS4wNCwxMyw2NywwGg8xLjM1LDEuNSwwLjU3LDA6ZAoECAEQAQoCCAQKAggbCgYIFRAFGAEKBAgNEAEKAggHCgYICRADGAMKAggDCgIIBgoGCBcQcRhVCgIICAoGCAIQBhgCCgYIGRA6GCoKBggWEAcYAgoCCCAKAggOCgYIGBA/GBpCJgoHMS0wLTEtMBIOCOwQGgkwLjM3LDAuMzYaCQEAz/X1uwaNFTAE";
const buffer = Buffer.from(base64String, 'base64');
handler.processApiResponse(buffer, handler.protobufMap.FootballVariableDetail);
} catch (error) {
console.error('Failed to process data:', error);
}
#这是我用Node实现的
#请教大佬们,用易语言怎样才能取到图内那个数组
|