SkillAgentSearch skills...

Fmutils

Golang protobuf FieldMask missing utils

Install / Use

/learn @mennanov/Fmutils
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

Golang protobuf FieldMask utils

Build Status Coverage Status PkgGoDev

Filter a protobuf message with a FieldMask applied

// Keeps the fields mentioned in the paths untouched, all the other fields will be cleared.
fmutils.Filter(protoMessage, []string{"a.b.c", "d"})

Prune a protobuf message with a FieldMask applied

// Clears all the fields mentioned in the paths, all the other fields will be left untouched.
fmutils.Prune(protoMessage, []string{"a.b.c", "d"})

Merge protobuf messages with a FieldMask applied

// Overwrites the fields in the dst from src.
// Only the fields listed in the field mask will be copied.
fmutils.Overwrite(src, dst, []string{"a.b.c", "d"})

Working with Golang protobuf APIv1

This library uses the new Go API for protocol buffers. If your *.pb.go files are generated with the old version APIv1 then you have 2 choices:

  • migrate to the new APIv2 google.golang.org/protobuf
  • upgrade an existing APIv1 version to github.com/golang/protobuf@v1.4.0 that implements the new API

In both cases you'll need to regenerate *.pb.go files.

If you decide to stay with APIv1 then you need to use the proto.MessageV2 function like this:

import protov1 "github.com/golang/protobuf/proto"

fmutils.Filter(protov1.MessageV2(protoMessage), []string{"a.b.c", "d"})

Read more about the Go protobuf API versions.

Examples

See the examples_test.go for real life examples.

Related Skills

View on GitHub
GitHub Stars133
CategoryDevelopment
Updated2mo ago
Forks16

Languages

Go

Security Score

100/100

Audited on Jan 27, 2026

No findings