bin

package
v0.0.0-...-32c7374 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package bin256 provides a binary 256-bit value.

Index

Constants

View Source
const Len128 = 16
View Source
const Len128Char = (Len128 * 2) + 1 // 341a7d60bc5893a6-4bda3de06721534c
View Source
const Len256 = 32
View Source
const Len256Char = (Len256 * 2) + 3
View Source
const Len64 = 8
View Source
const Len64Char = (Len64 * 2) // 341a7d60bc5893a6

Variables

View Source
var Max128 = Bin128{Max64, Max64}
View Source
var Max64 = Bin64{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}
View Source
var Regexp128 = regexp.MustCompile(`^[0-9A-Za-z]{16}-[0-9A-Za-z]{16}$`)
View Source
var Regexp256 = regexp.MustCompile(`^[0-9A-Za-z]{16}-[0-9A-Za-z]{16}-[0-9A-Za-z]{16}-[0-9A-Za-z]{16}$`)
View Source
var Regexp64 = regexp.MustCompile(`^[0-9A-Za-z]{16}$`)

Functions

func Compare128

func Compare128(a, b Bin128) int

Compare128 compares two bin128 values.

Returns:

-1 if a < b
 0 if a == b
 1 if a > b

func Compare256

func Compare256(a, b Bin256) int

Compare256 compares two bin256 values.

Returns:

-1 if a < b
 0 if a == b
 1 if a > b

func Compare64

func Compare64(a, b Bin64) int

Compare64 compares two bin64 values.

Returns:

-1 if a < b
 0 if a == b
 1 if a > b

func Sort128

func Sort128(vv []Bin128)

Sort128 sorts bin128 values.

func Sort256

func Sort256(vv []Bin256)

Sort256 sorts bin256 values.

func Sort64

func Sort64(vv []Bin64)

Sort64 sorts bin64 values.

Types

type Bin128

type Bin128 [2]Bin64

Bin128 is a 128-bit value.

func Int128

func Int128(v0, v1 int64) Bin128

Int128 returns a bin128 from two int64 encoded as big-endian.

func MustParseString128

func MustParseString128(s string) Bin128

MustParseString128 parses a bin128 from 33-char string or panics.

func New128

func New128(b [Len128]byte) Bin128

New128 returns a bin128 from a byte array.

func Parse128

func Parse128(b []byte) (Bin128, error)

Parse128 parses a bin128 value from a 16-byte array.

func ParseString128

func ParseString128(s string) (Bin128, error)

ParseString128 parses a bin128 from 33-char string.

func Random128

func Random128() Bin128

Random128 returns a random bin128.

func TimeRandom128

func TimeRandom128() Bin128

TimeRandom128 returns a time-random bin128 with a millisecond resolution.

func (Bin128) AppendHexTo

func (b Bin128) AppendHexTo(buf []byte) []byte

AppendHexTo appends a 33-char lower-case hex-encoded string to a buffer.

func (Bin128) Compare

func (b Bin128) Compare(b1 Bin128) int

Compare compares two values.

Returns:

-1 if a < b
 0 if a == b
 1 if a > b

func (Bin128) Equal

func (b Bin128) Equal(b1 Bin128) bool

Equal returns whether two values are equal.

func (Bin128) Hash32

func (b Bin128) Hash32() uint32

Hash32 returns a 32-bit hash. The method decodes the value as two big-endian uint64s and then xors their halves.

func (Bin128) Hash64

func (b Bin128) Hash64() uint64

Hash64 returns a 64-bit hash. The method decodes the value as two big-endian uint64s and then xors them.

func (Bin128) Int64

func (b Bin128) Int64() (int64, int64)

Int64 returns two int64 decoded as big-endian.

func (Bin128) IsZero

func (b Bin128) IsZero() bool

IsZero returns whether the value is zero.

func (Bin128) Less

func (b Bin128) Less(b1 Bin128) bool

Less returns whether the current value is less than another.

func (Bin128) Marshal

func (b Bin128) Marshal() []byte

Marshal marshals the value to a 16-byte array.

func (Bin128) MarshalJSON

func (b Bin128) MarshalJSON() ([]byte, error)

