common

package
v3.9.0 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2024 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PrintableCharSub = 0x20 // 0x20, i.e. ' ', is the first printable ASCII character
	PrintableCharSup = 0x7E // 0x7E, i.e. '~', is the last printable ASCII character

	// Common64Set contains 64 selected common characters.
	// This value can change in different software releases.
	Common64Set = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_-"
)
View Source
const DefaultMTU = 1400

DefaultMTU is the default MTU of L2 packets in the network.

Variables

This section is empty.

Functions

func AllIPAddr

func AllIPAddr() string

AllIPAddr returns a catch-all IP address to bind. If the machine supports IP dual stack, "::" is returned. Otherwise "0.0.0.0" is returned.

func BidiCopy

func BidiCopy(conn1, conn2 io.ReadWriteCloser) error

BidiCopy does bi-directional data copy.

func FillBytes

func FillBytes(b []byte, value byte)

FillBytes fills the byte slice with the given value.

func GetAllStackTrace added in v3.8.1

func GetAllStackTrace() string

GetAllStackTrace returns the stack trace of all goroutines.

func GetHeapProfile added in v3.8.1

func GetHeapProfile(filePath string) error

GetHeapProfile generates a heap profile file.

func GetMemoryStats added in v3.8.1

func GetMemoryStats() string

GetMemoryStats returns JSON formatted memory statistics.

func GetStackTrace added in v3.8.1

func GetStackTrace() string

GetStackTrace returns the stack trace of this goroutine.

func IsBitsAllOne

func IsBitsAllOne(b []byte) bool

IsBitsAllOne returns true if all bits in the slice are one.

func IsBitsAllZero

func IsBitsAllZero(b []byte) bool

IsBitsAllZero returns true if all bits in the slice are zero.

func IsIPDualStack

func IsIPDualStack() bool

IsIPDualStack returns true if an IPv6 socket is able to send and receive both IPv4 and IPv6 packets.

This function only supports Linux. It always returns false if running other operating systems.

func IsNilNetAddr

func IsNilNetAddr(addr net.Addr) bool

IsNilNetAddr returns true if the net.Addr is nil / empty.

func LocalIPAddr

func LocalIPAddr() string

LocalIPAddr returns the localhost IP address.

func MarshalJSON

func MarshalJSON(m protoreflect.ProtoMessage) ([]byte, error)

Marshal returns a JSON representation of protobuf.

func MaxConsecutivePrintableLength

func MaxConsecutivePrintableLength(b []byte) int

MaxConsecutivePrintableLength returns the length of the maximum consecutive bytes that are printable.

func MaybeDecorateIPv6

func MaybeDecorateIPv6(addr string) string

MaybeDecorateIPv6 adds [ and ] before and after an IPv6 address. If the input string is a IPv4 address or not a valid IP address (e.g. is a domain name), the same string is returned.

func NilNetAddr

func NilNetAddr() net.Addr

NilNetAddr returns an empty network address.

func ReadAllAndDiscard

func ReadAllAndDiscard(r io.Reader)

ReadAllAndDiscard reads from r until an error or EOF. All the data are discarded.

func RoundTrip

func RoundTrip(ctx context.Context, rw io.ReadWriter, req []byte, maxRespSize int) (resp []byte, err error)

RoundTrip sends a request to the connection and returns the response.

func SetReadTimeout

func SetReadTimeout(conn SetReadDeadlineInterface, timeout time.Duration)

SetReadTimeout set read deadline. It cancels the deadline if the timeout is 0 or negative.

func StartCPUProfile added in v3.8.1

func StartCPUProfile(filePath string) error

StartCPUProfile starts CPU profile and writes result to the file.

func StopCPUProfile added in v3.8.1

func StopCPUProfile()

StopCPUProfile stops CPU profile.

func TCPCongestionControlAlgorithm

func TCPCongestionControlAlgorithm() string

TCPCongestionControlAlgorithm returns the TCP congestion control algorithm used by the operating system.

func ToCommon64Set

func ToCommon64Set(b []byte, beginIdx, endIdx int)

ToCommon64Set rewrites [beginIdx, endIdx) of the byte slice with characters from Common64Set.

func ToPrintableChar

func ToPrintableChar(b []byte, beginIdx, endIdx int)

ToPrintableChar rewrites [beginIdx, endIdx) of the byte slice with printable ASCII characters.

func UnmarshalJSON

func UnmarshalJSON(b []byte, m protoreflect.ProtoMessage) error

Unmarshal writes protobuf based on JSON data.

func UnusedTCPPort

func UnusedTCPPort() (int, error)

UnusedTCPPort returns an unused TCP port in the local network.

func UnusedUDPPort

func UnusedUDPPort() (int, error)

UnusedUDPPort returns an unused UDP port in the local network.

Types

type BitDistribution

type BitDistribution struct {
	Bit0      float64
	Bit1      float64
	Bit0Count int
	Bit1Count int
}

BitDistribution describes the probability of bit 0 and bit 1 in a byte array.

func ToBitDistribution

func ToBitDistribution(arr []byte) BitDistribution

ToBitDistribution returns the BitDistribution from a byte array.

func (BitDistribution) String

func (bd BitDistribution) String() string

type HierarchyConn

type HierarchyConn interface {
	net.Conn

	// AddSubConnection attach a child connection to this connection.
	// The child connection is closed when this connection close.
	AddSubConnection(conn net.Conn)
}

HierarchyConn closes sub-connections when this connection is closed.

func WrapHierarchyConn

func WrapHierarchyConn(conn net.Conn) HierarchyConn

WrapHierarchyConn wraps an existing connection with HierarchyConn.

type SetReadDeadlineInterface

type SetReadDeadlineInterface interface {
	SetReadDeadline(t time.Time) error
}

type TransportProtocol

type TransportProtocol uint8
const (
	UnknownTransport TransportProtocol = iota
	StreamTransport
	PacketTransport
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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