Skip to content

Commit 44c1920

Browse files
committed
Added easyjson to package_index.json parser
1 parent d3c22a1 commit 44c1920

File tree

2 files changed

+1349
-2
lines changed

2 files changed

+1349
-2
lines changed

arduino/cores/packageindex/index.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,20 @@ import (
2424
"github.com/arduino/arduino-cli/arduino/security"
2525
"github.com/arduino/arduino-cli/i18n"
2626
"github.com/arduino/go-paths-helper"
27+
easyjson "github.com/mailru/easyjson"
2728
"github.com/sirupsen/logrus"
2829
semver "go.bug.st/relaxed-semver"
2930
)
3031

3132
// Index represents Cores and Tools struct as seen from package_index.json file.
33+
//easyjson:json
3234
type Index struct {
3335
Packages []*indexPackage `json:"packages"`
3436
IsTrusted bool
3537
}
3638

3739
// indexPackage represents a single entry from package_index.json file.
40+
//easyjson:json
3841
type indexPackage struct {
3942
Name string `json:"name"`
4043
Maintainer string `json:"maintainer"`
@@ -47,6 +50,7 @@ type indexPackage struct {
4750
}
4851

4952
// indexPlatformRelease represents a single Core Platform from package_index.json file.
53+
//easyjson:json
5054
type indexPlatformRelease struct {
5155
Name string `json:"name"`
5256
Architecture string `json:"architecture"`
@@ -65,32 +69,37 @@ type indexPlatformRelease struct {
6569
}
6670

6771
// indexToolDependency represents a single dependency of a core from a tool.
72+
//easyjson:json
6873
type indexToolDependency struct {
6974
Packager string `json:"packager"`
7075
Name string `json:"name"`
7176
Version *semver.RelaxedVersion `json:"version"`
7277
}
7378

7479
// indexDiscoveryDependency represents a single dependency of a core from a pluggable discovery tool.
80+
//easyjson:json
7581
type indexDiscoveryDependency struct {
7682
Packager string `json:"packager"`
7783
Name string `json:"name"`
7884
}
7985

8086
// indexMonitorDependency represents a single dependency of a core from a pluggable monitor tool.
87+
//easyjson:json
8188
type indexMonitorDependency struct {
8289
Packager string `json:"packager"`
8390
Name string `json:"name"`
8491
}
8592

8693
// indexToolRelease represents a single Tool from package_index.json file.
94+
//easyjson:json
8795
type indexToolRelease struct {
8896
Name string `json:"name"`
8997
Version *semver.RelaxedVersion `json:"version"`
9098
Systems []indexToolReleaseFlavour `json:"systems"`
9199
}
92100

93101
// indexToolReleaseFlavour represents a single tool flavor in the package_index.json file.
102+
//easyjson:json
94103
type indexToolReleaseFlavour struct {
95104
OS string `json:"host"`
96105
URL string `json:"url"`
@@ -100,17 +109,20 @@ type indexToolReleaseFlavour struct {
100109
}
101110

102111
// indexBoard represents a single Board as written in package_index.json file.
112+
//easyjson:json
103113
type indexBoard struct {
104114
Name string `json:"name"`
105115
ID []indexBoardID `json:"id,omitempty"`
106116
}
107117

108118
// indexBoardID represents the ID of a single board. i.e. uno, yun, diecimila, micro and the likes
119+
//easyjson:json
109120
type indexBoardID struct {
110121
USB string `json:"usb"`
111122
}
112123

113124
// indexHelp represents the help URL
125+
//easyjson:json
114126
type indexHelp struct {
115127
Online string `json:"online,omitempty"`
116128
}
@@ -352,7 +364,7 @@ func LoadIndex(jsonIndexFile *paths.Path) (*Index, error) {
352364
return nil, err
353365
}
354366
var index Index
355-
err = json.Unmarshal(buff, &index)
367+
err = easyjson.Unmarshal(buff, &index)
356368
if err != nil {
357369
return nil, err
358370
}
@@ -381,7 +393,7 @@ func LoadIndexNoSign(jsonIndexFile *paths.Path) (*Index, error) {
381393
return nil, err
382394
}
383395
var index Index
384-
err = json.Unmarshal(buff, &index)
396+
err = easyjson.Unmarshal(buff, &index)
385397
if err != nil {
386398
return nil, err
387399
}

0 commit comments

Comments
 (0)