Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Alfus committed Jan 21, 2025
1 parent 755109d commit ca8cddd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
7 changes: 3 additions & 4 deletions decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -1304,8 +1304,7 @@ func parseDurationNext(str string, totalNanos *big.Int) (string, error) {
var bytesUnitNames = []string{"K", "M", "G", "T", "P", "E", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei"}

// A map from unit to the number of bytes in that unit.
var bytesPerUnitMap = map[string]uint64{
"": 1,
var bytesPerUnitMap = map[string]int64{
"K": 1000,
"Ki": 1 << 10,
"M": 1000 * 1000,
Expand Down Expand Up @@ -1336,13 +1335,13 @@ func parseBytes(str string, totalBytes *big.Int) (string, error) {
if whole > 0 {
wholeBytes := &big.Int{}
wholeBytes.SetUint64(whole)
wholeBytes.Mul(wholeBytes, big.NewInt(int64(bytesPerUnit)))
wholeBytes.Mul(wholeBytes, big.NewInt(bytesPerUnit))
totalBytes.Add(totalBytes, wholeBytes)
}
if frac > 0 {
fracBytes := &big.Int{}
fracBytes.SetUint64(frac)
fracBytes.Mul(fracBytes, big.NewInt(int64(bytesPerUnit)))
fracBytes.Mul(fracBytes, big.NewInt(bytesPerUnit))
rem := &big.Int{}
fracBytes.QuoRem(fracBytes, scale, rem)
totalBytes.Add(totalBytes, fracBytes)
Expand Down
4 changes: 4 additions & 0 deletions internal/testdata/basic.proto3test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,7 @@ internal/testdata/basic.proto3test.yaml:144:19 integer is too small: < -21474836
internal/testdata/basic.proto3test.yaml:145:19 invalid integer: invalid bytes: unknown unit, expected one of [K M G T P E Ki Mi Gi Ti Pi Ei]
145 | - single_int32: 1Ai
145 | ..................^

internal/testdata/basic.proto3test.yaml:146:19 invalid integer: precision loss
146 | - single_int32: 1.1
146 | ..................^
1 change: 1 addition & 0 deletions internal/testdata/basic.proto3test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,4 @@ values:
- single_int32: -1Ki
- single_int32: -1Ti
- single_int32: 1Ai
- single_int32: 1.1

0 comments on commit ca8cddd

Please sign in to comment.