From 64c52ce0fb2257999e5b37c7501a477c4fa2748b Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Thu, 19 Dec 2024 12:05:17 +0100 Subject: [PATCH] Ported some gRPC API calls to opaque API --- commands/cmderrors/cmderrors.go | 9 +- commands/instances.go | 122 +++++++-------- commands/internal/instances/instances.go | 2 +- commands/service_monitor.go | 17 ++- .../builder/internal/diagnostics/parser.go | 39 ++--- .../builder/internal/progress/progress.go | 13 +- internal/integrationtest/arduino-cli.go | 139 +++++++++--------- 7 files changed, 167 insertions(+), 174 deletions(-) diff --git a/commands/cmderrors/cmderrors.go b/commands/cmderrors/cmderrors.go index bcc33bc3a8f..644bd5ef275 100644 --- a/commands/cmderrors/cmderrors.go +++ b/commands/cmderrors/cmderrors.go @@ -24,6 +24,7 @@ import ( "github.com/arduino/go-paths-helper" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" + "google.golang.org/protobuf/proto" ) func composeErrorMsg(msg string, cause error) string { @@ -322,10 +323,10 @@ func (ife *InitFailedError) Error() string { func (ife *InitFailedError) GRPCStatus() *status.Status { st, _ := status. New(ife.Code, ife.Cause.Error()). - WithDetails(&rpc.FailedInstanceInitError{ - Reason: ife.Reason, - Message: ife.Cause.Error(), - }) + WithDetails(rpc.FailedInstanceInitError_builder{ + Reason: &ife.Reason, + Message: proto.String(ife.Cause.Error()), + }.Build()) return st } diff --git a/commands/instances.go b/commands/instances.go index 3c023301cd4..4dc1e55938d 100644 --- a/commands/instances.go +++ b/commands/instances.go @@ -45,17 +45,18 @@ import ( "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" "google.golang.org/grpc/status" + "google.golang.org/protobuf/proto" ) func installTool(ctx context.Context, pm *packagemanager.PackageManager, tool *cores.ToolRelease, downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB) error { pme, release := pm.NewExplorer() defer release() - taskCB(&rpc.TaskProgress{Name: i18n.Tr("Downloading missing tool %s", tool)}) + taskCB(rpc.TaskProgress_builder{Name: proto.String(i18n.Tr("Downloading missing tool %s", tool))}.Build()) if err := pme.DownloadToolRelease(ctx, tool, downloadCB); err != nil { return errors.New(i18n.Tr("downloading %[1]s tool: %[2]s", tool, err)) } - taskCB(&rpc.TaskProgress{Completed: true}) + taskCB(rpc.TaskProgress_builder{Completed: proto.Bool(true)}.Build()) if err := pme.InstallTool(tool, taskCB, true); err != nil { return errors.New(i18n.Tr("installing %[1]s tool: %[2]s", tool, err)) } @@ -97,7 +98,7 @@ func (s *arduinoCoreServerImpl) Create(ctx context.Context, req *rpc.CreateReque if err != nil { return nil, err } - return &rpc.CreateResponse{Instance: inst}, nil + return rpc.CreateResponse_builder{Instance: inst}.Build(), nil } // InitStreamResponseToCallbackFunction returns a gRPC stream to be used in Init that sends @@ -128,29 +129,23 @@ func (s *arduinoCoreServerImpl) Init(req *rpc.InitRequest, stream rpc.ArduinoCor responseCallback = func(*rpc.InitResponse) error { return nil } } responseError := func(st *status.Status) { - responseCallback(&rpc.InitResponse{ - Message: &rpc.InitResponse_Error{ - Error: st.Proto(), - }, - }) + responseCallback(rpc.InitResponse_builder{ + Error: st.Proto(), + }.Build()) } taskCallback := func(msg *rpc.TaskProgress) { - responseCallback(&rpc.InitResponse{ - Message: &rpc.InitResponse_InitProgress{ - InitProgress: &rpc.InitResponse_Progress{ - TaskProgress: msg, - }, - }, - }) + responseCallback(rpc.InitResponse_builder{ + InitProgress: rpc.InitResponse_Progress_builder{ + TaskProgress: msg, + }.Build(), + }.Build()) } downloadCallback := func(msg *rpc.DownloadProgress) { - responseCallback(&rpc.InitResponse{ - Message: &rpc.InitResponse_InitProgress{ - InitProgress: &rpc.InitResponse_Progress{ - DownloadProgress: msg, - }, - }, - }) + responseCallback(rpc.InitResponse_builder{ + InitProgress: rpc.InitResponse_Progress_builder{ + DownloadProgress: msg, + }.Build(), + }.Build()) } // Try to extract profile if specified @@ -165,11 +160,9 @@ func (s *arduinoCoreServerImpl) Init(req *rpc.InitRequest, stream rpc.ArduinoCor return err } profile = p - responseCallback(&rpc.InitResponse{ - Message: &rpc.InitResponse_Profile{ - Profile: profile.ToRpc(), - }, - }) + responseCallback(rpc.InitResponse_builder{ + Profile: profile.ToRpc(), + }.Build()) } // Perform first-update of indexes if needed @@ -369,38 +362,38 @@ func (s *arduinoCoreServerImpl) Init(req *rpc.InitRequest, stream rpc.ArduinoCor if !libDir.IsDir() { // Download library - taskCallback(&rpc.TaskProgress{Name: i18n.Tr("Downloading library %s", libraryRef)}) + taskCallback(rpc.TaskProgress_builder{Name: proto.String(i18n.Tr("Downloading library %s", libraryRef))}.Build()) libRelease, err := li.FindRelease(libraryRef.Library, libraryRef.Version) if err != nil { - taskCallback(&rpc.TaskProgress{Name: i18n.Tr("Library %s not found", libraryRef)}) + taskCallback(rpc.TaskProgress_builder{Name: proto.String(i18n.Tr("Library %s not found", libraryRef))}.Build()) err := &cmderrors.LibraryNotFoundError{Library: libraryRef.Library} responseError(err.GRPCStatus()) continue } config, err := s.settings.DownloaderConfig() if err != nil { - taskCallback(&rpc.TaskProgress{Name: i18n.Tr("Error downloading library %s", libraryRef)}) + taskCallback(rpc.TaskProgress_builder{Name: proto.String(i18n.Tr("Error downloading library %s", libraryRef))}.Build()) e := &cmderrors.FailedLibraryInstallError{Cause: err} responseError(e.GRPCStatus()) continue } if err := libRelease.Resource.Download(ctx, pme.DownloadDir, config, libRelease.String(), downloadCallback, ""); err != nil { - taskCallback(&rpc.TaskProgress{Name: i18n.Tr("Error downloading library %s", libraryRef)}) + taskCallback(rpc.TaskProgress_builder{Name: proto.String(i18n.Tr("Error downloading library %s", libraryRef))}.Build()) e := &cmderrors.FailedLibraryInstallError{Cause: err} responseError(e.GRPCStatus()) continue } - taskCallback(&rpc.TaskProgress{Completed: true}) + taskCallback(rpc.TaskProgress_builder{Completed: proto.Bool(true)}.Build()) // Install library - taskCallback(&rpc.TaskProgress{Name: i18n.Tr("Installing library %s", libraryRef)}) + taskCallback(rpc.TaskProgress_builder{Name: proto.String(i18n.Tr("Installing library %s", libraryRef))}.Build()) if err := libRelease.Resource.Install(pme.DownloadDir, libRoot, libDir); err != nil { - taskCallback(&rpc.TaskProgress{Name: i18n.Tr("Error installing library %s", libraryRef)}) + taskCallback(rpc.TaskProgress_builder{Name: proto.String(i18n.Tr("Error installing library %s", libraryRef))}.Build()) e := &cmderrors.FailedLibraryInstallError{Cause: err} responseError(e.GRPCStatus()) continue } - taskCallback(&rpc.TaskProgress{Completed: true}) + taskCallback(rpc.TaskProgress_builder{Completed: proto.Bool(true)}.Build()) } lmb.AddLibrariesDir(librariesmanager.LibrariesDir{ @@ -456,8 +449,7 @@ func UpdateLibrariesIndexStreamResponseToCallbackFunction(ctx context.Context, d func (s *arduinoCoreServerImpl) UpdateLibrariesIndex(req *rpc.UpdateLibrariesIndexRequest, stream rpc.ArduinoCoreService_UpdateLibrariesIndexServer) error { syncSend := NewSynchronizedSend(stream.Send) downloadCB := func(p *rpc.DownloadProgress) { - syncSend.Send(&rpc.UpdateLibrariesIndexResponse{ - Message: &rpc.UpdateLibrariesIndexResponse_DownloadProgress{DownloadProgress: p}}) + syncSend.Send(rpc.UpdateLibrariesIndexResponse_builder{DownloadProgress: p}.Build()) } pme, release, err := instances.GetPackageManagerExplorer(req.GetInstance()) @@ -469,16 +461,14 @@ func (s *arduinoCoreServerImpl) UpdateLibrariesIndex(req *rpc.UpdateLibrariesInd index := globals.LibrariesIndexResource resultCB := func(status rpc.IndexUpdateReport_Status) { - syncSend.Send(&rpc.UpdateLibrariesIndexResponse{ - Message: &rpc.UpdateLibrariesIndexResponse_Result_{ - Result: &rpc.UpdateLibrariesIndexResponse_Result{ - LibrariesIndex: &rpc.IndexUpdateReport{ - IndexUrl: index.URL.String(), - Status: status, - }, - }, - }, - }) + syncSend.Send(rpc.UpdateLibrariesIndexResponse_builder{ + Result: rpc.UpdateLibrariesIndexResponse_Result_builder{ + LibrariesIndex: rpc.IndexUpdateReport_builder{ + IndexUrl: proto.String(index.URL.String()), + Status: &status, + }.Build(), + }.Build(), + }.Build()) } // Create the index directory if it doesn't exist @@ -535,17 +525,15 @@ func (s *arduinoCoreServerImpl) UpdateIndex(req *rpc.UpdateIndexRequest, stream } report := func(indexURL *url.URL, status rpc.IndexUpdateReport_Status) *rpc.IndexUpdateReport { - return &rpc.IndexUpdateReport{ - IndexUrl: indexURL.String(), - Status: status, - } + return rpc.IndexUpdateReport_builder{ + IndexUrl: proto.String(indexURL.String()), + Status: &status, + }.Build() } syncSend := NewSynchronizedSend(stream.Send) var downloadCB rpc.DownloadProgressCB = func(p *rpc.DownloadProgress) { - syncSend.Send(&rpc.UpdateIndexResponse{ - Message: &rpc.UpdateIndexResponse_DownloadProgress{DownloadProgress: p}, - }) + syncSend.Send(rpc.UpdateIndexResponse_builder{DownloadProgress: p}.Build()) } indexpath := s.settings.DataDir() @@ -555,7 +543,7 @@ func (s *arduinoCoreServerImpl) UpdateIndex(req *rpc.UpdateIndexRequest, stream } failed := false - result := &rpc.UpdateIndexResponse_Result{} + result := rpc.UpdateIndexResponse_Result_builder{} for _, u := range urls { URL, err := url.Parse(u) if err != nil { @@ -564,7 +552,7 @@ func (s *arduinoCoreServerImpl) UpdateIndex(req *rpc.UpdateIndexRequest, stream downloadCB.Start(u, i18n.Tr("Downloading index: %s", u)) downloadCB.End(false, msg) failed = true - result.UpdatedIndexes = append(result.GetUpdatedIndexes(), report(URL, rpc.IndexUpdateReport_STATUS_FAILED)) + result.UpdatedIndexes = append(result.UpdatedIndexes, report(URL, rpc.IndexUpdateReport_STATUS_FAILED)) continue } @@ -582,9 +570,9 @@ func (s *arduinoCoreServerImpl) UpdateIndex(req *rpc.UpdateIndexRequest, stream downloadCB.Start(u, i18n.Tr("Downloading index: %s", filepath.Base(URL.Path))) downloadCB.End(false, msg) failed = true - result.UpdatedIndexes = append(result.GetUpdatedIndexes(), report(URL, rpc.IndexUpdateReport_STATUS_FAILED)) + result.UpdatedIndexes = append(result.UpdatedIndexes, report(URL, rpc.IndexUpdateReport_STATUS_FAILED)) } else { - result.UpdatedIndexes = append(result.GetUpdatedIndexes(), report(URL, rpc.IndexUpdateReport_STATUS_SKIPPED)) + result.UpdatedIndexes = append(result.UpdatedIndexes, report(URL, rpc.IndexUpdateReport_STATUS_SKIPPED)) } continue } @@ -596,14 +584,14 @@ func (s *arduinoCoreServerImpl) UpdateIndex(req *rpc.UpdateIndexRequest, stream downloadCB.Start(u, i18n.Tr("Downloading index: %s", filepath.Base(URL.Path))) downloadCB.End(false, i18n.Tr("Invalid index URL: %s", err)) failed = true - result.UpdatedIndexes = append(result.GetUpdatedIndexes(), report(URL, rpc.IndexUpdateReport_STATUS_FAILED)) + result.UpdatedIndexes = append(result.UpdatedIndexes, report(URL, rpc.IndexUpdateReport_STATUS_FAILED)) continue } indexFile := indexpath.Join(indexFileName) if info, err := indexFile.Stat(); err == nil { ageSecs := int64(time.Since(info.ModTime()).Seconds()) if ageSecs < req.GetUpdateIfOlderThanSecs() { - result.UpdatedIndexes = append(result.GetUpdatedIndexes(), report(URL, rpc.IndexUpdateReport_STATUS_ALREADY_UP_TO_DATE)) + result.UpdatedIndexes = append(result.UpdatedIndexes, report(URL, rpc.IndexUpdateReport_STATUS_ALREADY_UP_TO_DATE)) continue } } @@ -622,14 +610,14 @@ func (s *arduinoCoreServerImpl) UpdateIndex(req *rpc.UpdateIndexRequest, stream } if err := indexResource.Download(stream.Context(), indexpath, downloadCB, config); err != nil { failed = true - result.UpdatedIndexes = append(result.GetUpdatedIndexes(), report(URL, rpc.IndexUpdateReport_STATUS_FAILED)) + result.UpdatedIndexes = append(result.UpdatedIndexes, report(URL, rpc.IndexUpdateReport_STATUS_FAILED)) } else { - result.UpdatedIndexes = append(result.GetUpdatedIndexes(), report(URL, rpc.IndexUpdateReport_STATUS_UPDATED)) + result.UpdatedIndexes = append(result.UpdatedIndexes, report(URL, rpc.IndexUpdateReport_STATUS_UPDATED)) } } - syncSend.Send(&rpc.UpdateIndexResponse{ - Message: &rpc.UpdateIndexResponse_Result_{Result: result}, - }) + syncSend.Send(rpc.UpdateIndexResponse_builder{ + Result: result.Build(), + }.Build()) if failed { return &cmderrors.FailedDownloadError{Message: i18n.Tr("Some indexes could not be updated.")} } @@ -644,7 +632,7 @@ func firstUpdate(ctx context.Context, srv rpc.ArduinoCoreServiceServer, instance if libraryIndex.NotExist() { // The library_index.json file doesn't exists, that means the CLI is run for the first time // so we proceed with the first update that downloads the file - req := &rpc.UpdateLibrariesIndexRequest{Instance: instance} + req := rpc.UpdateLibrariesIndexRequest_builder{Instance: instance}.Build() stream, _ := UpdateLibrariesIndexStreamResponseToCallbackFunction(ctx, downloadCb) if err := srv.UpdateLibrariesIndex(req, stream); err != nil { return err @@ -667,7 +655,7 @@ func firstUpdate(ctx context.Context, srv rpc.ArduinoCoreServiceServer, instance // or the 3rd party package index URL has just been added. Similarly to the // library update we download that file and all the other package indexes from // additional_urls - req := &rpc.UpdateIndexRequest{Instance: instance} + req := rpc.UpdateIndexRequest_builder{Instance: instance}.Build() stream, _ := UpdateIndexStreamResponseToCallbackFunction(ctx, downloadCb) if err := srv.UpdateIndex(req, stream); err != nil { return err diff --git a/commands/internal/instances/instances.go b/commands/internal/instances/instances.go index b327bbc1d88..0b6e7b1edb6 100644 --- a/commands/internal/instances/instances.go +++ b/commands/internal/instances/instances.go @@ -158,7 +158,7 @@ func Create(dataDir, packagesDir, userPackagesDir, downloadsDir *paths.Path, ext instancesCount++ instancesMux.Unlock() - return &rpc.Instance{Id: id}, nil + return rpc.Instance_builder{Id: &id}.Build(), nil } // IsValid returns true if the given instance is valid. diff --git a/commands/service_monitor.go b/commands/service_monitor.go index 012d4ddf8bc..5d165c3e8f9 100644 --- a/commands/service_monitor.go +++ b/commands/service_monitor.go @@ -35,6 +35,7 @@ import ( "github.com/djherbis/nio/v3" "github.com/sirupsen/logrus" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) type monitorPipeServer struct { @@ -55,14 +56,14 @@ func (s *monitorPipeServer) Send(resp *rpc.MonitorResponse) error { func (s *monitorPipeServer) Recv() (r *rpc.MonitorRequest, e error) { if conf := s.req.Swap(nil); conf != nil { - return &rpc.MonitorRequest{Message: &rpc.MonitorRequest_OpenRequest{OpenRequest: conf}}, nil + return rpc.MonitorRequest_builder{OpenRequest: conf}.Build(), nil } buff := make([]byte, 4096) n, err := s.in.Read(buff) if err != nil { return nil, err } - return &rpc.MonitorRequest{Message: &rpc.MonitorRequest_TxData{TxData: buff[:n]}}, nil + return rpc.MonitorRequest_builder{TxData: buff[:n]}.Build(), nil } func (s *monitorPipeServer) Context() context.Context { @@ -162,7 +163,7 @@ func (s *arduinoCoreServerImpl) Monitor(stream rpc.ArduinoCoreService_MonitorSer // Send a message with Success set to true to notify the caller of the port being now active syncSend := NewSynchronizedSend(stream.Send) - _ = syncSend.Send(&rpc.MonitorResponse{Message: &rpc.MonitorResponse_Success{Success: true}}) + _ = syncSend.Send(rpc.MonitorResponse_builder{Success: proto.Bool(true)}.Build()) ctx, cancel := context.WithCancel(stream.Context()) gracefulCloseInitiated := &atomic.Bool{} @@ -177,13 +178,13 @@ func (s *arduinoCoreServerImpl) Monitor(stream rpc.ArduinoCoreService_MonitorSer return } if err != nil { - syncSend.Send(&rpc.MonitorResponse{Message: &rpc.MonitorResponse_Error{Error: err.Error()}}) + syncSend.Send(rpc.MonitorResponse_builder{Error: proto.String(err.Error())}.Build()) return } if conf := msg.GetUpdatedConfiguration(); conf != nil { for _, c := range conf.GetSettings() { if err := monitor.Configure(c.GetSettingId(), c.GetValue()); err != nil { - syncSend.Send(&rpc.MonitorResponse{Message: &rpc.MonitorResponse_Error{Error: err.Error()}}) + syncSend.Send(rpc.MonitorResponse_builder{Error: proto.String(err.Error())}.Build()) } } } @@ -201,7 +202,7 @@ func (s *arduinoCoreServerImpl) Monitor(stream rpc.ArduinoCoreService_MonitorSer return } if err != nil { - syncSend.Send(&rpc.MonitorResponse{Message: &rpc.MonitorResponse_Error{Error: err.Error()}}) + syncSend.Send(rpc.MonitorResponse_builder{Error: proto.String(err.Error())}.Build()) return } tx = tx[n:] @@ -219,10 +220,10 @@ func (s *arduinoCoreServerImpl) Monitor(stream rpc.ArduinoCoreService_MonitorSer break } if err != nil { - syncSend.Send(&rpc.MonitorResponse{Message: &rpc.MonitorResponse_Error{Error: err.Error()}}) + syncSend.Send(rpc.MonitorResponse_builder{Error: proto.String(err.Error())}.Build()) break } - if err := syncSend.Send(&rpc.MonitorResponse{Message: &rpc.MonitorResponse_RxData{RxData: buff[:n]}}); err != nil { + if err := syncSend.Send(rpc.MonitorResponse_builder{RxData: buff[:n]}.Build()); err != nil { break } } diff --git a/internal/arduino/builder/internal/diagnostics/parser.go b/internal/arduino/builder/internal/diagnostics/parser.go index 5aafaa5072d..9fc5e335549 100644 --- a/internal/arduino/builder/internal/diagnostics/parser.go +++ b/internal/arduino/builder/internal/diagnostics/parser.go @@ -20,6 +20,7 @@ import ( "strings" rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1" + "google.golang.org/protobuf/proto" ) // CompilerOutputParserCB is a callback function that is called to feed a parser @@ -117,15 +118,15 @@ func (d *Diagnostic) ToRPC() *rpc.CompileDiagnostic { if d == nil { return nil } - return &rpc.CompileDiagnostic{ - Severity: string(d.Severity), - Message: d.Message, - File: d.File, - Line: int64(d.Line), - Column: int64(d.Column), + return rpc.CompileDiagnostic_builder{ + Severity: proto.String(string(d.Severity)), + Message: &d.Message, + File: &d.File, + Line: proto.Int64(int64(d.Line)), + Column: proto.Int64(int64(d.Column)), Context: d.Context.ToRPC(), Notes: d.Suggestions.ToRPC(), - } + }.Build() } // ToRPC converts a Notes to a slice of rpc.CompileDiagnosticNote @@ -142,12 +143,12 @@ func (s *Note) ToRPC() *rpc.CompileDiagnosticNote { if s == nil { return nil } - return &rpc.CompileDiagnosticNote{ - File: s.File, - Line: int64(s.Line), - Column: int64(s.Column), - Message: s.Message, - } + return rpc.CompileDiagnosticNote_builder{ + File: &s.File, + Line: proto.Int64(int64(s.Line)), + Column: proto.Int64(int64(s.Column)), + Message: &s.Message, + }.Build() } // ToRPC converts a FullContext to a slice of rpc.CompileDiagnosticContext @@ -164,10 +165,10 @@ func (d *Context) ToRPC() *rpc.CompileDiagnosticContext { if d == nil { return nil } - return &rpc.CompileDiagnosticContext{ - File: d.File, - Line: int64(d.Line), - Column: int64(d.Column), - Message: d.Message, - } + return rpc.CompileDiagnosticContext_builder{ + File: &d.File, + Line: proto.Int64(int64(d.Line)), + Column: proto.Int64(int64(d.Column)), + Message: &d.Message, + }.Build() } diff --git a/internal/arduino/builder/internal/progress/progress.go b/internal/arduino/builder/internal/progress/progress.go index 4722813f6a8..b93c6cbb477 100644 --- a/internal/arduino/builder/internal/progress/progress.go +++ b/internal/arduino/builder/internal/progress/progress.go @@ -15,7 +15,10 @@ package progress -import rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1" +import ( + rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1" + "google.golang.org/protobuf/proto" +) // Struct fixdoc type Struct struct { @@ -58,9 +61,9 @@ func (p *Struct) CompleteStep() { func (p *Struct) pushProgress() { if p.callback != nil { - p.callback(&rpc.TaskProgress{ - Percent: p.Progress, - Completed: p.Progress >= 100.0, - }) + p.callback(rpc.TaskProgress_builder{ + Percent: &p.Progress, + Completed: proto.Bool(p.Progress >= 100.0), + }.Build()) } } diff --git a/internal/integrationtest/arduino-cli.go b/internal/integrationtest/arduino-cli.go index 231065843d4..c0cfcfc8600 100644 --- a/internal/integrationtest/arduino-cli.go +++ b/internal/integrationtest/arduino-cli.go @@ -35,6 +35,7 @@ import ( "github.com/stretchr/testify/require" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" + "google.golang.org/protobuf/proto" ) // FindRepositoryRootPath returns the repository root path @@ -491,10 +492,10 @@ func (cli *ArduinoCLI) Create() *ArduinoCLIInstance { // SetValue calls the "SetValue" gRPC method. func (cli *ArduinoCLI) SetValue(key, jsonData string) error { - req := &commands.SettingsSetValueRequest{ - Key: key, - EncodedValue: jsonData, - } + req := commands.SettingsSetValueRequest_builder{ + Key: &key, + EncodedValue: &jsonData, + }.Build() logCallf(">>> SetValue(%+v)\n", req) _, err := cli.daemonClient.SettingsSetValue(context.Background(), req) return err @@ -502,11 +503,11 @@ func (cli *ArduinoCLI) SetValue(key, jsonData string) error { // Init calls the "Init" gRPC method. func (inst *ArduinoCLIInstance) Init(profile string, sketchPath string, respCB func(*commands.InitResponse)) error { - initReq := &commands.InitRequest{ + initReq := commands.InitRequest_builder{ Instance: inst.instance, - Profile: profile, - SketchPath: sketchPath, - } + Profile: &profile, + SketchPath: &sketchPath, + }.Build() logCallf(">>> Init(%v)\n", initReq) initClient, err := inst.cli.daemonClient.Init(context.Background(), initReq) if err != nil { @@ -529,10 +530,10 @@ func (inst *ArduinoCLIInstance) Init(profile string, sketchPath string, respCB f // BoardList calls the "BoardList" gRPC method. func (inst *ArduinoCLIInstance) BoardList(timeout time.Duration) (*commands.BoardListResponse, error) { - boardListReq := &commands.BoardListRequest{ + boardListReq := commands.BoardListRequest_builder{ Instance: inst.instance, - Timeout: timeout.Milliseconds(), - } + Timeout: proto.Int64(timeout.Milliseconds()), + }.Build() logCallf(">>> BoardList(%v) -> ", boardListReq) resp, err := inst.cli.daemonClient.BoardList(context.Background(), boardListReq) logCallf("err=%v\n", err) @@ -541,9 +542,9 @@ func (inst *ArduinoCLIInstance) BoardList(timeout time.Duration) (*commands.Boar // BoardListWatch calls the "BoardListWatch" gRPC method. func (inst *ArduinoCLIInstance) BoardListWatch(ctx context.Context) (commands.ArduinoCoreService_BoardListWatchClient, error) { - boardListWatchReq := &commands.BoardListWatchRequest{ + boardListWatchReq := commands.BoardListWatchRequest_builder{ Instance: inst.instance, - } + }.Build() logCallf(">>> BoardListWatch(%v)\n", boardListWatchReq) watcher, err := inst.cli.daemonClient.BoardListWatch(ctx, boardListWatchReq) if err != nil { @@ -554,39 +555,39 @@ func (inst *ArduinoCLIInstance) BoardListWatch(ctx context.Context) (commands.Ar // PlatformInstall calls the "PlatformInstall" gRPC method. func (inst *ArduinoCLIInstance) PlatformInstall(ctx context.Context, packager, arch, version string, skipPostInst bool) (commands.ArduinoCoreService_PlatformInstallClient, error) { - installCl, err := inst.cli.daemonClient.PlatformInstall(ctx, &commands.PlatformInstallRequest{ + installCl, err := inst.cli.daemonClient.PlatformInstall(ctx, commands.PlatformInstallRequest_builder{ Instance: inst.instance, - PlatformPackage: packager, - Architecture: arch, - Version: version, - SkipPostInstall: skipPostInst, - }) + PlatformPackage: &packager, + Architecture: &arch, + Version: &version, + SkipPostInstall: &skipPostInst, + }.Build()) logCallf(">>> PlatformInstall(%v:%v %v)\n", packager, arch, version) return installCl, err } // Compile calls the "Compile" gRPC method. func (inst *ArduinoCLIInstance) Compile(ctx context.Context, fqbn, sketchPath string, warnings string) (commands.ArduinoCoreService_CompileClient, error) { - compileCl, err := inst.cli.daemonClient.Compile(ctx, &commands.CompileRequest{ + compileCl, err := inst.cli.daemonClient.Compile(ctx, commands.CompileRequest_builder{ Instance: inst.instance, - Fqbn: fqbn, - SketchPath: sketchPath, - Verbose: true, - Warnings: warnings, - }) + Fqbn: &fqbn, + SketchPath: &sketchPath, + Verbose: proto.Bool(true), + Warnings: &warnings, + }.Build()) logCallf(">>> Compile(%v %v warnings=%v)\n", fqbn, sketchPath, warnings) return compileCl, err } // LibraryList calls the "LibraryList" gRPC method. func (inst *ArduinoCLIInstance) LibraryList(ctx context.Context, name, fqbn string, all, updatable bool) (*commands.LibraryListResponse, error) { - req := &commands.LibraryListRequest{ + req := commands.LibraryListRequest_builder{ Instance: inst.instance, - Name: name, - Fqbn: fqbn, - All: all, - Updatable: updatable, - } + Name: &name, + Fqbn: &fqbn, + All: &all, + Updatable: &updatable, + }.Build() logCallf(">>> LibraryList(%v) -> ", req) resp, err := inst.cli.daemonClient.LibraryList(ctx, req) logCallf("err=%v\n", err) @@ -601,14 +602,14 @@ func (inst *ArduinoCLIInstance) LibraryInstall(ctx context.Context, name, versio if installAsBundled { installLocation = commands.LibraryInstallLocation_LIBRARY_INSTALL_LOCATION_BUILTIN } - req := &commands.LibraryInstallRequest{ + req := commands.LibraryInstallRequest_builder{ Instance: inst.instance, - Name: name, - Version: version, - NoDeps: noDeps, - NoOverwrite: noOverwrite, - InstallLocation: installLocation, - } + Name: &name, + Version: &version, + NoDeps: &noDeps, + NoOverwrite: &noOverwrite, + InstallLocation: &installLocation, + }.Build() installCl, err := inst.cli.daemonClient.LibraryInstall(ctx, req) logCallf(">>> LibraryInstall(%+v)\n", req) return installCl, err @@ -616,11 +617,11 @@ func (inst *ArduinoCLIInstance) LibraryInstall(ctx context.Context, name, versio // LibraryUninstall calls the "LibraryUninstall" gRPC method. func (inst *ArduinoCLIInstance) LibraryUninstall(ctx context.Context, name, version string) (commands.ArduinoCoreService_LibraryUninstallClient, error) { - req := &commands.LibraryUninstallRequest{ + req := commands.LibraryUninstallRequest_builder{ Instance: inst.instance, - Name: name, - Version: version, - } + Name: &name, + Version: &version, + }.Build() installCl, err := inst.cli.daemonClient.LibraryUninstall(ctx, req) logCallf(">>> LibraryUninstall(%+v)\n", req) return installCl, err @@ -628,10 +629,10 @@ func (inst *ArduinoCLIInstance) LibraryUninstall(ctx context.Context, name, vers // UpdateIndex calls the "UpdateIndex" gRPC method. func (inst *ArduinoCLIInstance) UpdateIndex(ctx context.Context, ignoreCustomPackages bool) (commands.ArduinoCoreService_UpdateIndexClient, error) { - req := &commands.UpdateIndexRequest{ + req := commands.UpdateIndexRequest_builder{ Instance: inst.instance, - IgnoreCustomPackageIndexes: ignoreCustomPackages, - } + IgnoreCustomPackageIndexes: &ignoreCustomPackages, + }.Build() updCl, err := inst.cli.daemonClient.UpdateIndex(ctx, req) logCallf(">>> UpdateIndex(%+v)\n", req) return updCl, err @@ -639,22 +640,22 @@ func (inst *ArduinoCLIInstance) UpdateIndex(ctx context.Context, ignoreCustomPac // PlatformUpgrade calls the "PlatformUpgrade" gRPC method. func (inst *ArduinoCLIInstance) PlatformUpgrade(ctx context.Context, packager, arch string, skipPostInst bool) (commands.ArduinoCoreService_PlatformUpgradeClient, error) { - installCl, err := inst.cli.daemonClient.PlatformUpgrade(ctx, &commands.PlatformUpgradeRequest{ + installCl, err := inst.cli.daemonClient.PlatformUpgrade(ctx, commands.PlatformUpgradeRequest_builder{ Instance: inst.instance, - PlatformPackage: packager, - Architecture: arch, - SkipPostInstall: skipPostInst, - }) + PlatformPackage: &packager, + Architecture: &arch, + SkipPostInstall: &skipPostInst, + }.Build()) logCallf(">>> PlatformUpgrade(%v:%v)\n", packager, arch) return installCl, err } // PlatformSearch calls the "PlatformSearch" gRPC method. func (inst *ArduinoCLIInstance) PlatformSearch(ctx context.Context, args string, all bool) (*commands.PlatformSearchResponse, error) { - req := &commands.PlatformSearchRequest{ + req := commands.PlatformSearchRequest_builder{ Instance: inst.instance, - SearchArgs: args, - } + SearchArgs: &args, + }.Build() logCallf(">>> PlatformSearch(%+v)\n", req) resp, err := inst.cli.daemonClient.PlatformSearch(ctx, req) return resp, err @@ -668,29 +669,27 @@ func (inst *ArduinoCLIInstance) Monitor(ctx context.Context, port *commands.Port if err != nil { return nil, err } - err = monitorClient.Send(&commands.MonitorRequest{ - Message: &commands.MonitorRequest_OpenRequest{ - OpenRequest: &commands.MonitorPortOpenRequest{ - Instance: inst.instance, - Port: port, - }, - }, - }) + err = monitorClient.Send(commands.MonitorRequest_builder{ + OpenRequest: commands.MonitorPortOpenRequest_builder{ + Instance: inst.instance, + Port: port, + }.Build(), + }.Build()) return monitorClient, err } // Upload calls the "Upload" gRPC method. func (inst *ArduinoCLIInstance) Upload(ctx context.Context, fqbn, sketchPath, port, protocol string) (commands.ArduinoCoreService_UploadClient, error) { - uploadCl, err := inst.cli.daemonClient.Upload(ctx, &commands.UploadRequest{ + uploadCl, err := inst.cli.daemonClient.Upload(ctx, commands.UploadRequest_builder{ Instance: inst.instance, - Fqbn: fqbn, - SketchPath: sketchPath, - Verbose: true, - Port: &commands.Port{ - Address: port, - Protocol: protocol, - }, - }) + Fqbn: &fqbn, + SketchPath: &sketchPath, + Verbose: proto.Bool(true), + Port: commands.Port_builder{ + Address: &port, + Protocol: &protocol, + }.Build(), + }.Build()) logCallf(">>> Upload(%v %v port/protocol=%s/%s)\n", fqbn, sketchPath, port, protocol) return uploadCl, err }