【发布时间】:2022-11-10 06:22:25
【问题描述】:
我在 React Native (v0.65.1) 中使用 google-protobuf (v3.21.0) 时遇到问题,以便使用 expressif (Security1) 通过 SoftWiFi 连接设备 (IoT)
使用curve25519成功创建私钥和公钥后,我需要使用protobuf来传递有效负载。为此,我遵循以下解释: https://medium.com/@singhandresh09/using-protobuf-in-react-native-7cc8286389f5
在使用 protoc 编译器成功创建 js 文件后,我成功地使用了该应用程序。
我得到的错误是指由 protoc session_pb.js 创建的文件:
Can't find variable: proto
goog.object.extend(proto, sec0_pb)
在这里复制它就是我所做的。
- 首先导入创建的js文件。
var session_pb = require('../../../proto/session_pb');
然后使用它
const s = new session_pb.S0SessionCmd();
const r = s.setClientPubKey('123');
我注意到在创建的 js 文件中,“proto”没有在任何地方定义。这里生成的文件:
...
// GENERATED CODE -- DO NOT EDIT!
/* eslint-disable */
// @ts-nocheck
var jspb = require('google-protobuf');
var goog = jspb;
var global = (function() { return this || window || global || self || Function('return this')(); }).call(null);
var sec0_pb = require('./sec0_pb.js');
goog.object.extend(proto, sec0_pb); <--- here is where the error occurs
var sec1_pb = require('./sec1_pb.js');
goog.object.extend(proto, sec1_pb);
var sec2_pb = require('./sec2_pb.js');
goog.object.extend(proto, sec2_pb);
...
【问题讨论】:
-
现在遇到同样的问题,请更新发现!
标签: javascript react-native protocol-buffers proto