gpt4 book ai didi

rest - Protobuf Field Mask 可以应用于 grpc only case 吗?

转载 作者:IT王子 更新时间:2023-10-29 01:28:08 27 4
gpt4 key购买 nike

我们以官方doc中的这个例子为例:

// Updates a book.
rpc UpdateBook(UpdateBookRequest) returns (Book) {
// Update maps to HTTP PATCH. Resource name is mapped to a URL path.
// Resource is contained in the HTTP request body.
option (google.api.http) = {
// Note the URL template variable which captures the resource name of the
// book to update.
patch: "/v1/{book.name=shelves/*/books/*}"
body: "book"
};
}

message UpdateBookRequest {
// The book resource which replaces the resource on the server.
Book book = 1;

// The update mask applies to the resource. For the `FieldMask` definition,
// see https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#fieldmask
FieldMask update_mask = 2;
}

如果我没有grpc网关,只使用grpc,我可以这样使用mask吗:

// Updates a book.
rpc UpdateBook(UpdateBookRequest) returns (Book);

message UpdateBookRequest {
// The book resource which replaces the resource on the server.
Book book = 1;

// The update mask applies to the resource. For the `FieldMask` definition,
// see https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#fieldmask
FieldMask update_mask = 2;
}

如果是这样,该掩码应该如何工作 - 过滤器请求?或在数据库保存期间应用以及它如何知道数据库......所以我对使用它有点困惑。在我自己的 grpc 示例中,我看到掩码没有过滤请求。

最佳答案

根据protobuf docs :

Field Masks in Update Operations
A field mask in update operations specifies which fields of the targeted resource are going to be updated. The API is required to only change the values of the fields as specified in the mask and leave the others untouched. If a resource is passed in to describe the updated values, the API ignores the values of all fields not covered by the mask.

当您应用字段掩码时,它会指定在 gRPC 请求中更新哪些特定字段。请记住,如果您在 HTTP 请求中使用它,根据我收集的信息,您正在执行的操作必须是 PATCH 请求而不是 PUT 请求。

例如,假设您有一个名为 Books 的声明,其属性为:title 作为字符串,year_published 作为 int32,author 作为作者。声明 Author 的字段 first_name 为字符串,last_name 为字符串。如果您要使用 author.first_name 字段掩码,则只会更新 book authorfirst_name 字段.

请注意,这是基于 protobufs 文档的,我可能完全误解了它,所以请对它持保留态度。

关于rest - Protobuf Field Mask 可以应用于 grpc only case 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53948361/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com