Comments (8)
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.
I like NullableTime idea, thanks. It totally covers my case.
from scalapb.
@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.
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.
@thesamet this seems like a pretty big regression compared to proto2, am I missing something? :)
from scalapb.
@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.
Found them: https://github.com/google/protobuf/blob/master/src/google/protobuf/wrappers.proto
from scalapb.
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)
- Support more than 254 fields HOT 1
- Cyclic Error when compiling protobuf-java 3.24.0 on Scala 3.3.0
- Add option to generate only gRPC service and method descriptors. HOT 1
- Custom target directory breaks incremental compilation HOT 2
- ScalaPB 0.11.13 missing release note HOT 3
- problem with `-Xsource:3` and Scala 2.13.12 HOT 2
- Dockerized Native Image build failing HOT 4
- Unify ObjectLens and MessageLens in next release
- Different behavior from Google protoc generated message for accessing proto extensions HOT 15
- Help making pull request: Ability to add `derives` clause HOT 6
- Scalapb.proto would result in a name clash for clearExtension method in OneofOptionsBuilder HOT 8
- allow_alias equality semantics differ between generated Scala and Java code HOT 1
- JSON serialization of Any message fails when the message has a special JSON representation HOT 2
- scalapb grpc runtime & InProcessTransport HOT 4
- Unrecognized enum serialized as int HOT 2
- Cannot name a 'oneof' field 'option' if an optional field exists HOT 1
- --jvm_0_out: protoc-gen-jvm_0: Plugin failed with status code 1. WIth Java version 11, change to 17 is fixed HOT 21
- Type Mismatch Error with `asRecognized` in versions 0.11.14 and 0.11.15 HOT 3
- sealed_oneof_companion_extends doesn't work for optional sealed oneof
- Sealed oneof "extend" for Empty case 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 scalapb.