Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion utils/proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@

package utils

import "google.golang.org/protobuf/proto"
import (
"github.com/livekit/protocol/livekit/logger"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/reflect/protoreflect"
)

func CloneProto[T proto.Message](m T) T {
return proto.Clone(m).(T)
Expand All @@ -27,3 +31,15 @@ func CloneProtoSlice[T proto.Message](ms []T) []T {
}
return cs
}

func CloneProtoRedacted[T proto.Message](m T) T {
clone := proto.Clone(m).(T)
reflected := clone.ProtoReflect()
reflected.Range(func(fd protoreflect.FieldDescriptor, v protoreflect.Value) bool {
if proto.HasExtension(fd.Options(), logger.E_Redact) {
reflected.Clear(fd)
}
return true
})
return clone
}
Loading