Skip to content

Commit ed4ffc2

Browse files
protogetter: refactor all direct proto access with getter methods
1 parent 4b207c9 commit ed4ffc2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+370
-370
lines changed

arduino/cores/packagemanager/install_uninstall.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ func (pme *Explorer) IsToolRequired(toolRelease *cores.ToolRelease) bool {
448448

449449
func skipEmptyMessageTaskProgressCB(taskCB rpc.TaskProgressCB) rpc.TaskProgressCB {
450450
return func(msg *rpc.TaskProgress) {
451-
if msg != nil && len(msg.Message) == 0 {
451+
if msg != nil && len(msg.GetMessage()) == 0 {
452452
return
453453
}
454454
taskCB(msg)

arduino/discovery/discovery.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,14 @@ func PortFromRPCPort(o *rpc.Port) (p *Port) {
125125
return nil
126126
}
127127
res := &Port{
128-
Address: o.Address,
129-
AddressLabel: o.Label,
130-
Protocol: o.Protocol,
131-
ProtocolLabel: o.ProtocolLabel,
132-
HardwareID: o.HardwareId,
133-
}
134-
if o.Properties != nil {
135-
res.Properties = properties.NewFromHashmap(o.Properties)
128+
Address: o.GetAddress(),
129+
AddressLabel: o.GetLabel(),
130+
Protocol: o.GetProtocol(),
131+
ProtocolLabel: o.GetProtocolLabel(),
132+
HardwareID: o.GetHardwareId(),
133+
}
134+
if o.GetProperties() != nil {
135+
res.Properties = properties.NewFromHashmap(o.GetProperties())
136136
}
137137
return res
138138
}

arduino/errors.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ type NoBoardsDetectedError struct {
134134
func (e *NoBoardsDetectedError) Error() string {
135135
return tr(
136136
"Please specify an FQBN. The board on port %[1]s with protocol %[2]s can't be identified",
137-
e.Port.Address,
138-
e.Port.Protocol,
137+
e.Port.GetAddress(),
138+
e.Port.GetProtocol(),
139139
)
140140
}
141141

@@ -154,8 +154,8 @@ type MultipleBoardsDetectedError struct {
154154
func (e *MultipleBoardsDetectedError) Error() string {
155155
return tr(
156156
"Please specify an FQBN. Multiple possible boards detected on port %[1]s with protocol %[2]s",
157-
e.Port.Address,
158-
e.Port.Protocol,
157+
e.Port.GetAddress(),
158+
e.Port.GetProtocol(),
159159
)
160160
}
161161

client_example/main.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ func createInstance(client rpc.ArduinoCoreServiceClient) *rpc.Instance {
339339
if err != nil {
340340
log.Fatalf("Error creating server instance: %s", err)
341341
}
342-
return res.Instance
342+
return res.GetInstance()
343343
}
344344

345345
func initInstance(client rpc.ArduinoCoreServiceClient, instance *rpc.Instance) {
@@ -545,8 +545,8 @@ func callBoardSearch(client rpc.ArduinoCoreServiceClient, instance *rpc.Instance
545545
log.Fatalf("Error getting board data: %s\n", err)
546546
}
547547

548-
for _, board := range res.Boards {
549-
log.Printf("Board Name: %s, Board Platform: %s\n", board.Name, board.Platform.Id)
548+
for _, board := range res.GetBoards() {
549+
log.Printf("Board Name: %s, Board Platform: %s\n", board.GetName(), board.GetPlatform().GetId())
550550
}
551551
}
552552

@@ -674,16 +674,16 @@ func callBoardListWatch(client rpc.ArduinoCoreServiceClient, instance *rpc.Insta
674674
} else if err != nil {
675675
log.Fatalf("Board list watch error: %s\n", err)
676676
}
677-
if res.EventType == "error" {
678-
log.Printf("res: %s\n", res.Error)
677+
if res.GetEventType() == "error" {
678+
log.Printf("res: %s\n", res.GetError())
679679
continue
680680
}
681681

682-
log.Printf("event: %s, address: %s\n", res.EventType, res.Port.Port.Address)
683-
if res.EventType == "add" {
684-
log.Printf("protocol: %s, ", res.Port.Port.Protocol)
685-
log.Printf("protocolLabel: %s, ", res.Port.Port.ProtocolLabel)
686-
log.Printf("boards: %s\n\n", res.Port.MatchingBoards)
682+
log.Printf("event: %s, address: %s\n", res.GetEventType(), res.GetPort().GetPort().GetAddress())
683+
if res.GetEventType() == "add" {
684+
log.Printf("protocol: %s, ", res.GetPort().GetPort().GetProtocol())
685+
log.Printf("protocolLabel: %s, ", res.GetPort().GetPort().GetProtocolLabel())
686+
log.Printf("boards: %s\n\n", res.GetPort().GetMatchingBoards())
687687
}
688688
}
689689
}()

commands/board/details.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,16 @@ func Details(ctx context.Context, req *rpc.BoardDetailsRequest) (*rpc.BoardDetai
5252
details.Version = board.PlatformRelease.Version.String()
5353
details.IdentificationProperties = []*rpc.BoardIdentificationProperties{}
5454
for _, p := range board.GetIdentificationProperties() {
55-
details.IdentificationProperties = append(details.IdentificationProperties, &rpc.BoardIdentificationProperties{
55+
details.IdentificationProperties = append(details.GetIdentificationProperties(), &rpc.BoardIdentificationProperties{
5656
Properties: p.AsMap(),
5757
})
5858
}
5959
for _, k := range boardProperties.Keys() {
6060
v := boardProperties.Get(k)
61-
details.BuildProperties = append(details.BuildProperties, k+"="+v)
61+
details.BuildProperties = append(details.GetBuildProperties(), k+"="+v)
6262
}
6363
if !req.GetDoNotExpandBuildProperties() {
64-
details.BuildProperties, _ = utils.ExpandBuildProperties(details.BuildProperties)
64+
details.BuildProperties, _ = utils.ExpandBuildProperties(details.GetBuildProperties())
6565
}
6666

6767
details.DebuggingSupported = boardProperties.ContainsKey("debug.executable") ||
@@ -111,10 +111,10 @@ func Details(ctx context.Context, req *rpc.BoardDetailsRequest) (*rpc.BoardDetai
111111
}
112112
configValue.Value = value
113113
configValue.ValueLabel = values.Get(value)
114-
configOption.Values = append(configOption.Values, configValue)
114+
configOption.Values = append(configOption.GetValues(), configValue)
115115
}
116116

117-
details.ConfigOptions = append(details.ConfigOptions, configOption)
117+
details.ConfigOptions = append(details.GetConfigOptions(), configOption)
118118
}
119119

120120
details.ToolsDependencies = []*rpc.ToolsDependencies{}
@@ -132,7 +132,7 @@ func Details(ctx context.Context, req *rpc.BoardDetailsRequest) (*rpc.BoardDetai
132132
})
133133
}
134134
}
135-
details.ToolsDependencies = append(details.ToolsDependencies, &rpc.ToolsDependencies{
135+
details.ToolsDependencies = append(details.GetToolsDependencies(), &rpc.ToolsDependencies{
136136
Name: tool.ToolName,
137137
Packager: tool.ToolPackager,
138138
Version: tool.ToolVersion.String(),
@@ -142,7 +142,7 @@ func Details(ctx context.Context, req *rpc.BoardDetailsRequest) (*rpc.BoardDetai
142142

143143
details.Programmers = []*rpc.Programmer{}
144144
for id, p := range boardPlatform.Programmers {
145-
details.Programmers = append(details.Programmers, &rpc.Programmer{
145+
details.Programmers = append(details.GetProgrammers(), &rpc.Programmer{
146146
Platform: boardPlatform.Platform.Name,
147147
Id: id,
148148
Name: p.Name,

commands/board/list.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,12 @@ func identify(pme *packagemanager.Explorer, port *discovery.Port) ([]*rpc.BoardL
180180

181181
// Sort by FQBN alphabetically
182182
sort.Slice(boards, func(i, j int) bool {
183-
return strings.ToLower(boards[i].Fqbn) < strings.ToLower(boards[j].Fqbn)
183+
return strings.ToLower(boards[i].GetFqbn()) < strings.ToLower(boards[j].GetFqbn())
184184
})
185185

186186
// Put Arduino boards before others in case there are non Arduino boards with identical VID:PID combination
187187
sort.SliceStable(boards, func(i, j int) bool {
188-
if boards[i].Platform.Maintainer == "Arduino" && boards[j].Platform.Maintainer != "Arduino" {
188+
if boards[i].GetPlatform().GetMaintainer() == "Arduino" && boards[j].GetPlatform().GetMaintainer() != "Arduino" {
189189
return true
190190
}
191191
return false
@@ -244,8 +244,8 @@ func List(req *rpc.BoardListRequest) (r []*rpc.DetectedPort, discoveryStartError
244244
}
245245

246246
func hasMatchingBoard(b *rpc.DetectedPort, fqbnFilter *cores.FQBN) bool {
247-
for _, detectedBoard := range b.MatchingBoards {
248-
detectedFqbn, err := cores.ParseFQBN(detectedBoard.Fqbn)
247+
for _, detectedBoard := range b.GetMatchingBoards() {
248+
detectedFqbn, err := cores.ParseFQBN(detectedBoard.GetFqbn())
249249
if err != nil {
250250
continue
251251
}

commands/board/list_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ func TestGetByVidPid(t *testing.T) {
5454
res, err := apiByVidPid("0xf420", "0XF069")
5555
require.Nil(t, err)
5656
require.Len(t, res, 1)
57-
require.Equal(t, "Arduino/Genuino MKR1000", res[0].Name)
58-
require.Equal(t, "arduino:samd:mkr1000", res[0].Fqbn)
57+
require.Equal(t, "Arduino/Genuino MKR1000", res[0].GetName())
58+
require.Equal(t, "arduino:samd:mkr1000", res[0].GetFqbn())
5959

6060
// wrong vid (too long), wrong pid (not an hex value)
6161
_, err = apiByVidPid("0xfffff", "0xDEFG")
@@ -156,8 +156,8 @@ func TestBoardIdentifySorting(t *testing.T) {
156156
require.Len(t, res, 4)
157157

158158
// Verify expected sorting
159-
require.Equal(t, res[0].Fqbn, "arduino:avr:assurdo")
160-
require.Equal(t, res[1].Fqbn, "arduino:avr:nessuno")
161-
require.Equal(t, res[2].Fqbn, "packager:platform:boardA")
162-
require.Equal(t, res[3].Fqbn, "packager:platform:boardB")
159+
require.Equal(t, res[0].GetFqbn(), "arduino:avr:assurdo")
160+
require.Equal(t, res[1].GetFqbn(), "arduino:avr:nessuno")
161+
require.Equal(t, res[2].GetFqbn(), "packager:platform:boardA")
162+
require.Equal(t, res[3].GetFqbn(), "packager:platform:boardB")
163163
}

commands/board/listall.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func ListAll(ctx context.Context, req *rpc.BoardListAllRequest) (*rpc.BoardListA
8585
continue
8686
}
8787

88-
list.Boards = append(list.Boards, &rpc.BoardListItem{
88+
list.Boards = append(list.GetBoards(), &rpc.BoardListItem{
8989
Name: board.Name(),
9090
Fqbn: board.FQBN(),
9191
IsHidden: board.IsHidden(),

commands/board/search.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func Search(ctx context.Context, req *rpc.BoardSearchRequest) (*rpc.BoardSearchR
8181
continue
8282
}
8383

84-
res.Boards = append(res.Boards, &rpc.BoardListItem{
84+
res.Boards = append(res.GetBoards(), &rpc.BoardListItem{
8585
Name: board.Name(),
8686
Fqbn: board.FQBN(),
8787
IsHidden: board.IsHidden(),
@@ -95,7 +95,7 @@ func Search(ctx context.Context, req *rpc.BoardSearchRequest) (*rpc.BoardSearchR
9595
continue
9696
}
9797

98-
res.Boards = append(res.Boards, &rpc.BoardListItem{
98+
res.Boards = append(res.GetBoards(), &rpc.BoardListItem{
9999
Name: strings.Trim(board.Name, " \n"),
100100
Platform: rpcPlatform,
101101
})
@@ -104,11 +104,11 @@ func Search(ctx context.Context, req *rpc.BoardSearchRequest) (*rpc.BoardSearchR
104104
}
105105
}
106106

107-
sort.Slice(res.Boards, func(i, j int) bool {
108-
if res.Boards[i].Name != res.Boards[j].Name {
109-
return res.Boards[i].Name < res.Boards[j].Name
107+
sort.Slice(res.GetBoards(), func(i, j int) bool {
108+
if res.GetBoards()[i].GetName() != res.GetBoards()[j].GetName() {
109+
return res.GetBoards()[i].GetName() < res.GetBoards()[j].GetName()
110110
}
111-
return res.Boards[i].Platform.Id < res.Boards[j].Platform.Id
111+
return res.GetBoards()[i].GetPlatform().GetId() < res.GetBoards()[j].GetPlatform().GetId()
112112
})
113113
return res, nil
114114
}

commands/compile/compile.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
5454
// the optionality of this property, otherwise we would have no way of knowing if the property
5555
// was set in the request or it's just the default boolean value.
5656
if reqExportBinaries := req.GetExportBinaries(); reqExportBinaries != nil {
57-
exportBinaries = reqExportBinaries.Value
57+
exportBinaries = reqExportBinaries.GetValue()
5858
}
5959

6060
pme, release := instances.GetPackageManagerExplorer(req.GetInstance())
@@ -110,13 +110,13 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
110110
r.BuildPlatform = buildPlatform.ToRPCPlatformReference()
111111

112112
// Setup sign keys if requested
113-
if req.KeysKeychain != "" {
113+
if req.GetKeysKeychain() != "" {
114114
boardBuildProperties.Set("build.keys.keychain", req.GetKeysKeychain())
115115
}
116-
if req.SignKey != "" {
116+
if req.GetSignKey() != "" {
117117
boardBuildProperties.Set("build.keys.sign_key", req.GetSignKey())
118118
}
119-
if req.EncryptKey != "" {
119+
if req.GetEncryptKey() != "" {
120120
boardBuildProperties.Set("build.keys.encrypt_key", req.GetEncryptKey())
121121
}
122122
// At the current time we do not have a way of knowing if a board supports the secure boot or not,
@@ -196,7 +196,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
196196
targetPlatform, actualPlatform,
197197
req.GetSkipLibrariesDiscovery(),
198198
libsManager,
199-
paths.NewPathList(req.Library...),
199+
paths.NewPathList(req.GetLibrary()...),
200200
outStream, errStream, req.GetVerbose(), req.GetWarnings(),
201201
progressCB,
202202
)
@@ -226,10 +226,10 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
226226
keys := buildProperties.Keys()
227227
sort.Strings(keys)
228228
for _, key := range keys {
229-
r.BuildProperties = append(r.BuildProperties, key+"="+buildProperties.Get(key))
229+
r.BuildProperties = append(r.GetBuildProperties(), key+"="+buildProperties.Get(key))
230230
}
231231
if !req.GetDoNotExpandBuildProperties() {
232-
r.BuildProperties, _ = utils.ExpandBuildProperties(r.BuildProperties)
232+
r.BuildProperties, _ = utils.ExpandBuildProperties(r.GetBuildProperties())
233233
}
234234
}()
235235

commands/core/download.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ func PlatformDownload(ctx context.Context, req *rpc.PlatformDownloadRequest, dow
4242
}
4343

4444
ref := &packagemanager.PlatformReference{
45-
Package: req.PlatformPackage,
46-
PlatformArchitecture: req.Architecture,
45+
Package: req.GetPlatformPackage(),
46+
PlatformArchitecture: req.GetArchitecture(),
4747
PlatformVersion: version,
4848
}
4949
platform, tools, err := pme.FindPlatformReleaseDependencies(ref)

commands/core/install.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ func PlatformInstall(ctx context.Context, req *rpc.PlatformInstallRequest, downl
4141
}
4242

4343
ref := &packagemanager.PlatformReference{
44-
Package: req.PlatformPackage,
45-
PlatformArchitecture: req.Architecture,
44+
Package: req.GetPlatformPackage(),
45+
PlatformArchitecture: req.GetArchitecture(),
4646
PlatformVersion: version,
4747
}
4848
platformRelease, tools, err := pme.FindPlatformReleaseDependencies(ref)
@@ -74,7 +74,7 @@ func PlatformInstall(ctx context.Context, req *rpc.PlatformInstallRequest, downl
7474
if err := install(); err != nil {
7575
return nil, err
7676
}
77-
if err := commands.Init(&rpc.InitRequest{Instance: req.Instance}, nil); err != nil {
77+
if err := commands.Init(&rpc.InitRequest{Instance: req.GetInstance()}, nil); err != nil {
7878
return nil, err
7979
}
8080
return &rpc.PlatformInstallResponse{}, nil

commands/core/list.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func PlatformList(req *rpc.PlatformListRequest) (*rpc.PlatformListResponse, erro
4242

4343
// The All flags adds to the list of installed platforms the installable platforms (from the indexes)
4444
// If both All and UpdatableOnly are set All takes precedence
45-
if req.All {
45+
if req.GetAll() {
4646
installedVersion := ""
4747
if platformRelease == nil { // if the platform is not installed
4848
platformRelease = platform.GetLatestRelease()
@@ -65,7 +65,7 @@ func PlatformList(req *rpc.PlatformListRequest) (*rpc.PlatformListResponse, erro
6565
}
6666

6767
// show only the updatable platforms
68-
if req.UpdatableOnly && latest == platformRelease {
68+
if req.GetUpdatableOnly() && latest == platformRelease {
6969
continue
7070
}
7171

@@ -78,10 +78,10 @@ func PlatformList(req *rpc.PlatformListRequest) (*rpc.PlatformListResponse, erro
7878
}
7979
// Sort result alphabetically and put deprecated platforms at the bottom
8080
sort.Slice(res, func(i, j int) bool {
81-
return strings.ToLower(res[i].Name) < strings.ToLower(res[j].Name)
81+
return strings.ToLower(res[i].GetName()) < strings.ToLower(res[j].GetName())
8282
})
8383
sort.SliceStable(res, func(i, j int) bool {
84-
if !res[i].Deprecated && res[j].Deprecated {
84+
if !res[i].GetDeprecated() && res[j].GetDeprecated() {
8585
return true
8686
}
8787
return false

commands/core/search.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ func PlatformSearch(req *rpc.PlatformSearchRequest) (*rpc.PlatformSearchResponse
3737
defer release()
3838

3939
res := []*cores.PlatformRelease{}
40-
if isUsb, _ := regexp.MatchString("[0-9a-f]{4}:[0-9a-f]{4}", req.SearchArgs); isUsb {
41-
vid, pid := req.SearchArgs[:4], req.SearchArgs[5:]
40+
if isUsb, _ := regexp.MatchString("[0-9a-f]{4}:[0-9a-f]{4}", req.GetSearchArgs()); isUsb {
41+
vid, pid := req.GetSearchArgs()[:4], req.GetSearchArgs()[5:]
4242
res = pme.FindPlatformReleaseProvidingBoardsWithVidPid(vid, pid)
4343
} else {
44-
searchArgs := utils.SearchTermsFromQueryString(req.SearchArgs)
45-
allVersions := req.AllVersions
44+
searchArgs := utils.SearchTermsFromQueryString(req.GetSearchArgs())
45+
allVersions := req.GetAllVersions()
4646
for _, targetPackage := range pme.GetPackages() {
4747
for _, platform := range targetPackage.Platforms {
4848
// Users can install platforms manually in the Sketchbook hardware folder,
@@ -93,11 +93,11 @@ func PlatformSearch(req *rpc.PlatformSearchRequest) (*rpc.PlatformSearchResponse
9393
// Sort result alphabetically and put deprecated platforms at the bottom
9494
sort.Slice(
9595
out, func(i, j int) bool {
96-
return strings.ToLower(out[i].Name) < strings.ToLower(out[j].Name)
96+
return strings.ToLower(out[i].GetName()) < strings.ToLower(out[j].GetName())
9797
})
9898
sort.SliceStable(
9999
out, func(i, j int) bool {
100-
if !out[i].Deprecated && out[j].Deprecated {
100+
if !out[i].GetDeprecated() && out[j].GetDeprecated() {
101101
return true
102102
}
103103
return false

0 commit comments

Comments
 (0)