package storage import ( "io" "time" "unsafe" ) var ( _ = unsafe.Sizeof(0) _ = io.ReadFull _ = time.Now() ) func (d *User) Size() (s uint64) { { l := uint64(len(d.Username)) { t := l for t >= 0x80 { t <<= 7 s++ } s++ } s += l } s += 8 return } func (d *User) Marshal(buf []byte) ([]byte, error) { size := d.Size() { if uint64(cap(buf)) >= size { buf = buf[:size] } else { buf = make([]byte, size) } } i := uint64(0) { buf[i+0+0] = byte(d.ID >> 0) buf[i+1+0] = byte(d.ID >> 8) buf[i+2+0] = byte(d.ID >> 16) buf[i+3+0] = byte(d.ID >> 24) buf[i+4+0] = byte(d.ID >> 32) buf[i+5+0] = byte(d.ID >> 40) buf[i+6+0] = byte(d.ID >> 48) buf[i+7+0] = byte(d.ID >> 56) } { l := uint64(len(d.Username)) { t := uint64(l) for t >= 0x80 { buf[i+8] = byte(t) | 0x80 t >>= 7 i++ } buf[i+8] = byte(t) i++ } copy(buf[i+8:], d.Username) i += l } return buf[:i+8], nil } func (d *User) Unmarshal(buf []byte) (uint64, error) { i := uint64(0) { d.ID = 0 | (uint64(buf[i+0+0]) << 0) | (uint64(buf[i+1+0]) << 8) | (uint64(buf[i+2+0]) << 16) | (uint64(buf[i+3+0]) << 24) | (uint64(buf[i+4+0]) << 32) | (uint64(buf[i+5+0]) << 40) | (uint64(buf[i+6+0]) << 48) | (uint64(buf[i+7+0]) << 56) } { l := uint64(0) { bs := uint8(7) t := uint64(buf[i+8] & 0x7F) for buf[i+8]&0x80 == 0x80 { i++ t |= uint64(buf[i+8]&0x7F) << bs bs += 7 } i++ l = t } d.Username = string(buf[i+8 : i+8+l]) i += l } return i + 8, nil } func (d *Server) Size() (s uint64) { { l := uint64(len(d.Name)) { t := l for t >= 0x80 { t <<= 7 s++ } s++ } s += l } { l := uint64(len(d.Host)) { t := l for t >= 0x80 { t <<= 7 s++ } s++ } s += l } { l := uint64(len(d.Port)) { t := l for t >= 0x80 { t <<= 7 s++ } s++ } s += l } { l := uint64(len(d.Password)) { t := l for t >= 0x80 { t <<= 7 s++ } s++ } s += l } { l := uint64(len(d.Nick)) { t := l for t >= 0x80 { t <<= 7 s++ } s++ } s += l } { l := uint64(len(d.Username)) { t := l for t >= 0x80 { t <<= 7 s++ } s++ } s += l } { l := uint64(len(d.Realname)) { t := l for t >= 0x80 { t <<= 7 s++ } s++ } s += l } s += 1 return } func (d *Server) Marshal(buf []byte) ([]byte, error) { size := d.Size() { if uint64(cap(buf)) >= size { buf = buf[:size] } else { buf = make([]byte, size) } } i := uint64(0) { l := uint64(len(d.Name)) { t := uint64(l) for t >= 0x80 { buf[i+0] = byte(t) | 0x80 t >>= 7 i++ } buf[i+0] = byte(t) i++ } copy(buf[i+0:], d.Name) i += l } { l := uint64(len(d.Host)) { t := uint64(l) for t >= 0x80 { buf[i+0] = byte(t) | 0x80 t >>= 7 i++ } buf[i+0] = byte(t) i++ } copy(buf[i+0:], d.Host) i += l } { l := uint64(len(d.Port)) { t := uint64(l) for t >= 0x80 { buf[i+0] = byte(t) | 0x80 t >>= 7 i++ } buf[i+0] = byte(t) i++ } copy(buf[i+0:], d.Port) i += l } { if d.TLS { buf[i+0] = 1 } else { buf[i+0] = 0 } } { l := uint64(len(d.Password)) { t := uint64(l) for t >= 0x80 { buf[i+1] = byte(t) | 0x80 t >>= 7 i++ } buf[i+1] = byte(t) i++ } copy(buf[i+1:], d.Password) i += l } { l := uint64(len(d.Nick)) { t := uint64(l) for t >= 0x80 { buf[i+1] = byte(t) | 0x80 t >>= 7 i++ } buf[i+1] = byte(t) i++ } copy(buf[i+1:], d.Nick) i += l } { l := uint64(len(d.Username)) { t := uint64(l) for t >= 0x80 { buf[i+1] = byte(t) | 0x80 t >>= 7 i++ } buf[i+1] = byte(t) i++ } copy(buf[i+1:], d.Username) i += l } { l := uint64(len(d.Realname)) { t := uint64(l) for t >= 0x80 { buf[i+1] = byte(t) | 0x80 t >>= 7 i++ } buf[i+1] = byte(t) i++ } copy(buf[i+1:], d.Realname) i += l } return buf[:i+1], nil } func (d *Server) Unmarshal(buf []byte) (uint64, error) { i := uint64(0) { l := uint64(0) { bs := uint8(7) t := uint64(buf[i+0] & 0x7F) for buf[i+0]&0x80 == 0x80 { i++ t |= uint64(buf[i+0]&0x7F) << bs bs += 7 } i++ l = t } d.Name = string(buf[i+0 : i+0+l]) i += l } { l := uint64(0) { bs := uint8(7) t := uint64(buf[i+0] & 0x7F) for buf[i+0]&0x80 == 0x80 { i++ t |= uint64(buf[i+0]&0x7F) << bs bs += 7 } i++ l = t } d.Host = string(buf[i+0 : i+0+l]) i += l } { l := uint64(0) { bs := uint8(7) t := uint64(buf[i+0] & 0x7F) for buf[i+0]&0x80 == 0x80 { i++ t |= uint64(buf[i+0]&0x7F) << bs bs += 7 } i++ l = t } d.Port = string(buf[i+0 : i+0+l]) i += l } { d.TLS = buf[i+0] == 1 } { l := uint64(0) { bs := uint8(7) t := uint64(buf[i+1] & 0x7F) for buf[i+1]&0x80 == 0x80 { i++ t |= uint64(buf[i+1]&0x7F) << bs bs += 7 } i++ l = t } d.Password = string(buf[i+1 : i+1+l]) i += l } { l := uint64(0) { bs := uint8(7) t := uint64(buf[i+1] & 0x7F) for buf[i+1]&0x80 == 0x80 { i++ t |= uint64(buf[i+1]&0x7F) << bs bs += 7 } i++ l = t } d.Nick = string(buf[i+1 : i+1+l]) i += l } { l := uint64(0) { bs := uint8(7) t := uint64(buf[i+1] & 0x7F) for buf[i+1]&0x80 == 0x80 { i++ t |= uint64(buf[i+1]&0x7F) << bs bs += 7 } i++ l = t } d.Username = string(buf[i+1 : i+1+l]) i += l } { l := uint64(0) { bs := uint8(7) t := uint64(buf[i+1] & 0x7F) for buf[i+1]&0x80 == 0x80 { i++ t |= uint64(buf[i+1]&0x7F) << bs bs += 7 } i++ l = t } d.Realname = string(buf[i+1 : i+1+l]) i += l } return i + 1, nil } func (d *Channel) Size() (s uint64) { { l := uint64(len(d.Server)) { t := l for t >= 0x80 { t <<= 7 s++ } s++ } s += l } { l := uint64(len(d.Name)) { t := l for t >= 0x80 { t <<= 7 s++ } s++ } s += l } { l := uint64(len(d.Topic)) { t := l for t >= 0x80 { t <<= 7 s++ } s++ } s += l } return } func (d *Channel) Marshal(buf []byte) ([]byte, error) { size := d.Size() { if uint64(cap(buf)) >= size { buf = buf[:size] } else { buf = make([]byte, size) } } i := uint64(0) { l := uint64(len(d.Server)) { t := uint64(l) for t >= 0x80 { buf[i+0] = byte(t) | 0x80 t >>= 7 i++ } buf[i+0] = byte(t) i++ } copy(buf[i+0:], d.Server) i += l } { l := uint64(len(d.Name)) { t := uint64(l) for t >= 0x80 { buf[i+0] = byte(t) | 0x80 t >>= 7 i++ } buf[i+0] = byte(t) i++ } copy(buf[i+0:], d.Name) i += l } { l := uint64(len(d.Topic)) { t := uint64(l) for t >= 0x80 { buf[i+0] = byte(t) | 0x80 t >>= 7 i++ } buf[i+0] = byte(t) i++ } copy(buf[i+0:], d.Topic) i += l } return buf[:i+0], nil } func (d *Channel) Unmarshal(buf []byte) (uint64, error) { i := uint64(0) { l := uint64(0) { bs := uint8(7) t := uint64(buf[i+0] & 0x7F) for buf[i+0]&0x80 == 0x80 { i++ t |= uint64(buf[i+0]&0x7F) << bs bs += 7 } i++ l = t } d.Server = string(buf[i+0 : i+0+l]) i += l } { l := uint64(0) { bs := uint8(7) t := uint64(buf[i+0] & 0x7F) for buf[i+0]&0x80 == 0x80 { i++ t |= uint64(buf[i+0]&0x7F) << bs bs += 7 } i++ l = t } d.Name = string(buf[i+0 : i+0+l]) i += l } { l := uint64(0) { bs := uint8(7) t := uint64(buf[i+0] & 0x7F) for buf[i+0]&0x80 == 0x80 { i++ t |= uint64(buf[i+0]&0x7F) << bs bs += 7 } i++ l = t } d.Topic = string(buf[i+0 : i+0+l]) i += l } return i + 0, nil } func (d *Message) Size() (s uint64) { { l := uint64(len(d.Server)) { t := l for t >= 0x80 { t <<= 7 s++ } s++ } s += l } { l := uint64(len(d.From)) { t := l for t >= 0x80 { t <<= 7 s++ } s++ } s += l } { l := uint64(len(d.To)) { t := l for t >= 0x80 { t <<= 7 s++ } s++ } s += l } { l := uint64(len(d.Content)) { t := l for t >= 0x80 { t <<= 7 s++ } s++ } s += l } s += 16 return } func (d *Message) Marshal(buf []byte) ([]byte, error) { size := d.Size() { if uint64(cap(buf)) >= size { buf = buf[:size] } else { buf = make([]byte, size) } } i := uint64(0) { buf[i+0+0] = byte(d.ID >> 0) buf[i+1+0] = byte(d.ID >> 8) buf[i+2+0] = byte(d.ID >> 16) buf[i+3+0] = byte(d.ID >> 24) buf[i+4+0] = byte(d.ID >> 32) buf[i+5+0] = byte(d.ID >> 40) buf[i+6+0] = byte(d.ID >> 48) buf[i+7+0] = byte(d.ID >> 56) } { l := uint64(len(d.Server)) { t := uint64(l) for t >= 0x80 { buf[i+8] = byte(t) | 0x80 t >>= 7 i++ } buf[i+8] = byte(t) i++ } copy(buf[i+8:], d.Server) i += l } { l := uint64(len(d.From)) { t := uint64(l) for t >= 0x80 { buf[i+8] = byte(t) | 0x80 t >>= 7 i++ } buf[i+8] = byte(t) i++ } copy(buf[i+8:], d.From) i += l } { l := uint64(len(d.To)) { t := uint64(l) for t >= 0x80 { buf[i+8] = byte(t) | 0x80 t >>= 7 i++ } buf[i+8] = byte(t) i++ } copy(buf[i+8:], d.To) i += l } { l := uint64(len(d.Content)) { t := uint64(l) for t >= 0x80 { buf[i+8] = byte(t) | 0x80 t >>= 7 i++ } buf[i+8] = byte(t) i++ } copy(buf[i+8:], d.Content) i += l } { buf[i+0+8] = byte(d.Time >> 0) buf[i+1+8] = byte(d.Time >> 8) buf[i+2+8] = byte(d.Time >> 16) buf[i+3+8] = byte(d.Time >> 24) buf[i+4+8] = byte(d.Time >> 32) buf[i+5+8] = byte(d.Time >> 40) buf[i+6+8] = byte(d.Time >> 48) buf[i+7+8] = byte(d.Time >> 56) } return buf[:i+16], nil } func (d *Message) Unmarshal(buf []byte) (uint64, error) { i := uint64(0) { d.ID = 0 | (uint64(buf[i+0+0]) << 0) | (uint64(buf[i+1+0]) << 8) | (uint64(buf[i+2+0]) << 16) | (uint64(buf[i+3+0]) << 24) | (uint64(buf[i+4+0]) << 32) | (uint64(buf[i+5+0]) << 40) | (uint64(buf[i+6+0]) << 48) | (uint64(buf[i+7+0]) << 56) } { l := uint64(0) { bs := uint8(7) t := uint64(buf[i+8] & 0x7F) for buf[i+8]&0x80 == 0x80 { i++ t |= uint64(buf[i+8]&0x7F) << bs bs += 7 } i++ l = t } d.Server = string(buf[i+8 : i+8+l]) i += l } { l := uint64(0) { bs := uint8(7) t := uint64(buf[i+8] & 0x7F) for buf[i+8]&0x80 == 0x80 { i++ t |= uint64(buf[i+8]&0x7F) << bs bs += 7 } i++ l = t } d.From = string(buf[i+8 : i+8+l]) i += l } { l := uint64(0) { bs := uint8(7) t := uint64(buf[i+8] & 0x7F) for buf[i+8]&0x80 == 0x80 { i++ t |= uint64(buf[i+8]&0x7F) << bs bs += 7 } i++ l = t } d.To = string(buf[i+8 : i+8+l]) i += l } { l := uint64(0) { bs := uint8(7) t := uint64(buf[i+8] & 0x7F) for buf[i+8]&0x80 == 0x80 { i++ t |= uint64(buf[i+8]&0x7F) << bs bs += 7 } i++ l = t } d.Content = string(buf[i+8 : i+8+l]) i += l } { d.Time = 0 | (int64(buf[i+0+8]) << 0) | (int64(buf[i+1+8]) << 8) | (int64(buf[i+2+8]) << 16) | (int64(buf[i+3+8]) << 24) | (int64(buf[i+4+8]) << 32) | (int64(buf[i+5+8]) << 40) | (int64(buf[i+6+8]) << 48) | (int64(buf[i+7+8]) << 56) } return i + 16, nil }