Skip to content

Commit

Permalink
Merge pull request #6 from tidepool-org/use-decimals
Browse files Browse the repository at this point in the history
Use int32 for fixed decimal units
  • Loading branch information
toddkazakov authored Jul 9, 2020
2 parents 8a4aafb + 7f8347c commit 3d1edbd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
6 changes: 3 additions & 3 deletions api/api.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ message RecommendedBounds {

message FixedDecimal {
// The whole units of the amount
int64 units = 1;
int32 units = 1;

// Number of nano (10^-9) units of the amount.
int32 nanos = 2;
Expand Down
11 changes: 5 additions & 6 deletions config/devices.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ type Bounds struct {
}

type FixedDecimal struct {
Units int64 `yaml:"units"`
Units int32 `yaml:"units"`
Nanos int32 `yaml:"units"`
}

Expand All @@ -92,8 +92,7 @@ func ParseFixedDecimal(value string, decimal *FixedDecimal) error {
return errors.New(fmt.Sprintf("invalid fixed decimal value %v", value))
}

var units int64
var nanos int32
var units, nanos int32
units, err := parseFixedDecimalUnits(split[0])
if err != nil {
return err
Expand All @@ -115,15 +114,15 @@ func ParseFixedDecimal(value string, decimal *FixedDecimal) error {
return nil
}

func parseFixedDecimalUnits(value string) (int64, error) {
func parseFixedDecimalUnits(value string) (int32, error) {
if len(value) == 0 {
return 0, nil
}
val, err := strconv.ParseInt(value, 10, 64)
val, err := strconv.ParseInt(value, 10, 32)
if err != nil {
return 0, err
}
return val, nil
return int32(val), nil
}

func parseFixedDecimalNanos(value string) (int32, error) {
Expand Down

0 comments on commit 3d1edbd

Please sign in to comment.