Skip to main content

data_rate.go

data_rate.go - Overview

  1. Overview

This file defines constants for various data rate units (bits/second, bytes/second, and their multiples using both SI and IEC prefixes) and provides a converter for data rates.

  1. Detailed Documentation

Constants

The file defines several constants representing data rates in bits/second and bytes/second, using both base-10 (SI) and base-2 (IEC) prefixes.

  • SI Prefixes (base 10):
    • BitPerSecond, KilobitPerSecond, MegabitPerSecond, GigabitPerSecond, TerabitPerSecond, PetabitPerSecond, ExabitPerSecond, ZettabitPerSecond, YottabitPerSecond
    • BytePerSecond, KilobytePerSecond, MegabytePerSecond, GigabytePerSecond, TerabytePerSecond, PetabytePerSecond, ExabytePerSecond, ZettabytePerSecond, YottabytePerSecond
  • IEC Prefixes (base 2):
    • KibibitPerSecond, MebibitPerSecond, GibibitPerSecond, TebibitPerSecond, PebibitPerSecond, ExbibitPerSecond, ZebibitPerSecond, YobibitPerSecond
    • KibibytePerSecond, MebibytePerSecond, GibibytePerSecond, TebibytePerSecond, PebibytePerSecond, ExbibytePerSecond, ZebibytePerSecond, YobibytePerSecond

dataRateConverter Class

Purpose:

dataRateConverter is a struct that implements the Converter interface for converting between different data rate units.

Methods:

  • NewDataRateConverter()

    • Purpose: Creates a new instance of dataRateConverter.
    • Parameters: None
    • Returns: A Converter interface implemented by dataRateConverter.
  • (*dataRateConverter) Name()

    • Purpose: Returns the name of the converter, which is "data_rate".
    • Parameters: None
    • Returns: A string representing the name of the converter ("data_rate").
  • FromDataRateUnit(u Unit) float64

    • Purpose: Returns the float64 value of the data rate unit based on BitPerSecond or BytePerSecond.
    • Parameters:
      • u (Unit): The data rate unit to convert from.
    • Returns: A float64 value representing the multiplier for the given unit relative to BitPerSecond or BytePerSecond. Returns 1 if the unit is not recognized.
  • (*dataRateConverter) Convert(v Value, to Unit) Value

    • Purpose: Converts a Value (which contains a float and a unit) from one data rate unit to another.
    • Parameters:
      • v (Value): The value to convert, containing the numeric value and the original unit.
      • to (Unit): The target unit to convert to.
    • Returns: A Value containing the converted numeric value and the target unit.
  1. Code Examples

Not applicable

  1. Clarity and Accuracy

The documentation accurately reflects the code's functionality.

  1. Markdown & MDX Perfection

The markdown is properly formatted and escaped.

  1. Edge Cases To Avoid Breaking MDX:

No issues found.

  1. Getting Started Relevance

Include in Getting Started: NO