summaryrefslogtreecommitdiff
path: root/srv/src/chat/util.go
blob: 05f4830d7a4eb934db18663b827a9bf1c1424ed6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package chat

import (
	"strconv"
	"strings"

	"github.com/mediocregopher/radix/v4"
)

func parseStreamEntryID(str string) (radix.StreamEntryID, error) {

	split := strings.SplitN(str, "-", 2)
	if len(split) != 2 {
		return radix.StreamEntryID{}, errInvalidMessageID
	}

	time, err := strconv.ParseUint(split[0], 10, 64)
	if err != nil {
		return radix.StreamEntryID{}, errInvalidMessageID
	}

	seq, err := strconv.ParseUint(split[1], 10, 64)
	if err != nil {
		return radix.StreamEntryID{}, errInvalidMessageID
	}

	return radix.StreamEntryID{Time: time, Seq: seq}, nil
}