com.scalacraft.domain.v2.binary

OctetPair

Related Docs: object OctetPair | package binary

case class OctetPair extends Product with Serializable

An OctetPair represents two Octets.

The following constraints hold for instances of this class,

- hi is not null - lo is not null

An instance can be created using a suitable overload of the opt method.

val op1: Option[OctetPair] = OctetPair.opt(34540)  // OctetPair(134, 236) = 34540
val op2: Option[OctetPair] = OctetPair.opt(0x86ec) // OctetPair(134, 236) = 34540
val op3: Option[OctetPair] = OctetPair.opt("d") // OctetPair(0, 13)
val op3: Option[OctetPair] = OctetPair.opt("fe") // OctetPair(0, 254)
val op5: Option[OctetPair] = OctetPair.opt("012") // Decimal 18
val op4: Option[OctetPair] = OctetPair.opt("f11d") // Decimal 61725

Note that the string variant takes between one to four hex characters.

When any class constraint is violated the result is None.

val op1: Option[OctetPair] = OctetPair.opt("NaN") // None
val op2: Option[OctetPair] = OctetPair.opt(0xf1234) // None
Pattern Matching

Pattern matching is supported as the following examples demonstrate,

0x3490 match {
  case OctetPair(hi, lo) => (hi, lo) // (Octet(0x34), Octet(0x90)
  case _ => None
}

The match target can be a string,

val s: String = "4020"

s match {
  case OctetPair(hi, lo) => (hi, lo) // (Octet(0x40), Octet(0x20)
  case _ => None
}

Invalid octet pairs are not matched,

-129 match {
  case OctetPair(hi, lo) => (hi, lo)
  case _ => None // None
}
Implicit Conversions

Implicit conversions are supplied which allow an instance of OctetPair to be used when an Int or String is required.

val Some(pair) = OctetPair.opt(0x40cc)
val w: Int = 1 + pair // 0x40cd
val Some(pair) = OctetPair.opt("f")
val s: String = pair: String // 000f

A conversion to the unconstrained version of this class is also available.

Linear Supertypes
Serializable, Serializable, Product, Equals, AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. OctetPair
  2. Serializable
  3. Serializable
  4. Product
  5. Equals
  6. AnyRef
  7. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Value Members

  1. final def !=(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  5. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  6. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  7. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  8. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  9. val hi: Octet

    A valid octet representing the high byte

  10. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  11. val lo: Octet

    A valid octet representing the low byte

  12. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  13. final def notify(): Unit

    Definition Classes
    AnyRef
  14. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  15. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  16. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  17. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  18. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from Serializable

Inherited from Serializable

Inherited from Product

Inherited from Equals

Inherited from AnyRef

Inherited from Any

Ungrouped