Comments (7)
Sorry, I switched to protobuf-es
which seems to handle my usecase correctly. I first tried to fix this project but the code is too all over the place for me.
from ts-proto.
Hi @Demon000 , proto2 should be supported; it was not an initial goal of ts-proto, but I think it basically works at the moment.
The biggest flag for proto2 support is usePrototypeForDefaults
because it disables the proto3 behavior of "always fill in missing keys with their default value". proto2 code would sometimes rely on the presence of "is this key set or what?", i.e. hazzer functions, and so usePrototypeForDefaults
enables hazzer checks.
Otherwise, yeah, it should work. Let me know if it doesn't, and I can try and point you in the right direction of a fix/PR. Thanks!
from ts-proto.
Hi @Demon000 , proto2 should be supported; it was not an initial goal of ts-proto, but I think it basically works at the moment.
The biggest flag for proto2 support is
usePrototypeForDefaults
because it disables the proto3 behavior of "always fill in missing keys with their default value". proto2 code would sometimes rely on the presence of "is this key set or what?", i.e. hazzer functions, and sousePrototypeForDefaults
enables hazzer checks.Otherwise, yeah, it should work. Let me know if it doesn't, and I can try and point you in the right direction of a fix/PR. Thanks!
Thanks for the quick answer.
The first issue I encountered is that fields marked as optional
would not translate to a field: Type | undefined
.
The second issue I have is that fields with set default values will not be sent over the wire.
I'm not sure how usePrototypeForDefaults helps with these cases, it doesn't seem to.
from ts-proto.
The second issue I have is that fields with set default values will not be sent over the wire.
Ah, okay, that makes sense. I think the only place I've personally used proto2 optional fields is reading them, and not putting them on the wire.
I think we'd need some sort of encodeDefaultValues
flag, which hopefully shouldn't be that hard to support, if you're interested in submitting a PR, that'd be great!
from ts-proto.
The first issue I encountered is that fields marked as optional
would not translate to a field: Type | undefined.
I guess this makes sense...when ts-proto was first written, it was when proto3 didn't have optional fields. Then after a few years, proto3 added support for optional fields, as like oneofs, and so we support that ... but probably not the "quick & simple" approach of proto2 of just "do or do not put the value on the wire".
Fwiw personally I wish proto3 would have kept proto2's optional field semantics, instead of asserting for ~4-5 years that "no one needs optional fields", and then just backtracking on it later. 🤷
Apologies for the late replies, I can't always immediately triage ts-proto issues, but try to check-in about once per week or two.
I think both of these issues you're seeing are fixable if you're interested in poking around, like the main.ts
generateEncodeMethod
iirc.
from ts-proto.
Ah yeah; I won't deny that--ts-proto's "strength" is that its collected a large array of knobs/flags over the years that, in theory, let users adapt the output to whatever their random/esoteric protobuf internal stacks, but yeah the complexity has gone up to support that. 🤷
Not really a problem I'm paid to solve :-) , so happy you found protobuf-es does what you want.
from ts-proto.
Fwiw @lukealvoeiro I was looking for any issues tagged with "proto2" to close out, after you landed #1007 ... seems like this one is still valid, i.e. an ask to recognize field values as "matching the optional value", and not encode them.
Which is really similar to what proto3 does with its default values, but probably still something we don't do, which is fine imo/not high priority, just noting my current understanding.
from ts-proto.
Related Issues (20)
- I'm using the buf tool to generate a ts file and have set `-ts_proto_opt=esModuleInterop=true`, but the generated code still contains `import Long = require("long");` HOT 1
- Module has already exported a member named 'ServerStreamingMethodResult' HOT 7
- basic_string::_M_construct null not valid HOT 5
- removeEnumPrefix not working HOT 1
- fromJSON should accept both snake_case and camelCase keys HOT 1
- Provide Options type for execution in TS HOT 1
- Add common types to their own file/export w/outputIndex option HOT 2
- Questions about defaults, optionals, arrays, null/undefined HOT 2
- Support `google.api` attributes/conventions HOT 1
- NestJS without Observables HOT 1
- meta generated for messages with oneOf properties is incorret for other properties HOT 1
- Add types for toJSON/fromJSON methods HOT 1
- TypeError on Runtime ChannelCredentials object HOT 1
- Using 'useDate=string' parameter; the response is still anticipating an object for Timestamp Wrapper
- Encode crashes on `null` object values HOT 2
- Rpc doesn't account for metadata HOT 2
- Rpc is not exported by ts-proto as it previously was HOT 6
- Generated affixes HOT 1
- Wrapper Types conversion does not work for repeated field
- Oneof objects do not follow generated interface. 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 ts-proto.