github.com/GeniusesGroup/libgo@v0.0.0-20220929090155-5ff932cb408e/gp/address.go (about) 1 /* For license and copyright information please see LEGAL file in repository */ 2 3 package gp 4 5 // Addr present GP address with needed methods 6 type Addr [16]byte 7 8 // Some global address 9 var ( 10 AddrNil = Addr{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} 11 ) 12 13 // PlanetID returns planet ID. 14 func (addr Addr) PlanetID() uint16 { 15 return uint16(addr[0]) | uint16(addr[1])<<8 16 } 17 18 // SocietyID returns society ID. 19 func (addr Addr) SocietyID() uint32 { 20 return uint32(addr[2]) | uint32(addr[3])<<8 | uint32(addr[4])<<16 | uint32(addr[5])<<24 21 } 22 23 // RouterID returns router ID in the society scope. 24 func (addr Addr) RouterID() uint32 { 25 return uint32(addr[6]) | uint32(addr[7])<<8 | uint32(addr[8])<<16 | uint32(addr[9])<<24 26 } 27 28 // UserID returns user ID in the router scope. 29 func (addr Addr) UserID() uint32 { 30 return uint32(addr[10]) | uint32(addr[11])<<8 | uint32(addr[12])<<16 | uint32(addr[13])<<24 31 } 32 33 // AppID returns app ID in the user scope. 34 func (addr Addr) AppID() uint16 { 35 return uint16(addr[14]) | uint16(addr[15])<<8 36 } 37 38 // SetPlanetID set planet ID in given Addr. 39 func (addr Addr) SetPlanetID(id uint16) { 40 addr[0] = byte(id) 41 addr[1] = byte(id >> 8) 42 } 43 44 // SetSocietyID set society ID in given Addr. 45 func (addr Addr) SetSocietyID(id uint32) { 46 addr[2] = byte(id) 47 addr[3] = byte(id >> 8) 48 addr[4] = byte(id >> 16) 49 addr[5] = byte(id >> 24) 50 } 51 52 // SetRouterID set router ID in given Addr. 53 func (addr Addr) SetRouterID(id uint32) { 54 addr[6] = byte(id) 55 addr[7] = byte(id >> 8) 56 addr[8] = byte(id >> 16) 57 addr[9] = byte(id >> 24) 58 } 59 60 // SetUserID set user ID in given Addr. 61 func (addr Addr) SetUserID(id uint32) { 62 addr[10] = byte(id) 63 addr[11] = byte(id >> 8) 64 addr[12] = byte(id >> 16) 65 addr[13] = byte(id >> 24) 66 } 67 68 // SetAppID set app ID in given Addr. 69 func (addr Addr) SetAppID(id uint32) { 70 addr[14] = byte(id) 71 addr[15] = byte(id >> 8) 72 }