Coder Social home page Coder Social logo

Comments (6)

thesamet avatar thesamet commented on June 3, 2024

Context would be more helpful to answer this since you haven't stated where A comes from and how you want to use the Bs. A few thoughts:

  1. A and B have the same binary representation. So if you have A available in binary forms, just parse it using B.parseFrom and then you get efficiency by not instantiating As.
  2. Don't create messages of type B, convert the bytes to string at the time of access. You could add a base trait to A that has a method like def getString(index: Int): String = ByteString.copyFromUtf8(a_strings(i))

from scalapb.

jCalamari avatar jCalamari commented on June 3, 2024

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.

thesamet avatar thesamet commented on June 3, 2024

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.

jCalamari avatar jCalamari commented on June 3, 2024

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].

This sounds promising. What would happen to already compiled clients who would expect repeated string but got repeated bytes?

from scalapb.

thesamet avatar thesamet commented on June 3, 2024

The binary representation is the same. Running clients will not be impacted when this change rolls out to a server.

from scalapb.

jCalamari avatar jCalamari commented on June 3, 2024

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)

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.