blob: 25376c7b8c16272659528e77698b26cfe2490dc4 [file] [log] [blame]
Joey Armstrong903c69d2024-02-01 19:46:39 -05001package internal
2
3import (
Joey Armstrong903c69d2024-02-01 19:46:39 -05004 "github.com/golang/protobuf/proto"
5)
6
Joey Armstrong903c69d2024-02-01 19:46:39 -05007// GetUnrecognized fetches the bytes of unrecognized fields for the given message.
8func GetUnrecognized(msg proto.Message) []byte {
balaji.nagarajan8a2a7ee2026-06-19 22:31:13 +05309 return proto.MessageReflect(msg).GetUnknown()
Joey Armstrong903c69d2024-02-01 19:46:39 -050010}
11
12// SetUnrecognized adds the given bytes to the unrecognized fields for the given message.
13func SetUnrecognized(msg proto.Message, data []byte) {
balaji.nagarajan8a2a7ee2026-06-19 22:31:13 +053014 refl := proto.MessageReflect(msg)
15 existing := refl.GetUnknown()
Joey Armstrong903c69d2024-02-01 19:46:39 -050016 if len(existing) > 0 {
17 data = append(existing, data...)
18 }
balaji.nagarajan8a2a7ee2026-06-19 22:31:13 +053019 refl.SetUnknown(data)
Joey Armstrong903c69d2024-02-01 19:46:39 -050020}