MarshalJSON marshals the value to a JSON string.

func (Bin128) MarshalTo

func (b Bin128) MarshalTo(buf []byte)

MarshalTo marshals the value to a 16-byte array.

func (Bin128) MarshalToBuffer

func (b Bin128) MarshalToBuffer(buf buffer.Buffer) []byte

MarshalToBuffer marshals the value to a buffer.

func (Bin128) Size

func (b Bin128) Size() int

Size returns 16 bytes.

func (Bin128) String

func (b Bin128) String() string

String returns a 33-char lower-case hex-encoded string.

func (Bin128) Uint64

func (b Bin128) Uint64() (uint64, uint64)

Uint64 returns two uint64 decoded as big-endian.

func (*Bin128) Unmarshal

func (b *Bin128) Unmarshal(buf []byte) error

Unmarshal parses a 16-byte array.

func (*Bin128) UnmarshalJSON

func (b *Bin128) UnmarshalJSON(buf []byte) error

MarshalJSON parses the value from a JSON string.

type Bin256

type Bin256 [4]Bin64

Bin256 is a 32 byte value.

func Int256

func Int256(v0, v1, v2, v3 int64) Bin256

Int256 returns a bin256 from four int64s encoded as big-endian.

func MustParseString256

func MustParseString256(s string) Bin256

MustParseString256 parses a bin256 from 67-char string or panics.

func New256

func New256(p [Len256]byte) Bin256

New256 returns a bin256 from a byte array.

func Parse256

func Parse256(b []byte) (Bin256, error)

Parse256 parses a bin256 from a 32-byte array.

func ParseString256

func ParseString256(s string) (Bin256, error)

ParseString256 parses a bin256 from 67-char string.

func Random256

func Random256() Bin256

Random256 returns a random bin256.

func TimeRandom256

func TimeRandom256() Bin256

TimeRandom256 returns a time-random bin256 with a millisecond resolution.

func (Bin256) AppendHexTo

func (b Bin256) AppendHexTo(buf []byte) []byte

AppendHexTo appends a 67-char lower-case hex-encoded string to a buffer.

func (Bin256) Bin128

func (b Bin256) Bin128() [2]Bin128

Bin128 returns two 128-bit values.

func (Bin256) Compare

func (b Bin256) Compare(b1 Bin256) int

Compare compares two values.

Returns:

-1 if a < b
 0 if a == b
 1 if a > b

func (Bin256) Equal

func (b Bin256) Equal(b1 Bin256) bool

Equal returns whether two values are equal.

func (Bin256) Hash32

func (b Bin256) Hash32() uint32

Hash32 returns a 32-bit hash. The method decodes the value as four big-endian uint64s and then xors their halves.

func (Bin256) Hash64

func (b Bin256) Hash64() uint64

Hash64 returns a 64-bit hash. The method decodes the value as four big-endian uint64s and then xors them.

func (Bin256) Int64

func (b Bin256) Int64() [4]int64

Int64 returns four int64 decoded as big-endian.

func (Bin256) IsZero

func (b Bin256) IsZero() bool

IsZero returns whether the value is zero.

func (Bin256) Less

func (b Bin256) Less(b1 Bin256) bool

Less returns whether the current value is less than another.

func (Bin256) Marshal

func (b Bin256) Marshal() []byte

Marshal marshals the value to a 32-byte array.

func (Bin256) MarshalJSON

func (b Bin256) MarshalJSON() ([]byte, error)

MarshalJSON marshals the value to a JSON string.

func (Bin256) MarshalTo

func (b Bin256) MarshalTo(buf []byte)

MarshalTo marshals the value to a 32-byte array.

func (Bin256) MarshalToBuffer

func (b Bin256) MarshalToBuffer(buf buffer.Buffer) []byte

MarshalToBuffer marshals the value to a buffer.

func (Bin256) Size

func (b Bin256) Size() int

Size returns 32 bytes.

func (Bin256) String

func (b Bin256) String() string

String returns a 64-char lower-case hex-encoded string.

func (Bin256) Uint64

func (b Bin256) Uint64() [4]uint64

Uint64 returns four uint64 decoded as big-endian.

