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