bitrate

package
v0.3.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package bitrate is the bandwidth type the dispatcher admits and the executor enforces, so both compute with the same units and bounds.

Index

Constants

View Source
const (
	Bit      Bitrate = 1
	Kilobit          = 1000 * Bit
	Megabit          = 1000 * Kilobit
	Gigabit          = 1000 * Megabit
	Terabit          = 1000 * Gigabit
	Petabit          = 1000 * Terabit
	Byte             = 8 * Bit
	Kilobyte         = 1000 * Byte
	Megabyte         = 1000 * Kilobyte
	Gigabyte         = 1000 * Megabyte
	Terabyte         = 1000 * Gigabyte
	Petabyte         = 1000 * Terabyte
)
View Source
const Max = Petabit

Max is the largest bandwidth the dispatcher admits and the executor accepts on any boundary. It is far above any capacity a real executor announces and low enough that the aggregate of every run a schedule can hold stays an exact int64. api/openapi.yaml documents the same bound for floor_bw and ceil_bw.

View Source
const MaxByteCount = math.MaxInt64 / bitsPerByte

MaxByteCount is the largest byte count that has an exact bit count.

Variables

This section is empty.

Functions

func InPolicyRange

func InPolicyRange(bps int64) bool

InPolicyRange reports whether bps, a bandwidth in bits per second as the control protocol and the HTTP contract carry it, lies in [0, Max]. The dispatcher's admission and the executor's own checks both apply it, so neither role can accept a bandwidth the other rejects.

Types

type Bitrate

type Bitrate int64

Bitrate in bits/s.

func Add

func Add(a, b Bitrate) (Bitrate, bool)

Add adds two bandwidths and reports whether the sum is exact. Every aggregate admission decision uses it, so a sum that would wrap rejects the request instead of admitting it against a negative total.

func FromBytes

func FromBytes(b int) Bitrate

FromBytes converts a byte count into bits. A count beyond MaxByteCount in either direction has no exact bit count and saturates, rather than wrapping into a bitrate of the opposite sign.

func Parse

func Parse(s string) (Bitrate, error)

func (Bitrate) Bytes

func (b Bitrate) Bytes() int

Bytes is the buffer size that holds b bits, rounded up to a whole byte. It is a size, so it is defined for a non-negative bitrate: a negative one is a debt, has no buffer size and reports zero. Use Bitrate.SignedBytes to convert a signed token balance.

func (Bitrate) SignedBytes

func (b Bitrate) SignedBytes() int

SignedBytes converts a signed bit count into whole bytes, rounding towards negative infinity. Applied to a token balance it reports only bytes that are fully covered and never erases part of a debt: -8 bits is one byte owed and -1 bit is still one byte owed, where rounding towards zero reports none of either and grants the next reservation early. It is exact for every int64.

func (Bitrate) String

func (b Bitrate) String() string

Jump to

Keyboard shortcuts

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