blob: 25376c7b8c16272659528e77698b26cfe2490dc4 [file] [log] [blame]
khenaidoof3333552021-12-15 16:52:31 -05001package internal
2
3import (
khenaidoof3333552021-12-15 16:52:31 -05004 "github.com/golang/protobuf/proto"
5)
6
khenaidoof3333552021-12-15 16:52:31 -05007// GetUnrecognized fetches the bytes of unrecognized fields for the given message.
8func GetUnrecognized(msg proto.Message) []byte {
Abhay Kumare65b2792025-11-10 13:39:07 +00009 return proto.MessageReflect(msg).GetUnknown()
khenaidoof3333552021-12-15 16:52:31 -050010}
11
12// SetUnrecognized adds the given bytes to the unrecognized fields for the given message.
13func SetUnrecognized(msg proto.Message, data []byte) {
Abhay Kumare65b2792025-11-10 13:39:07 +000014 refl := proto.MessageReflect(msg)
15 existing := refl.GetUnknown()
khenaidoof3333552021-12-15 16:52:31 -050016 if len(existing) > 0 {
17 data = append(existing, data...)
18 }
Abhay Kumare65b2792025-11-10 13:39:07 +000019 refl.SetUnknown(data)
khenaidoof3333552021-12-15 16:52:31 -050020}