package domain64 type Domain64 struct { // The TLD is FF TLD uint8 // The Domain is FFFFFF, so the uint16 is the closest we'll get Domain uint16 // Subdomains are FF Subdomain uint8 // Paths are, again, FFFFFF Path uint16 } /* ```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 = uint8((i & MASK_TLD) >> SHIFT_TLD) d64.Domain = uint16((i & MASK_DOMAIN) >> SHIFT_DOMAIN) d64.Subdomain = uint8((i & MASK_SUBDOMAIN) >> SHIFT_SUBDOMAIN) d64.Path = uint16(i & MASK_PATH) return d64 }