func unwrapData(data []byte) ([]byte, pb.ProtocolID, error) { // Unmarshal pbm := new(pb.PBProtocolMessage) err := proto.Unmarshal(data, pbm) if err != nil { return nil, 0, err } return pbm.GetData(), pbm.GetProtocolID(), nil }
func wrapData(data []byte, pid pb.ProtocolID) ([]byte, error) { // Marshal pbm := new(pb.PBProtocolMessage) pbm.ProtocolID = &pid pbm.Data = data b, err := proto.Marshal(pbm) if err != nil { return nil, err } return b, nil }