Skip to content

Instantly share code, notes, and snippets.

@macalinao
Created November 17, 2016 23:35
Show Gist options
  • Save macalinao/02f873d8a70845a31439516b5f1d7258 to your computer and use it in GitHub Desktop.
Save macalinao/02f873d8a70845a31439516b5f1d7258 to your computer and use it in GitHub Desktop.
// deserializeBonusSet works for masteries, runes, and keystones.
func deserializeBonusSet(s string) (map[uint32]uint32, error) {
ret := map[uint32]uint32{}
// no runes
if len(s) == 0 {
return ret, nil
}
// get rune counts
rs := strings.Split(s, "|")
for _, r := range rs {
id, ct, err := deserializeBonusSetElement(r)
if err != nil {
return nil, err
}
// assign
ret[uint32(id)] = uint32(ct)
}
return ret, nil
}
func deserializeBonusSetElement(s string) (uint32, uint32, error) {
// No element
if s == "" {
return 0, 0, nil
}
// get data of rune count
ps := strings.Split(s, ":")
// rune id
id, err := strconv.Atoi(ps[0])
// rune count
ct, err := strconv.Atoi(ps[2])
// check for strconv errors
if err != nil {
return 0, 0, err
}
return uint32(id), uint32(ct), nil
}
def deserializeBonusSet(serialized: String): Map[Int, Int] = {
serialized.split("|").map { part =>
var element = part.split(":").map(_.toInt)
(element(0), element(1))
}.toMap
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment