utils

package
v1.2.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 24, 2021 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Copyright 2014 loolgame Author. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const Nano2Millisecond int64 = 1000000

Variables

This section is empty.

Functions

func BoolToBytes

func BoolToBytes(v bool) []byte

func BytesToBool

func BytesToBool(buf []byte) bool

func BytesToFloat32

func BytesToFloat32(bytes []byte) float32

func BytesToFloat64

func BytesToFloat64(bytes []byte) float64

func BytesToInt

func BytesToInt(buf []byte) int

func BytesToInt32

func BytesToInt32(buf []byte) int32

func BytesToInt64

func BytesToInt64(buf []byte) int64

func BytesToMap

func BytesToMap(bytes []byte) (map[string]interface{}, error)

func BytesToMapString

func BytesToMapString(bytes []byte) (map[string]string, error)

func Float32ToBytes

func Float32ToBytes(float float32) []byte

func Float64ToBytes

func Float64ToBytes(float float64) []byte

func Int32ToBytes

func Int32ToBytes(i int32) []byte

func Int64ToBytes

func Int64ToBytes(i int64) []byte

func IntToBytes

func IntToBytes(i int) []byte

func InterfaceToBytes

func InterfaceToBytes(jmap interface{}) ([]byte, error)

func MapToBytes

func MapToBytes(jmap map[string]interface{}) ([]byte, error)

func MapToBytesString

func MapToBytesString(jmap map[string]string) ([]byte, error)

func RecoverFunc

func RecoverFunc()

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 ParseID

func ParseID(s string) (ID, error)

ParseID parses the given string as a hexadecimal string.

func (ID) MarshalJSON

func (id ID) MarshalJSON() ([]byte, error)

MarshalJSON encodes the ID as a hex string.

func (ID) String

func (id ID) String() string

String returns the ID as a hex string.

func (*ID) UnmarshalJSON

func (id *ID) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes the given data as either a hexadecimal string or JSON integer.

Directories

Path Synopsis
enum

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL