units

package
v0.6.0 Latest Latest
Warning

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

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

Documentation

Overview

Package units parses the scenario value grammar — rates, sizes, durations, and "lo..hi" ranges of each (docs/scenario-schema.md). Rates and sizes reuse github.com/BGrewell/go-conversions, which distinguishes SI decimal prefixes (K/M/G) from IEC binary prefixes (Ki/Mi/Gi); durations and ranges are parsed here.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseDuration

func ParseDuration(s string) (time.Duration, error)

ParseDuration parses a Go duration string (e.g. "100ms", "1m30s").

func ParseRate

func ParseRate(s string) (int64, error)

ParseRate parses a bit-rate (e.g. "100Mbps", "1.5G", "1000") to bits/sec. SI decimal prefixes (K=1e3, M=1e6, G=1e9, e.g. "100Mbps") are distinct from IEC binary prefixes (Ki=2^10, Mi=2^20, Gi=2^30, e.g. "100Mibps"). A value that overflows int64 is rejected as out-of-range rather than returned as a poisoned (negative) rate.

func ParseSize

func ParseSize(s string) (uint64, error)

ParseSize parses a byte size (e.g. "1000", "100K", "1.5MB") to bytes. SI decimal prefixes (K=1e3, M=1e6, G=1e9, e.g. "100MB") are distinct from IEC binary prefixes (Ki=2^10, Mi=2^20, Gi=2^30, e.g. "100MiB"); a trailing "B" is allowed. The underlying parser overflow-guards and returns a non-negative int64, which fits in the uint64 result.

Types

type DurationRange

type DurationRange struct{ Lo, Hi time.Duration }

DurationRange is an inclusive duration range.

func ParseDurationRange

func ParseDurationRange(s string) (DurationRange, error)

ParseDurationRange parses "lo..hi" or a scalar duration.

type RateRange

type RateRange struct{ Lo, Hi int64 }

RateRange, SizeRange, DurationRange are inclusive [Lo, Hi] bounds. A scalar parses to Lo == Hi.

func ParseRateRange

func ParseRateRange(s string) (RateRange, error)

ParseRateRange parses "lo..hi" or a scalar rate.

type SizeRange

type SizeRange struct{ Lo, Hi uint64 }

SizeRange is an inclusive byte range.

func ParseSizeRange

func ParseSizeRange(s string) (SizeRange, error)

ParseSizeRange parses "lo..hi" or a scalar size.

Jump to

Keyboard shortcuts

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