mirror of
https://github.com/Luzifer/sii.git
synced 2024-12-21 00:21:15 +00:00
Fix: Looks like SOME positions are arrays of int 😭
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
8cf339ecb2
commit
9c22ab945c
4 changed files with 46 additions and 6 deletions
|
@ -53,17 +53,17 @@ type Economy struct {
|
|||
StoredRainWetness int64 `sii:"stored_rain_wetness"`
|
||||
TimeZone int64 `sii:"time_zone"`
|
||||
TimeZoneName string `sii:"time_zone_name"`
|
||||
LastFerryPosition [3]float32 `sii:"last_ferry_position"`
|
||||
LastFerryPosition [3]int64 `sii:"last_ferry_position"`
|
||||
StoredShowWeigh bool `sii:"stored_show_weigh"`
|
||||
StoredNeedToWeigh bool `sii:"stored_need_to_weigh"`
|
||||
StoredNavStartPos [3]float32 `sii:"stored_nav_start_pos"`
|
||||
StoredNavEndPos [3]float32 `sii:"stored_nav_end_pos"`
|
||||
StoredNavStartPos [3]int64 `sii:"stored_nav_start_pos"`
|
||||
StoredNavEndPos [3]int64 `sii:"stored_nav_end_pos"`
|
||||
StoredGPSBehind int64 `sii:"stored_gps_behind"`
|
||||
StoredGPSAhead int64 `sii:"stored_gps_ahead"`
|
||||
StoredGPSBehindWaypoints []Ptr `sii:"stored_gps_behind_waypoints"`
|
||||
StoredGPSAheadWaypoints []Ptr `sii:"stored_gps_ahead_waypoints"`
|
||||
StoredGPSAvoidWaypoints []Ptr `sii:"stored_gps_avoid_waypoints"`
|
||||
StoredStartTollgatePos [3]float32 `sii:"stored_start_tollgate_pos"`
|
||||
StoredStartTollgatePos [3]int64 `sii:"stored_start_tollgate_pos"`
|
||||
StoredTutorialState int64 `sii:"stored_tutorial_state"`
|
||||
StoredMapActions []Ptr `sii:"stored_map_actions"`
|
||||
CleanDistanceCounter int64 `sii:"clean_distance_counter"`
|
||||
|
|
|
@ -5,7 +5,7 @@ func init() {
|
|||
}
|
||||
|
||||
type GPSWaypointStorage struct {
|
||||
NavNodePosition [3]float32 `sii:"nav_node_position"`
|
||||
NavNodePosition [3]int64 `sii:"nav_node_position"`
|
||||
Direction Ptr `sii:"direction"`
|
||||
|
||||
blockName string
|
||||
|
|
|
@ -104,6 +104,24 @@ func genericMarshal(in interface{}) ([]byte, error) {
|
|||
|
||||
buf.WriteString(fmt.Sprintf(" %s: (%s)\n", attributeName, bytes.Join(vals, []byte(", "))))
|
||||
|
||||
case reflect.Int64:
|
||||
var vals [][]byte
|
||||
|
||||
switch typeField.Type.Len() {
|
||||
|
||||
case 3:
|
||||
for _, v := range valField.Interface().([3]int64) {
|
||||
bv := []byte(strconv.FormatInt(v, 10))
|
||||
vals = append(vals, bv)
|
||||
}
|
||||
|
||||
default:
|
||||
return nil, errors.Errorf("Unsupported type: [%d]%s", typeField.Type.Len(), typeField.Type.Elem().Kind())
|
||||
|
||||
}
|
||||
|
||||
buf.WriteString(fmt.Sprintf(" %s: (%s)\n", attributeName, bytes.Join(vals, []byte(", "))))
|
||||
|
||||
default:
|
||||
return nil, errors.Errorf("Unsupported type: [%d]%s", typeField.Type.Len(), typeField.Type.Elem().Kind())
|
||||
|
||||
|
|
|
@ -131,6 +131,28 @@ func genericUnmarshal(in []byte, out interface{}, unit *Unit) error {
|
|||
|
||||
}
|
||||
|
||||
case reflect.Int64:
|
||||
switch typeField.Type.Len() {
|
||||
|
||||
case 3:
|
||||
grps := regexp.MustCompile(`^\(([0-9.-]+), ([0-9.-]+), ([0-9.-]+)\)$`).
|
||||
FindSubmatch(getSingleValue(in, attributeName))
|
||||
var v [3]int64
|
||||
|
||||
for i := range v {
|
||||
val, err := strconv.ParseInt(string(grps[i+1][:]), 10, 64)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "Unable to parse int64 for attribute %q", attributeName)
|
||||
}
|
||||
v[i] = val
|
||||
}
|
||||
valField.Set(reflect.ValueOf(v))
|
||||
|
||||
default:
|
||||
return errors.Errorf("Unsupported type: [%d]%s", typeField.Type.Len(), typeField.Type.Elem().Kind())
|
||||
|
||||
}
|
||||
|
||||
default:
|
||||
return errors.Errorf("Unsupported type: [%d]%s", typeField.Type.Len(), typeField.Type.Elem().Kind())
|
||||
|
||||
|
|
Loading…
Reference in a new issue