forked from credondocr/dota2api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsteamId.go
More file actions
45 lines (36 loc) · 697 Bytes
/
steamId.go
File metadata and controls
45 lines (36 loc) · 697 Bytes
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package dota2api
import "errors"
const uint32Max = uint64(^uint32(0))
type SteamId struct {
id uint64
isId64 bool
}
func (s SteamId) SteamId64() (uint64, error) {
if s.isId64 {
return s.id, nil
}
return s.id, errors.New("expected 64bit steamId")
}
func (s SteamId) SteamId32() uint32 {
return uint32(s.id & uint32Max)
}
func (s *SteamId) SetSteamId32(id uint32) {
s.isId64 = false
s.id = uint64(id)
}
func (s *SteamId) SetSteamId64(id uint64) {
s.isId64 = true
s.id = id
}
func NewSteamIdFrom64(id uint64) SteamId {
return SteamId{
id: id,
isId64: true,
}
}
func NewSteamIdFrom32(id uint32) SteamId {
return SteamId{
id: uint64(id),
isId64: false,
}
}