+// DecodeInt decodes the field bytes to an int.
+// The official Hotline clients will send uint32s as 2 bytes if possible, but
+// some third party clients such as Frogblast and Heildrun will always send 4 bytes
+func (f *Field) DecodeInt() (int, error) {
+ switch len(f.Data) {
+ case 2:
+ return int(binary.BigEndian.Uint16(f.Data)), nil
+ case 4:
+ return int(binary.BigEndian.Uint32(f.Data)), nil
+ }
+
+ return 0, errors.New("unknown byte length")
+}
+
+func (f *Field) DecodeObfuscatedString() string {
+ return string(EncodeString(f.Data))
+}
+
+// DecodeNewsPath decodes the field data to a news path.
+// Example News Path data for a Category nested under two Bundles:
+// 00000000 00 03 00 00 10 54 6f 70 20 4c 65 76 65 6c 20 42 |.....Top Level B|
+// 00000010 75 6e 64 6c 65 00 00 13 53 65 63 6f 6e 64 20 4c |undle...Second L|
+// 00000020 65 76 65 6c 20 42 75 6e 64 6c 65 00 00 0f 4e 65 |evel Bundle...Ne|
+// 00000030 73 74 65 64 20 43 61 74 65 67 6f 72 79 |sted Category|
+func (f *Field) DecodeNewsPath() ([]string, error) {
+ if len(f.Data) == 0 {
+ return []string{}, nil
+ }
+
+ pathCount := binary.BigEndian.Uint16(f.Data[0:2])
+
+ scanner := bufio.NewScanner(bytes.NewReader(f.Data[2:]))
+ scanner.Split(newsPathScanner)
+
+ var paths []string
+
+ for i := uint16(0); i < pathCount; i++ {
+ scanner.Scan()
+ paths = append(paths, scanner.Text())
+ }
+
+ return paths, nil
+}
+