Git Product home page Git Product logo

Comments (2)

opinali avatar opinali commented on May 8, 2024

This is a tradeoff, the builder parameter would certainly help your use case, but it's much less convenient for the general case where all callers would need code like:

Bid.Builder bid = Bid.newBuilder();
readBid(par, bid);
seatBid.addBid(bid);

I can make that better by returning the same builder passed as parameter:

seatBid.addBid(readBid(par, Bid.newBuilder()));

But it's still more code, and that's not even the most important thing: I lose the ability to control creation of that builder in the readBid() method. This is important for example if I want to optimize all those read methods so they don't even allocate a builder (and return null) if the JSON object is an empty {}, which is something that can happen inside sloppily-created messages. (Avoiding to set a dummy child object on desserialization will also prevent serializing it back to {} from the same model, if you need to do that.) It's not a big impact in terms of performance, so I didn't put the time yet for that change, but I still find that valuable as a way to ensure canonicalization of messages: in scenarios like persistent data or test data, you want if possible that the same "logical" message results in the exact same in-memory model / same JSON, that makes everything more efficient and reliable (comparisons, indexing and whatever you need to do).

In your use case you can do this: ext.mergeFrom(readBid(par)). That switches the inconvenience from some extra code to your use case :) but other than that, should work.

from openrtb.

thaDude avatar thaDude commented on May 8, 2024

Thank you for the reply. Yeah, ext.mergeFrom(readBid(par)) is probably what I was looking for. I am closing this issue.

from openrtb.

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.