首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从Google Logging API解码protoPayload

从Google Logging API解码protoPayload
EN

Stack Overflow用户
提问于 2018-06-20 02:57:10
回答 1查看 387关注 0票数 4

我想要读取BigQuery日志条目来做一些分析。但我好像没法把protoPayload.value解码。我尝试过摆弄google-proto-filesprotocol-buffers包,但我觉得这里遗漏了一些非常明显的东西……

代码语言:javascript
复制
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接收消息,但在尝试解码消息时收到的错误如下:

代码语言:javascript
复制
Error: no such Type or Enum 'google.rpc.Status' in Type .google.cloud.audit.AuditLog

实际问题:解码LogEntry中的protoPayload字段的正确方法是什么

谢谢!

EN

回答 1

Stack Overflow用户

发布于 2018-06-22 23:58:00

由于协议是一个序列化的entry.protoPayload.value (一个AuditLog消息),你应该能够用deserializeBinary()方法来处理它,这个方法在https://developers.google.com/protocol-buffers/docs/reference/javascript-generated#message上有文档,'protocol-buffers‘npm似乎不是来自谷歌,而且proto编译器已经生成了用于反序列化的代码。

我不认为您需要这样做,但您也可以尝试显式加载"google/rpc/status.proto“定义。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50935252

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档