内容简介:Molecule is a Go library for parsing protobufs in an efficient and zero-allocation manner. The API is loosely based onThis library is in alpha and the API could change. The current APIs are fairly low level, but additional helpers may be added in the futur
Molecule
Molecule is a Go library for parsing protobufs in an efficient and zero-allocation manner. The API is loosely based on this excellent Go JSON parsing library.
This library is in alpha and the API could change. The current APIs are fairly low level, but additional helpers may be added in the future to make certain operations more ergonomic.
Rationale
The standard Unmarshal protobuf interface in Go makes it difficult to manually control allocations when parsing protobufs. In addition, its common to only require access to a subset of an individual protobuf's fields. These issues make it hard to use protobuf in performance critical paths.
This library attempts to solve those problems by introducing a streaming, zero-allocation interface that allows users to have complete control over which fields are parsed, and how/when objects are allocated.
The downside, of course, is that molecule is more difficult to use (and easier to misuse) than the standard protobuf libraries so its recommended that it only be used in situations where performance is important. It is not a general purpose replacement for proto.Unmarshal() . It is recommended that users familiarize themselves with the proto3 encoding before attempting to use this library.
Features
- Unmarshal all protobuf primitive types with a streaming, zero-allocation API.
- Support for iterating through protobuf messages in a streaming fashion.
- Support for iterating through packed protobuf repeated fields (arrays) in a streaming fashion.
Not Supported
- Proto2 syntax (some things will probably work, but nothing is tested).
- Repeated fields encoded not using the "packed" encoding (although in theory they can be parsed using this library, there just aren't any special helpers).
- Map fields. It should be possible to parse maps using this library's API, but it would be a bid tedious. I plan on adding better support for this once I settle on a reasonable API.
- Probably lots of other things.
Examples
The godocs have numerous runnable examples.
Attributions
This library is mostly a thin wrapper around other people's work:
- The interface was inspired by this jsonparser library.
- The codec for interacting with protobuf streams was lifted from this protobuf reflection library . The code was manually vendored instead of imported to reduce dependencies.
Dependencies
The core molecule library has zero external dependencies. The go.sum file does contain some dependencies introduced from the tests package, however, those should not be included transitively when using this library.
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
创新者的窘境(全新修订版)
克莱顿•克里斯坦森 / 胡建桥 / 中信出版社 / 2014-1-1 / 48.00元
全球商业领域中,许多企业曾叱咤风云,但面对市场变化及新技术的挑战,最终惨遭淘汰。究其原因,竟然是因为它们精于管理,信奉客户至上等传统商业观念。这就是所有企业如今都正面临的“创新者的窘境”。 在《创新者的窘境》中,管理大师克里斯坦森指出,一些看似很完美的商业动作——对主流客户所需、赢利能力最强的产品进行精准投资和技术研发——最终却很可能毁掉一家优秀的企业。他分析了计算机、汽车、钢铁等多个行业的......一起来看看 《创新者的窘境(全新修订版)》 这本书的介绍吧!