Git Product home page Git Product logo

Comments (8)

thesamet avatar thesamet commented on May 22, 2024

Two options:

Option A:

int64 deleted_at = 5 [(scalapb.field).type = "Option[org.joda.time.DateTime]"];

and define a TypeMapper[Int, Option[org.joda.time.DateTime]] that maps 0 to None.

Option B:

you can define:

message NullableTime {
  int64 timestamp = 1
}

message Event {
  bytes data = 1;
  NullableTime deleted_at = 5 [(scalapb.field).type = "org.joda.time.DateTime"];
}

Message fields are always in options, and you can then use a custom type for it.

from scalapb.

onsails avatar onsails commented on May 22, 2024

I like NullableTime idea, thanks. It totally covers my case.

from scalapb.

zackangelo avatar zackangelo commented on May 22, 2024

@thesamet What's the reasoning behind not using Option for optional types in messages? Is it something related to how protobuf messages are encoded (e.g., they can't convey absent values)?

from scalapb.

thesamet avatar thesamet commented on May 22, 2024

Exactly. The receiving end has no way of telling if an int32 field was assigned to zero or whether it has not been assigned. See note here: https://developers.google.com/protocol-buffers/docs/proto3?hl=en#default

from scalapb.

zackangelo avatar zackangelo commented on May 22, 2024

@thesamet this seems like a pretty big regression compared to proto2, am I missing something? :)

from scalapb.

zackangelo avatar zackangelo commented on May 22, 2024

@thesamet it looks like proto3 betas will include built-in nullable primitives: protocolbuffers/protobuf#159 (comment).

Could we map these to Option types in the generated code?

That being said, I can't find any trace of them in the repo yet.

from scalapb.

zackangelo avatar zackangelo commented on May 22, 2024

Found them: https://github.com/google/protobuf/blob/master/src/google/protobuf/wrappers.proto

from scalapb.

zackangelo avatar zackangelo commented on May 22, 2024

Trying to use these built-in wrapped types results in compile-time errors:

[error] /Users/zack.angelo/git/galaxy/interfaces/target/scala-2.11/src_managed/main/compiled_protobuf/com/bigcommerce/services/catalog/Product.scala:37: value serializedSize is not a member of com.google.protobuf.Int32Value

[error]       if (id.isDefined) { __size += 1 + com.google.protobuf.CodedOutputStream.computeRawVarint32Size(id.get.serializedSize) + id.get.serializedSize }

Any idea how to fix?

from scalapb.

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.