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