Giter Site home page Giter Site logo

Comments (7)

Demon000 avatar Demon000 commented on June 11, 2024 1

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.

stephenh avatar stephenh commented on June 11, 2024

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.

Demon000 avatar Demon000 commented on June 11, 2024

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!

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.

stephenh avatar stephenh commented on June 11, 2024

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.

stephenh avatar stephenh commented on June 11, 2024

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.

stephenh avatar stephenh commented on June 11, 2024

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.

stephenh avatar stephenh commented on June 11, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.