我想阅读BigQuery日志条目来做一些分析.但我似乎无法解释protoPayload.value.我已经尝试过使用google-proto-files和protocol-buffers软件包,但我觉得我错过了一些非常明显的东西…… const Logging = r
const Logging = require('@google-cloud/logging'); const protobuf = require('protocol-buffers'); const protoFiles = require('google-proto-files'); const protoPath = './node_modules/google-proto-files/google/cloud/audit/audit_log.proto'; const root = protoFiles.loadSync(protoPath) const AuditLog = root.lookup('google.cloud.audit.AuditLog'); const client = new Logging.v2.LoggingServiceV2Client({ projectId }); client.listLogEntriesStream({resourceNames, filter, pageSize}) .on('data', entry => { console.log(entry); // Entry is of type AuditLog console.log(AuditLog.decode(entry.protoPayload.value.buffer)); process.exit(1) }) .on('error', e => console.error(e)) .on('end', () => console.info('END RECEIVED', arguments))
我确实收到带有protoPayloads的消息,但是在尝试解码消息时收到的错误是这样的:
Error: no such Type or Enum 'google.rpc.Status' in Type .google.cloud.audit.AuditLog
实际问题:在LogEntry中解码protoPayload字段的正确方法是什么?
谢谢!
由于entry.protoPayload.value是一个序列化的proto(一个AuditLog消息),你应该能够使用 https://developers.google.com/protocol-buffers/docs/reference/javascript-generated#message中记录的deserializeBinary()方法来处理它.“protocol-buffers”npm似乎不是来自Google,而且proto编译器将生成用于反序列化的代码.我不希望你需要,但你也可以尝试明确加载“google / rpc / status.proto”定义.