javascript - Convert JSON object to protobuf IStruct - Stack Overflow

I am using the Dialogflow API for Nodejs.This API is apparently implemented by Google via protocol buff

I am using the Dialogflow API for Nodejs.

This API is apparently implemented by Google via protocol buffers, though it presents a simple JavaScript/JSON based interface that I have used successfully for simple queries.

In order to request Dialogflow send me response data for a particular platform, I apparently need to encode a simple JSON object into protobuf format. The linked source gives an example that makes use of a "structjson util" that can presumably be used to do the necessary conversion:

const structjson = require('./structjson.js');

const request = {
    /* other properties omitted */
    queryParams: {
        payload: structjson.jsonToStructProto({source: 'ACTIONS_ON_GOOGLE'})
    },
};

Unfortunately, the link given for the structjson util is dead, and I can find no other reference to it.

I don't need to do anything other than encode a simple JSON object, as per the example above. Is there a simple utility (either runtime or mand line) that can be used to do that without having to do major surgery with the protobuf toolchain?

I am using the Dialogflow API for Nodejs.

This API is apparently implemented by Google via protocol buffers, though it presents a simple JavaScript/JSON based interface that I have used successfully for simple queries.

In order to request Dialogflow send me response data for a particular platform, I apparently need to encode a simple JSON object into protobuf format. The linked source gives an example that makes use of a "structjson util" that can presumably be used to do the necessary conversion:

const structjson = require('./structjson.js');

const request = {
    /* other properties omitted */
    queryParams: {
        payload: structjson.jsonToStructProto({source: 'ACTIONS_ON_GOOGLE'})
    },
};

Unfortunately, the link given for the structjson util is dead, and I can find no other reference to it.

I don't need to do anything other than encode a simple JSON object, as per the example above. Is there a simple utility (either runtime or mand line) that can be used to do that without having to do major surgery with the protobuf toolchain?

Share Improve this question asked Dec 30, 2019 at 21:09 Myk WillisMyk Willis 12.9k5 gold badges49 silver badges64 bronze badges 2
  • 1 found the file in history github./googleapis/nodejs-dialogflow/blob/… – karthick Commented Dec 30, 2019 at 21:21
  • thanks @karthick that's very helpful. I've also found that the samples were updated to use a new library for the conversion; I'll follow up with an answer to that effect. – Myk Willis Commented Dec 30, 2019 at 21:59
Add a ment  | 

1 Answer 1

Reset to default 10

It seems the Google Dialogflow samples were updated to use the pb-util package for JSON-to-protobuf conversions. This package provides a method for encoding JSON to protobuf easily, so the example from the original question simply bees:

const {struct} = require('pb-util');

const request = {
    /* other properties omitted */
    queryParams: {
        payload: struct.encode({source: 'ACTIONS_ON_GOOGLE'})
    },
};

Thanks also to @karthick for locating the original structjson file in the Dialogflow samples repo.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742328785a4423288.html

相关推荐

  • javascript - Convert JSON object to protobuf IStruct - Stack Overflow

    I am using the Dialogflow API for Nodejs.This API is apparently implemented by Google via protocol buff

    5小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信