Comments (6)
Context would be more helpful to answer this since you haven't stated where A
comes from and how you want to use the B
s. A few thoughts:
A
andB
have the same binary representation. So if you haveA
available in binary forms, just parse it usingB.parseFrom
and then you get efficiency by not instantiatingA
s.- Don't create messages of type
B
, convert the bytes to string at the time of access. You could add a base trait toA
that has a method likedef getString(index: Int): String = ByteString.copyFromUtf8(a_strings(i))
from scalapb.
Hi @thesamet,
thanks for prompt response! A
message comes from API response and there is no way to avoid creating A
message. Sadly A
and B
don't have the same binary representation (I formed the example wrong), they have many more fields and their field IDs don't match. Since I am working with akka-grpc ecosystem, delaying creation of B
is not an option. Is there a way to create instance of B
just by providing bytes for b_strings
field?
from scalapb.
Do you own the proto for B
? If so, you can leave the proto type as bytes, but similar to (2) above add a base trait that converts to strings only what you need. Then, the creation of this field is just assigning the same reference of Seq[ByteString]
.
from scalapb.
Do you own the proto for
B
? If so, you can leave the proto type as bytes, but similar to (2) above add a base trait that converts to strings only what you need. Then, the creation of this field is just assigning the same reference ofSeq[ByteString]
.
This sounds promising. What would happen to already compiled clients who would expect repeated string
but got repeated bytes
?
from scalapb.
The binary representation is the same. Running clients will not be impacted when this change rolls out to a server.
from scalapb.
The binary representation is the same. Running clients will not be impacted when this change rolls out to a server.
Worked like a charm, thank you very much for your prompt responses!
from scalapb.
Related Issues (20)
- 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
- java.lang.IllegalAccessError: tried to access method 'com.google.protobuf.LazyStringArrayList' HOT 10
- google/protobuf/empty.proto: File not found. HOT 1
- Define trait for GeneratedEnumCompanion’s fromJavaValue/toJavaValue HOT 1
- Support Scala 3.4 type wildcards HOT 2
- `_typemapper` are defined as package private, causing issues when deriving schemas HOT 4
- Protobuf with a field named using generates invalid Scala 3 code HOT 1
- ArrayIndexOutOfBoundsException on getFieldByNumber HOT 5
- UTF-8 Strings are unparseable? HOT 2
- JsonFormat.toJsonString omits authorisation string in the output JSON HOT 2
- Dependency on `scalapb.options.ScalapbProto` in generated code. HOT 3
- New release HOT 1
- Add an option to generate oneof fields as a sealed abstract class
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.