【发布时间】:2018-11-28 19:43:13
【问题描述】:
我想阅读 BigQuery 日志条目以进行一些分析。但我似乎无法解码protoPayload.value。我试过搞乱google-proto-files 和protocol-buffers 包,但我认为我在这里遗漏了一些非常明显的东西......
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 字段的正确方法是什么?
谢谢!
【问题讨论】:
标签: node.js protocol-buffers google-api-nodejs-client google-cloud-logging