Comments (3)
Can confirm. toBinary
and toJson
doesn't output default values for required
fields when we use proto2
.
Is this a bug or intended behavior? This should be solvable somehow. One approach is to made an option for those two functions to serialize required
values even in the default state.
from protobuf-ts.
There is only partial support for proto2
. The required
label is not supported. At least for toJson
there is an option to emitDefaultValues
, but there is no such option for toBinary
.
from protobuf-ts.
The info on partial support for proto2 is a bit outdated. The library is able to serialize and deserialize such fields without issues, there's no any bool
fallback.
From my experiments with other TS libraries this one is a clear winner, but the inability to configure default value writes to support proto2
clients is a deal breaker.
There was actually a very similar request to support this case some time ago: #194
I can think of few approaches to make this work:
- Support this as a flag in
BinaryWriteOptions
. This is pretty invasive, adds unnecessary runtime bloat that's not needed for most scenarios, but is clear and understandable. - Support this in
protoc
plugin with a flag likealways_emit_default_values
. This is a little bit hacky. The idea here is to keep TS interfaces as is (do not add?
to fields), but:- modify generated serializers to use
!== undefined
check instead of!== 0
and!= ""
; - add
opt: true
for reflection serializers to do the same.
- modify generated serializers to use
The protoc
flag looks like a solid solution to support this edge case for users who are forced to support proto2
in their projects, and at the same time don't intervene in the usual proto3
use cases of this library. Thoughts?
from protobuf-ts.
Related Issues (20)
- unused parameters in the empty.ts are causing TypeScript check errors HOT 6
- Global `Object` is not referenced when there is a message named Object. HOT 2
- Is this compiling error could be turned off by Typescript or Option in protobuf-ts HOT 2
- 2.9.2 not working with 'exactOptionalPropertyTypes: true' HOT 1
- Release 2.9.3 breaks serialization for me HOT 6
- Generated message classes cannot be subclassed because of missing 'export' HOT 1
- Error decoding from binary: "cant skip wire type 4" HOT 1
- How to debug INVALID_ARGUMENT? HOT 1
- Missing headers on RPCError HOT 8
- rpcError cannot support Chinese
- [Request] Flag to handle google wrapper types HOT 1
- Vite cannot found module HOT 2
- Invalid typescript in descriptor.ts HOT 2
- Can't retry request after awaiting response HOT 2
- Typesafe API to retrieve enums from strings HOT 4
- `output_javascript` no longer emits `.d.ts` files HOT 6
- Request: Support for moduleResolution "nodenext" and "node16" HOT 2
- Fails to download v27.0-rc1 (which was just released) HOT 7
- invalid url for latest v27.0-rc1 release HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from protobuf-ts.