hack

package
v0.18.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2023 License: Apache-2.0 Imports: 1 Imported by: 12

Documentation

Overview

Package hack gives you some efficient functionality at the cost of breaking some Go rules.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DisableProtoBufRandomness added in v0.11.0

func DisableProtoBufRandomness()

DisableProtoBufRandomness disables the random insertion of whitespace characters when serializing Protocol Buffers in textual form (both when serializing to JSON or to ProtoText)

Since the introduction of the APIv2 for Protocol Buffers, the default serializers in the package insert random whitespace characters that don't change the meaning of the serialized code but make byte-wise comparison impossible. The rationale behind this decision is as follows:

"The ProtoBuf authors believe that golden tests are Wrong"

Fine. Unfortunately, Vitess makes extensive use of golden tests through its test suite, which expect byte-wise comparison to be stable between test runs. Using the new version of the package would require us to rewrite hundreds of tests, or alternatively, we could disable the randomness and call it a day. The method required to disable the randomness is not public, but that won't stop us because we're good at computers.

Tracking issue: https://github.com/golang/protobuf/issues/1121

func ParseFloatPrefix added in v0.13.0

func ParseFloatPrefix(s string, bitSize int) (float64, int, error)

func RuntimeAllocSize added in v0.12.0

func RuntimeAllocSize(size int64) int64

RuntimeAllocSize returns size of the memory block that mallocgc will allocate if you ask for the size.

func RuntimeMemhash added in v0.10.0

func RuntimeMemhash(b []byte, seed uint64) uint64

RuntimeMemhash provides access to the Go runtime's default hash function for arbitrary bytes. This is an optimal hash function which takes an input seed and is potentially implemented in hardware for most architectures. This is the same hash function that the language's `map` uses.

func RuntimeStrhash added in v0.10.0

func RuntimeStrhash(str string, seed uint64) uint64

RuntimeStrhash provides access to the Go runtime's default hash function for strings. This is an optimal hash function which takes an input seed and is potentially implemented in hardware for most architectures. This is the same hash function that the language's `map` uses.

func String

func String(b []byte) (s string)

String force casts a []byte to a string. USE AT YOUR OWN RISK

func StringBytes added in v0.12.0

func StringBytes(s string) []byte

StringBytes returns the underlying bytes for a string. Modifying this byte slice will lead to undefined behavior.

Types

This section is empty.

Jump to

Keyboard shortcuts

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