鉴于以下json响应:
{
"id" : "123456",
"name" : "John Doe",
"email" : "john.doe@example.com"
}
Run Code Online (Sandbox Code Playgroud)
以下user.proto文件:
message User {
string id = 1;
string name = 2;
string email = 3;
}
Run Code Online (Sandbox Code Playgroud)
我想有可能动态创建protobuf消息类(在运行时编译.proto),这样如果json响应通过字段得到增强,"phone" : "+1234567890"我可以上传一个新版本的protobuf文件来包含string phone = 4并得到它protobuf响应中暴露的字段,没有重新启动服务.
如果我要从帽子中提取这些类,我希望能够在下面的代码中写一些东西.
import com.googlecode.protobuf.format.JsonFormat;
import com.googlecode.protobuf.Message;
import org.apache.commons.io.FileUtils;
...
public Message convertToProto(InputStream jsonInputStream){
// get the latest user.proto file
String userProtoFile = FileUtils.readFileToString("user.proto");
Message userProtoMessage = com.acme.ProtobufUtils.compile(userProtoFile);
Message.Builder builder = userProtoMessage.newBuilderForType();
new JsonFormat().merge(inputStream, Charset.forName("UTF-8"), builder);
return builder.build();
}
Run Code Online (Sandbox Code Playgroud)
是否存在com.acme.ProtobufUtils.compile(...)方法?或者如何实现一个?运行protoc …
我正在尝试获取我的userDTO对象列表并将其转换为protobuf候选列表,但我无法弄清楚如何做到这一点
public class UserDTO
{
public string UserNumber { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string UserId { get; set; }
public string EmailId { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
message Candidate {
string userNumber = 1;
string userId = 2;
string firstName = 3;
string lastName = 4;
string emailId = 5;
}
message CandidateList{
repeated Candidate candidateList = 1;
}
Run Code Online (Sandbox Code Playgroud)
public CandidateList GetUsersRpc()
{ …Run Code Online (Sandbox Code Playgroud) c# protocol-buffers .net-core google-protocol-buffer asp.net-core-2.1
I'm working on a project in which I need to analyze an image using Google's Vision API and post the response to a Dynamodb table.
I have successfully implemented the Vision API, but not able to convert its response into Python Dictionary.
Here's what I have tried:
if form.is_valid():
obj = form
obj.imageFile = form.cleaned_data['imageFile']
obj.textFile = form.cleaned_data['textFile']
obj.save()
print(obj.imageFile)
# Process the image using Google's vision API
image_path = os.path.join(settings.MEDIA_ROOT, 'images/', obj.imageFile.name)
print(image_path)
image = vision_image_manager(image_path)
text_path = os.path.join(settings.MEDIA_ROOT, …Run Code Online (Sandbox Code Playgroud) python protocol-buffers google-cloud-vision google-protocol-buffer
我有以下原型:
syntax = "proto3";
import "google/rpc/status.proto";
message Response {
google.rpc.Status status = 1;
}
message Request {
Type name = 1;
}
service Service {
rpc SomeMethod (Request) returns (Response);
}
Run Code Online (Sandbox Code Playgroud)
我在节点中编写一个客户端:
const path = require('path');
const grpc = require('grpc');
const protoLoader = require('@grpc/proto-loader');
const protoFiles = require('google-proto-files');
const PROTO_PATH = path.join(__dirname, '/proto/myproto.proto');
const packageDefinition = protoLoader.loadSync(
PROTO_PATH,
{
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true,
includeDirs: [protoFiles('rpc')],
},
);
const proto = grpc.loadPackageDefinition(packageDefinition);
const client = …Run Code Online (Sandbox Code Playgroud) protocol-buffers node.js grpc google-protocol-buffer grpc-node
我正在尝试为grpc-web. 我已经生成了协议缓冲区,我可以成功获取信息,但是我在创建请求时遇到了问题。
例如。
const request = new PricingMethodRequest()
request.setCurrencyId(64)
request.setId(0)
request.setFrequency(1)
request.setFromDate({ nanos: 0, seconds: 1555064508 }) // <--- Crashes on this line
...
Run Code Online (Sandbox Code Playgroud)
TypeError: c.toArray is not a function当我尝试设置日期值时,似乎我一直在收到。甚至也是一个对象的价格值。
如何实现设置日期值或任何需要 JavaScript 对象的值?
编辑:
我在网上看到过一些我可以做这样的事情:
const fromDateAny = new proto.google.protobuf.Any.fromJavaScript({ nanos: 0, seconds: 1555064508 })
request.setFromDate(fromDateAny)
Run Code Online (Sandbox Code Playgroud)
但是这样做给了我错误Cannot find name 'proto'。
如何在形成 protobuf 消息时将 .Net System.DateTime 转换为 google Protobuf TimeStamp?