Fix: Use 16 bit variables for GPS degree/minute/second

This commit is contained in:
Matthias Beyer 2018-04-28 23:00:32 +02:00
parent bfd536d3fb
commit 5870fa0785

View file

@ -34,14 +34,14 @@ pub trait FromValue : Sized {
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)] #[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
pub struct GPSValue { pub struct GPSValue {
pub degree: i8, pub degree: i32,
pub minutes: i8, pub minutes: i32,
pub seconds: i8 pub seconds: i32,
} }
impl GPSValue { impl GPSValue {
pub fn new(d: i8, m: i8, s: i8) -> GPSValue { pub fn new(d: i32, m: i32, s: i32) -> GPSValue {
GPSValue { GPSValue {
degree: d, degree: d,
minutes: m, minutes: m,
@ -49,15 +49,15 @@ impl GPSValue {
} }
} }
pub fn degree(&self) -> i8 { pub fn degree(&self) -> i32 {
self.degree self.degree
} }
pub fn minutes(&self) -> i8 { pub fn minutes(&self) -> i32 {
self.minutes self.minutes
} }
pub fn seconds(&self) -> i8 { pub fn seconds(&self) -> i32 {
self.seconds self.seconds
} }
@ -80,7 +80,7 @@ impl FromValue for GPSValue {
fn from_value(v: &Value) -> Result<Self> { fn from_value(v: &Value) -> Result<Self> {
let int_to_appropriate_width = |v: &Value| { let int_to_appropriate_width = |v: &Value| {
v.as_integer() v.as_integer()
.ok_or(GPSE::from_kind(GPSEK::HeaderTypeError)).and_then(i64_to_i8) .ok_or(GPSE::from_kind(GPSEK::HeaderTypeError)).and_then(i64_to_i32)
}; };
match *v { match *v {
@ -172,12 +172,12 @@ impl Display for Coordinates {
} }
} }
/// Helper to convert a i64 to i8 or return an error if this doesn't work. /// Helper to convert a i64 to i32 or return an error if this doesn't work.
fn i64_to_i8(i: i64) -> Result<i8> { fn i64_to_i32(i: i64) -> Result<i32> {
if i > (<i8>::max_value() as i64) { if i > (<i32>::max_value() as i64) {
Err(GPSE::from_kind(GPSEK::NumberConversionError)) Err(GPSE::from_kind(GPSEK::NumberConversionError))
} else { } else {
Ok(i as i8) Ok(i as i32)
} }
} }