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