Documentation
¶
Overview ¶
Package tools 工具箱
Package tools 字节转化
Index ¶
- Constants
- Variables
- func BoolToBytes(v bool) []byte
- func BytesToBool(buf []byte) bool
- func BytesToFloat32(bytes []byte) float32
- func BytesToFloat64(bytes []byte) float64
- func BytesToInt32(buf []byte) int32
- func BytesToInt64(buf []byte) int64
- func BytesToMap(bytes []byte) (map[string]any, error)
- func Catch(panicRet any) error
- func FeistelDecrypt(num uint32) uint32
- func FeistelEncrypt(num uint32) uint32
- func Float32ToBytes(float float32) []byte
- func Float64ToBytes(float float64) []byte
- func FromBase34(s string) (uint64, error)
- func FromBase62(str string) int64
- func Int32ToBytes(i int32) []byte
- func Int64ToBytes(i int64) []byte
- func JSONToMsgPack(jsonStr string) ([]byte, error)
- func MapToBytes(jmap map[string]any) ([]byte, error)
- func MsgPackToJSON(msgpackData []byte) (string, error)
- func ToBase34(d uint64) string
- func ToBase62(number int64) string
- type ID
- type Queue
- type SafeMap
Constants ¶
const CODE62 = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
CODE62 62进制码
const CodeLenth = 62
CodeLenth 进制位
Variables ¶
var EDOC = map[string]int64{"0": 0, "1": 1, "2": 2, "3": 3, "4": 4, "5": 5, "6": 6, "7": 7, "8": 8, "9": 9, "a": 10, "b": 11, "c": 12, "d": 13, "e": 14, "f": 15, "g": 16, "h": 17, "i": 18, "j": 19, "k": 20, "l": 21, "m": 22, "n": 23, "o": 24, "p": 25, "q": 26, "r": 27, "s": 28, "t": 29, "u": 30, "v": 31, "w": 32, "x": 33, "y": 34, "z": 35, "A": 36, "B": 37, "C": 38, "D": 39, "E": 40, "F": 41, "G": 42, "H": 43, "I": 44, "J": 45, "K": 46, "L": 47, "M": 48, "N": 49, "O": 50, "P": 51, "Q": 52, "R": 53, "S": 54, "T": 55, "U": 56, "V": 57, "W": 58, "X": 59, "Y": 60, "Z": 61}
EDOC 62进制码
Functions ¶
func FeistelDecrypt ¶ added in v1.1.7
Feistel网络解密 - 还原原始int32
func JSONToMsgPack ¶ added in v1.1.7
JSON → MsgPack
func MsgPackToJSON ¶ added in v1.1.7
MsgPack → JSON
Types ¶
type ID ¶
type ID uint64
An ID is a unique, uniformly distributed 64-bit ID.
func GenerateID ¶
func GenerateID() ID
GenerateID returns a randomly-generated 64-bit ID. This function is thread-safe. IDs are produced by consuming an AES-CTR-128 keystream in 64-bit chunks. The AES key is randomly generated on initialization, as is the counter's initial state. On machines with AES-NI support, ID generation takes ~30ns and generates no garbage.
func (ID) MarshalJSON ¶
MarshalJSON encodes the ID as a hex string.
func (*ID) UnmarshalJSON ¶
UnmarshalJSON decodes the given data as either a hexadecimal string or JSON integer.
type Queue ¶
type Queue[T any] struct { // contains filtered or unexported fields }
Queue represents a single instance of the queue data structure.
func (*Queue[T]) Get ¶
Get returns the element at index i in the queue. If the index is invalid, the call will panic. This method accepts both positive and negative index values. Index 0 refers to the first element, and index -1 refers to the last.
type SafeMap ¶ added in v1.1.7
type SafeMap[K comparable] struct { // contains filtered or unexported fields }
SafeMap is a map with lock
func NewSafeMap ¶ added in v1.1.7
func NewSafeMap[K comparable]() *SafeMap[K]
NewSafeMap return new safemap
func (*SafeMap[K]) Delete ¶ added in v1.1.7
func (m *SafeMap[K]) Delete(k K)
Delete the given key and value.