...
This commit is contained in:
@@ -4,6 +4,7 @@ import encoding.binary as bin
|
||||
import freeflowuniverse.herolib.data.ourtime
|
||||
import time
|
||||
import freeflowuniverse.herolib.data.gid
|
||||
import freeflowuniverse.herolib.data.currency
|
||||
|
||||
pub struct Decoder {
|
||||
pub mut:
|
||||
@@ -148,6 +149,18 @@ pub fn (mut d Decoder) get_ourtime() !ourtime.OurTime {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn (mut d Decoder) get_currency() !currency.Amount {
|
||||
curstring:=d.get_string()!
|
||||
if curstring.len == 0 {
|
||||
return error('currency string is empty')
|
||||
}
|
||||
currencyo := currency.get(curstring)!
|
||||
return currency.Amount{
|
||||
currency: currencyo
|
||||
val: d.get_f64()!
|
||||
}
|
||||
}
|
||||
|
||||
pub fn (mut d Decoder) get_percentage() !u8 {
|
||||
val := d.get_u8()!
|
||||
if val > 100 {
|
||||
|
||||
@@ -4,6 +4,7 @@ import time
|
||||
import encoding.binary as bin
|
||||
import freeflowuniverse.herolib.data.ourtime
|
||||
import freeflowuniverse.herolib.data.gid
|
||||
import freeflowuniverse.herolib.data.currency
|
||||
|
||||
const kb = 1024
|
||||
|
||||
@@ -102,6 +103,12 @@ pub fn (mut b Encoder) add_ourtime(data ourtime.OurTime) {
|
||||
b.add_u32(u32(data.unixt))
|
||||
}
|
||||
|
||||
pub fn (mut b Encoder) add_currency(data currency.Amount) {
|
||||
b.add_string(data.currency.name)
|
||||
b.add_f64(data.val)
|
||||
}
|
||||
|
||||
|
||||
// adds a float64 value
|
||||
pub fn (mut b Encoder) add_f64(data f64) {
|
||||
// Convert f64 to bits first, then store as u64
|
||||
|
||||
Reference in New Issue
Block a user