com.scalacraft.domain.v2.binary.unconstrained
      
    
      
      
    
      
      
    
      
      
    
      
      
    
      
      
    
      
      
    
      
      
    
      
      
    
      
      
    
      non-null octet option representing the high order octet in this pair
      
    
      
      
    
      non-null octet option representing the low order octet in this pair
      
    
      
      
    
      
      
    
      
      
    
      
      
    
      
      
    
      
      
    
      
An unconstrained
OctetPairrepresents two Octets which are themselves unconstrained.In addition to using unconstrained octets each octet is optional. This allows an invalid pair to be created when we have only valid octets to select from.
When interpreted as recording a single integer value using this expression 256 * hi + lo the allowable range has a minimum of -0x8080000000 and maximum equalling 0x807ffffeff.
In decimal the representable range is [-551903297536, 551903297279].
Pattern Matching
Pattern matching is supported as the following examples demonstrate,
Matching will succeed against integer values larger than the range of two constrained octets,
Negative values are matched,
The match target can be a string,
Implicit Conversions
An implicit conversion is supplied which allows an instance of
OctetPairto be used whereOption[String]is required.A conversion to an option of the constrained version of this class is also available.
Value distribution between hi and lo octets
With a
hiandlooctet the range of representable values is bounded below by256 * min-int-value + min-int-valueand above by
256 * max-int-value + max-int-valueWhen matching against values included in this sub-range,
the value of the
looctet will always be in this inclusive range,For values that lie outside of this range the
looctet will take on values from one of these two inclusive ranges,while the
hioctet will be one of these two values,Notionally the
hioctet overflows or underflows before thelooctet.Value Distribution Examples
When
OctetPairis called on to match a value outside of the normal range for two octets it will use the full range of the hi and lo octets. This involves a design choice around which octet exceeds 0xff first. The choice here is to fill the hi octet first and move onto the lo octet only when the hi octct can no longer be incremented."0"matches to(0x0, 0x0). The table below shows how other value are distributed across thehiandlooctets.Equivalent choices are made as the match target decrements towards the minimum value representable by two integers.
non-null octet option representing the high order octet in this pair
non-null octet option representing the low order octet in this pair