Home > Software engineering >  How to merge values of two protobuff of the same type?
How to merge values of two protobuff of the same type?

Time:10-13

I have a proto for my service configs and read it through different ways ( s3, env, db, etc. ).

I want two merge values of all of them ( with order ) into a single config, so if any attribute that is missing will be added or if there are duplicate values, the higher priority one's value gets replaced.

CodePudding user response:

As per the comments there is a Merge function in the proto package which:

Merge merges src into dst, which must be a message with the same descriptor.

Populated scalar fields in src are copied to dst, while populated singular messages in src are merged into dst by recursively calling Merge. The elements of every list field in src is appended to the corresponded list fields in dst. The entries of every map field in src is copied into the corresponding map field in dst, possibly replacing existing entries. The unknown fields of src are appended to the unknown fields of dst.

  • Related