func (*Bin256) Unmarshal

func (b *Bin256) Unmarshal(buf []byte) error

Unmarshal parses a 32-byte array.

func (*Bin256) UnmarshalJSON

func (b *Bin256) UnmarshalJSON(buf []byte) error

MarshalJSON parses the value from a JSON string.

type Bin64

type Bin64 [8]byte

Bin64 is a binary 64-bit value.

func Int64

func Int64(v int64) Bin64

Int64 returns a bin64 from an int64, encoded as big-endian.

func MustParseString64

func MustParseString64(s string) Bin64

MustParseString64 parses a bin64 from 16-char string or panics.

func New64

func New64(b [Len64]byte) Bin64

New64 returns a bin64 from a byte array.

func Parse64

func Parse64(p []byte) (Bin64, error)

Parse64 parses a bin64 value from a 16-byte array.

func ParseString64

func ParseString64(s string) (Bin64, error)

ParseString64 parses a bin64 from 32-char string.

func Random64

func Random64() Bin64

Random64 returns a random bin64.

func TimeRandom64

func TimeRandom64() Bin64

TimeRandom64 returns a time-random bin64 with a second resolution.

func (Bin64) AppendHexTo

func (b Bin64) AppendHexTo(buf []byte) []byte

AppendHexTo appends a 16-char lower-case hex-encoded string to a buffer.

func (Bin64) Compare

func (b Bin64) Compare(b1 Bin64) int

Compare compares two values.

Returns:

-1 if a < b
 0 if a == b
 1 if a > b

func (Bin64) Equal

func (b Bin64) Equal(b1 Bin64) bool

Equal returns whether two values are equal.

func (Bin64) Hash32

func (b Bin64) Hash32() uint32

Hash32 returns a 32-bit hash of the value. The method decodes the value as a big-endian uint64 and then xors the two halves.

func (Bin64) Hash64

func (b Bin64) Hash64() uint64

Hash64 returns a 64-bit hash of the value. The method decodes the value as a big-endian uint64.

func (Bin64) Int64

func (b Bin64) Int64() int64

Int64 returns an int64 decoded as big-endian.

func (Bin64) IsZero

func (b Bin64) IsZero() bool

IsZero returns whether the value is zero.

func (Bin64) Less

func (b Bin64) Less(b1 Bin64) bool

Less returns whether the current value is less than another.

func (Bin64) Marshal

func (b Bin64) Marshal() []byte

Marshal marshals the value to a 16-byte array.

func (Bin64) MarshalJSON

func (b Bin64) MarshalJSON() ([]byte, error)

MarshalJSON marshals the value to a JSON string.

func (Bin64) MarshalTo

func (b Bin64) MarshalTo(buf []byte)

MarshalTo marshals the value to a 16-byte array.

func (Bin64) MarshalToBuffer

func (b Bin64) MarshalToBuffer(buf buffer.Buffer) []byte

MarshalToBuffer marshals the value to a buffer.

func (Bin64) Size

func (b Bin64) Size() int

Size returns 8 bytes.

func (Bin64) String

func (b Bin64) String() string

String returns a 16-char lower-case hex-encoded string.

func (Bin64) Uint64

func (b Bin64) Uint64() uint64

Uint64 returns a uint64 decoded as big-endian.

func (*Bin64) Unmarshal

func (b *Bin64) Unmarshal(buf []byte) error

Unmarshal parses a 16-byte array.

func (*Bin64) UnmarshalJSON

func (b *Bin64) UnmarshalJSON(buf []byte) error

MarshalJSON parses the value from a JSON string.

type Hash128

type Hash128 interface {
	io.Writer

	// SumBin128 returns the current hash as bin128.
	SumBin128() Bin128

	// Reset resets the hash to its initial state.
	Reset()
}

Hash128 is a common interface for hash functions which return hashes as bin128.

type Hash256

type Hash256 interface {
	io.Writer

	// SumBin256 returns the current hash as bin256.
	SumBin256() Bin256

	// Reset resets the hash to its initial state.
	Reset()
}

Hash256 is a common interface for hash functions which return hashes as bin256.

Jump to

Keyboard shortcuts

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