utils

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bytes2String

func Bytes2String(b []byte) string

Bytes2String converts a byte slice to string without memory allocation (zero-copy).

WARNING: The input []byte must not be modified after conversion, as strings in Go are immutable. This method uses unsafe tricks and relies on Go's current runtime implementation. It is not guaranteed to be safe across all Go versions. For safety, prefer string(b) if you need a copy.

func Int2Bytes

func Int2Bytes(i int) []byte

Int2Bytes returns i encoded as a 4-byte big-endian slice.

func String2Bytes

func String2Bytes(s string) []byte

String2Bytes converts string to byte slice without memory allocation (zero-copy).

WARNING: The returned []byte must be treated as read-only. Modifying the returned slice may break Go's string immutability guarantee and cause undefined behavior. This method uses unsafe tricks and relies on Go's current runtime implementation. It is not guaranteed to be safe across all Go versions. Use only when you are sure the []byte will not be modified. For safety, prefer []byte(s) if you need a writable copy.

Types

This section is empty.

Source Files

  • converter.go

Jump to

Keyboard shortcuts

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