In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
Go Protobuf based on reflection API is how, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.
Go's protocol buffer binding is a language-independent data exchange format for Google and is designed to replace JSON for high-performance applications. The aim is to merge the protocol buffer system into Go's type system and implement its operations at run time.
Protocol buffer provides a way to specify the schema used to transfer structured data. This pattern is often transformed into a programming language-specific representation called binding, which makes it easier to use high-level interfaces to process protobuf messages.
According to Joe Tsai, Damien Neil, and Herbie Ong, the authors of the new protobuf module version, previous protobuf implementations can no longer meet the expectations of Go developers. Specifically, it provides a view of Go types and values, but ignores the information in the protocol buffer type system.
The consequence of this is the loss of portobuf comments. For example, we might want to write a function that traverses log entries and clears any annotations (annotation) as fields containing sensitive data. Annotations are not part of the Go type system.
Another limitation of the old portobuf module was its reliance on static binding, which hindered the use of dynamic messages, whose types were not fully known at compile time.
The new protobuf module (version APIv2) is based on the assumption that protobuf Message must fully specify the behavior of the message and use reflection to provide a complete view of the protobuf type. The cornerstone of Go protobuf APIv2 is the new proto.Message interface, which is available for all generated message types and provides a way to access the message content. This includes all the protobuf fields, which you can iterate over using protoreflect.Message.Range. This method can not only handle dynamic messages, but also access message options. The following example shows how to process a message to clear all sensitive information it contains before further processing:
/ / Redact clears each sensitive field in the pb. Func Redact (pb proto.Message) {m: = pb.ProtoReflect () m.Range (func (fd protoreflect.FieldDescriptor, v protoreflect.Value) bool {opts: = fd.Options (). (* descriptorpb.FieldOptions) if proto.GetExtension (opts, policypb.E_NonSensitive). (bool) {return true} m.Clear (fd) return true})}
However, several Hacker News commentators have pointed out that Go protobuf APIv2's version control is a bit confusing. Developers need to bind the new version to a specific repository and cannot extend the existing repository with the new version and mark it as v2. Damien Neil explains the reasons behind this decision, as follows:
We can mark the new API as v2: in the import path, v1 and v2 are clearly distinguished. What's confusing: google.golang.org/protobuf@v1 doesn't exist, but v2 does. Ten years later, I hope that no one cares about this old github.com/golang/protobuf, then this confusing thing no longer exists. We can mark the new API as v1: it is difficult to distinguish clearly in the import path. It makes sense to mark the first version of google.golang.org/protobuf as v1. If we think it's a bad idea, it's easier to move from v1 to v2 than from v2 to v1.
In addition, Go protobuf APIv2 will start with version 1.20. Neil explained this in order to avoid ambiguity caused by version overlap in error reports, and he believes that Go protobuf APIv1 will never have version 1.20.
Finally, it is important to note that APIv1 will not be eliminated by APIv2, it will be maintained indefinitely. In fact, its latest implementation (version 1.4) is implemented on top of APIv2.
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.