aboutsummaryrefslogtreecommitdiff
path: root/hotline/decode.go
blob: 385bc072a814a89957b8ca14bdd23592f51aedbf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package hotline

// ClientIDFromBytes converts client-supplied bytes to a ClientID, returning
// ok=false if the input is not exactly the expected length. Use this instead of
// a direct [2]byte(...) conversion on field data, which panics on a length
// mismatch.
func ClientIDFromBytes(b []byte) (id ClientID, ok bool) {
	if len(b) != len(id) {
		return id, false
	}
	return ClientID(b), true
}

// ChatIDFromBytes converts client-supplied bytes to a ChatID, returning ok=false
// if the input is not exactly the expected length. Use this instead of a direct
// [4]byte(...) conversion on field data, which panics on a length mismatch.
func ChatIDFromBytes(b []byte) (id ChatID, ok bool) {
	if len(b) != len(id) {
		return id, false
	}
	return ChatID(b), true
}