A more user-friendly API
See original GitHub issueIs anyone here opposed to maybe adding a more user-friendly API to this library.
Right now it takes a fair amount of boilerplate to do what is essentially JSON.parse(encoded) or JSON.stringify(obj).
Plus, there doesn’t seem to be a way to get the same objects out on the decode end as were put into the encoding step. This means even more boilerplate code to translate certain fields from numbers into enum strings. Considering this is probably the most common use case it seems worth it to make this a simple one-step call like buffer = encode(schema, obj) and obj = decode(schema, buffer). And preferably, the input to encode and the output of decode should have deep equality.
Issue Analytics
- State:
- Created 6 years ago
- Comments:6
Top Results From Across the Web
Developer-Friendly APIs - Mutually Human
Choosing to invest time into the design and development of your API can make it more appealing and “friendly” for developers to use,...
Read more >Best Practices for Building a User-Friendly API - Mike Gingerich
A user-friendly API is considered to be robust. Such an API will enable its users to strengthen and integrate software without facing any...
Read more >API design guidelines|Best practices for User-Friendly API
Do you want to design a robust API? Then follow these core API design guidelines, applicable for all types, and build User-friendly, ...
Read more >User friendly API - Gleb Bahmutov
How to design a simple to use and powerful library API. ... then you need to carefully think about the most user-friendly argument...
Read more >Building a Stable and User Friendly API for your Model
Constructing a stable and user friendly API is key for getting users / product teams to start consuming your services and to keep...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@download13 Thanks for sharing your thoughts! This library has a focus on performance and makes sacrifices in other areas such as usability. However, I agree that there is definitely room for improvement in ergonomics! I’ll try to add my thoughts one at a time.
One of the things this library does to make things fast is generate code for serialization instead of using a generic provider. This allows the JS engine to perform optimizations such as inlining and limits the amount of branching.
Unfortunately, compiling is quite expensive and shouldn’t be performed on every call. This makes your version of
encodeanddecodedifficult to achieve.However, there is probably some improvement that could be made to simplify
writecalls. Currently,pbfobjects are passed in to allow object pooling of the buffers. If we added a default value and returnedpbffromwritecalls (allowing chaining) encoding could be much more simple.This is definitely one of the sources of the most boilerplate and it would be great to translate these on the way in / out. We would probably want this optional to prevent the branching and string allocations for use cases that do not need it.
The primary reason for this is defaults as defined by the protobuf standard. This is also mentioned in https://github.com/mapbox/pbf/issues/80. If compiling had a flag to opt out of default values, this could be achieved.
Lastly, if you are looking to simplify the compilation process, take a look at
pbf-loaderfor webpack.Yep, so you can write something like: