Files
grosbeak/internal/domain64/domain64.go
2025-11-30 14:06:55 -05:00

51 lines
1.2 KiB
Go

package domain64
type Domain64 struct {
// The TLD is FF
TLD int64
// The Domain is FFFFFF, so the uint16 is the closest we'll get
Domain int64
// Subdomains are FF
Subdomain int64
// Paths are, again, FFFFFF
Path int64
}
/*
```mermaid
packet-beta
0-7: "FF | TLD"
8-31: "FFFFFF | Domain"
32-39: "FF | Subdomain"
40-63: "FFFFFF | Path"
```
*/
const SHIFT_TLD = (64 - 8)
const SHIFT_DOMAIN = (64 - (8 + 24))
const SHIFT_SUBDOMAIN = (64 - (8 + 24 + 8))
const SHIFT_PATH = (64 - (8 + 24 + 8 + 24))
const MASK_TLD = 0xFF0000000000000
const MASK_DOMAIN = 0x00FFFFFF00000000
const MASK_SUBDOMAIN = 0x00000000FF000000
const MASK_PATH = 0x0000000000FFFFFF
func (d64 Domain64) ToInt64() int64 {
var result int64 = 0
result = result | (int64(d64.TLD) << SHIFT_TLD)
result = result | (int64(d64.Domain) << SHIFT_DOMAIN)
result = result | (int64(d64.Subdomain) << SHIFT_SUBDOMAIN)
result = result | (int64(d64.Path) << SHIFT_PATH)
return result
}
func IntToDomain64(i int64) Domain64 {
d64 := Domain64{}
d64.TLD = (i & MASK_TLD) >> SHIFT_TLD
d64.Domain = (i & MASK_DOMAIN) >> SHIFT_DOMAIN
d64.Subdomain = (i & MASK_SUBDOMAIN) >> SHIFT_SUBDOMAIN
d64.Path = i & MASK_PATH
return d64
}