1
0
Fork 0
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:
Knut Ahlers 2019-12-23 21:32:10 +01:00
parent 8cf339ecb2
commit 9c22ab945c
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E
4 changed files with 46 additions and 6 deletions

View file

@ -53,17 +53,17 @@ type Economy struct {
StoredRainWetness int64 `sii:"stored_rain_wetness"` StoredRainWetness int64 `sii:"stored_rain_wetness"`
TimeZone int64 `sii:"time_zone"` TimeZone int64 `sii:"time_zone"`
TimeZoneName string `sii:"time_zone_name"` 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"` StoredShowWeigh bool `sii:"stored_show_weigh"`
StoredNeedToWeigh bool `sii:"stored_need_to_weigh"` StoredNeedToWeigh bool `sii:"stored_need_to_weigh"`
StoredNavStartPos [3]float32 `sii:"stored_nav_start_pos"` StoredNavStartPos [3]int64 `sii:"stored_nav_start_pos"`
StoredNavEndPos [3]float32 `sii:"stored_nav_end_pos"` StoredNavEndPos [3]int64 `sii:"stored_nav_end_pos"`
StoredGPSBehind int64 `sii:"stored_gps_behind"` StoredGPSBehind int64 `sii:"stored_gps_behind"`
StoredGPSAhead int64 `sii:"stored_gps_ahead"` StoredGPSAhead int64 `sii:"stored_gps_ahead"`
StoredGPSBehindWaypoints []Ptr `sii:"stored_gps_behind_waypoints"` StoredGPSBehindWaypoints []Ptr `sii:"stored_gps_behind_waypoints"`
StoredGPSAheadWaypoints []Ptr `sii:"stored_gps_ahead_waypoints"` StoredGPSAheadWaypoints []Ptr `sii:"stored_gps_ahead_waypoints"`
StoredGPSAvoidWaypoints []Ptr `sii:"stored_gps_avoid_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"` StoredTutorialState int64 `sii:"stored_tutorial_state"`
StoredMapActions []Ptr `sii:"stored_map_actions"` StoredMapActions []Ptr `sii:"stored_map_actions"`
CleanDistanceCounter int64 `sii:"clean_distance_counter"` CleanDistanceCounter int64 `sii:"clean_distance_counter"`

View file

@ -5,8 +5,8 @@ func init() {
} }
type GPSWaypointStorage struct { type GPSWaypointStorage struct {
NavNodePosition [3]float32 `sii:"nav_node_position"` NavNodePosition [3]int64 `sii:"nav_node_position"`
Direction Ptr `sii:"direction"` Direction Ptr `sii:"direction"`
blockName string blockName string
} }

View file

@ -104,6 +104,24 @@ func genericMarshal(in interface{}) ([]byte, error) {
buf.WriteString(fmt.Sprintf(" %s: (%s)\n", attributeName, bytes.Join(vals, []byte(", ")))) 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: default:
return nil, errors.Errorf("Unsupported type: [%d]%s", typeField.Type.Len(), typeField.Type.Elem().Kind()) return nil, errors.Errorf("Unsupported type: [%d]%s", typeField.Type.Len(), typeField.Type.Elem().Kind())

View file

@ -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: default:
return errors.Errorf("Unsupported type: [%d]%s", typeField.Type.Len(), typeField.Type.Elem().Kind()) return errors.Errorf("Unsupported type: [%d]%s", typeField.Type.Len(), typeField.Type.Elem().Kind())