Skip to content

Utilities for derived messages #150

Open
@JimLarson

Description

@JimLarson

Assuming #146 gets adopted for conditionally setting message fields, we still don't have one thing we might desire: a simple idiom for deriving one message from another by copying most of the fields, which would ideally be expressed as

MyProto{f1: orig.f1, f2: orig.f2, ...}

Because we don't have the same value when reading an unset field as when writing it, we'd have to write

MyProto{f1: has(orig.f1) ? orig.f1 : unset, f2: has(orig.f2) ? orig.f2 : unset, ...}

which is substantially more verbose.

Instead, we can introduce utility functions which can accomplish the same thing more concisely, such as orig.copy(fields or field_mask) which would create a copy restricted to the listed subset of fields, orig.exclude(fields or field_mask) which would create a copy without the listed fields, and orig.merge({"f1": v1, ...}) which would overwrite select fields.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions