# helloPB **Repository Path**: mrmriacle/hello-pb ## Basic Information - **Project Name**: helloPB - **Description**: 学习练习学习练习学习练习学习练习学习练习学习练习 - **Primary Language**: TypeScript - **License**: 0BSD - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2023-04-08 - **Last Updated**: 2025-12-04 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # hello-world Hello world new project template. npm init npm install protobufjs npm install protobufjs -g npm install protobufjs-cli -g # 开发中遇到的问题 ## 1、protobufjs 无法完整的赋值参数;语音是因为Ts中赋值参数不能使用下划线,而是使用的 a_bag_msg => aBagMsg 这种方式赋值的。 ### exp begin: message AwesomeMessage { string awesome_field = 1; // becomes awesomeField string req_msg = 2; // 请求消息 optional int32 service_address = 3; } const AwesomeMessage = this.pbUtil._root.lookupType("awesomepackage.AwesomeMessage"); let message = AwesomeMessage.create({ awesomeField: "hello", reqMsg:"asfasdfa", serviceAddress:1 }); console.log(`message = ${JSON.stringify(message)}`); let body_msg = AwesomeMessage.encode(message).finish(); let decodebody_msg = AwesomeMessage.decode(body_msg); console.log(`message decode = ${JSON.stringify(decodebody_msg)}`); ### exp end; ## 安装 proto转换ts工具 https://zhuanlan.zhihu.com/p/486451668 ## 命令如下 npm install -g proto2api cd proto2api proto2api -d examples/hello.proto -o api # 使用说明 https://www.yuque.com/yuexing0921/blog/ebmrh5 # 生成消息对象 proto2api -d ./awesome.proto -o api