github.com/jhump/protoreflect@v1.16.0/internal/unrecognized.go (about)

     1  package internal
     2  
     3  import (
     4  	"github.com/golang/protobuf/proto"
     5  )
     6  
     7  // GetUnrecognized fetches the bytes of unrecognized fields for the given message.
     8  func GetUnrecognized(msg proto.Message) []byte {
     9  	return proto.MessageReflect(msg).GetUnknown()
    10  }
    11  
    12  // SetUnrecognized adds the given bytes to the unrecognized fields for the given message.
    13  func SetUnrecognized(msg proto.Message, data []byte) {
    14  	refl := proto.MessageReflect(msg)
    15  	existing := refl.GetUnknown()
    16  	if len(existing) > 0 {
    17  		data = append(existing, data...)
    18  	}
    19  	refl.SetUnknown(data)
    20  }