Exemple #1
0
// Encode encodes uuid.UUID into a string using the least significant bits
// (LSB) first according to the alphabet. if the most significant bits (MSB)
// are 0, the string might be shorter.
func (su *ShortUUID) Encode(u uuid.UUID) string {
	var num big.Int
	num.SetString(strings.Replace(u.String(), "-", "", 4), 16)

	// Calculate encoded length.
	factor := math.Log(float64(25)) / math.Log(float64(su.alphabet.Length()))
	length := math.Ceil(factor * float64(len(u.Bytes())))

	return su.numToString(&num, int(length))
}
Exemple #2
0
func NewCursorFromSource(eventID uuid.UUID, createdAt time.Time) CursorEvents {
	res := make([]byte, lengthCursor)
	copy(res, eventID.Bytes())
	b2, err := createdAt.MarshalBinary()
	if err != nil {
		println("[WARNING] marshal time", err.Error())
	}
	copy(res[16:], b2)

	return CursorEvents(Base64(res))
}