Symbiotic Data

Primitives

Unit

data Unit = Unit

JSON

Treats Unit as an empty string ""

encodeJson :: Unit -> Json
encodeJson Unit = stringAsJson ""

Binary

Stores it as the byte 0

encodeBinary :: Unit -> ByteString
encodeBinary Unit = byteAsByteString 0

Symbiote Test Suite Instance

Instances

This data type implements a number of instances from the Algebraic Properties specification:

instance Semigroup Unit where
  append Unit Unit = Unit
instance Monoid Unit where
  mempty = Unit
instance Eq Unit where
  eq Unit Unit = True
instance Ord Unit where
  compare Unit Unit = EQ
instance Enum Unit where
  pred Unit = Unit
  succ Unit = Unit
instance Bounded Unit where
  top = Unit
  bottom = Unit
instance BoundedEnum Unit where
  toEnum 0 = Just Unit
  toEnum _ = Nothing
  fromEnum Unit = 0
instance HeytingAlgebra Unit where
  ff = Unit
  tt = Unit
  implies Unit Unit = Unit
  disj Unit Unit = Unit
  conj Unit Unit = Unit
  not Unit = Unit
instance BooleanAlgebra Unit
instance Semiring Unit where
  zero = Unit
  one = Unit
  add Unit Unit = Unit
  mul Unit Unit = Unit
instance Ring Unit where
  sub Unit Unit = Unit
instance CommutativeRing Unit
Operations
data UnitOperation
  = UnitMonoid (MonoidOperation Unit)
  | UnitBoundedEnum (BoundedEnumOperation Unit)
  | UnitBooleanAlgebra (BooleanAlgebraOperation Unit)
  | UnitCommutativeRing  (CommutativeRingOperation Unit)

performUnit :: UnitOperation -> Unit -> Bool
performUnit op x = case op of
  UnitMonoid op' ->
    performMonoid op' x
  UnitBoundedEnum op' ->
    performBoundedEnum op' x
  UnitBooleanAlgebra op' ->
    performBooleanAlgebra op' x
  UnitCommutativeRing op' ->
    performCommutativeRing op' x

encodeJson :: UnitOperation -> Json
encodeJson op = case op of
  UnitMonoid op' ->
    {"monoid": encodeJson op'}
  UnitBoundedEnum op' ->
    {"boundedEnum": encodeJson op'}
  UnitBooleanAlgebra op' ->
    {"booleanAlgebra": encodeJson op'}
  UnitCommutativeRing op' ->
    {"commutativeRing": encodeJson op'}

encodeBinary :: UnitOperation -> ByteString
encodeBinary op = case op of
  UnitMonoid op' ->
    (byteToByteString 0) ++ encodeBinary op'
  UnitBoundedEnum op' ->
    (byteToByteString 1) ++ encodeBinary op'
  UnitBooleanAlgebra op' ->
    (byteToByteString 2) ++ encodeBinary op'
  UnitCommutativeRing op' ->
    (byteToByteString 3) ++ encodeBinary op'
Topic

String literal Topic used in the Symbiote Test Suite for this data type. Composed solely as Unit.

"Unit"

Boolean

data Boolean = True | False

Note

Although throughout this text, in Haskell, we functionally use the Bool type to denote true/false values; that’s only due to that language’s design. For all intents and purposes, a Symbiotic-Data Boolean value is functionally the same as a operational true/false value, we opt to decide its name as Boolean, as opposed to Bool, specifically to distinguish it from a programming language’s notions.

An implementation need not write a new data type for this Symbiotic-Data specification, however; it just needs to associate its Topic value as Boolean.

JSON

Uses standard JSON Boolean

encodeJson :: Boolean -> Json
encodeJson x = case x of
  True -> true
  False -> false

Binary

Uses standard bytes 0 as false, 1 as true

encodeBinary :: Boolean -> ByteString
encodeBinary x = case x of
  True -> byteAsByteString 1
  False -> byteAsByteString 0

Symbiote Test Suite Instance

Instances

This data type implements a number of instances from the Algebraic Properties specification:

instance Eq Boolean where
  eq True  True  = True
  eq False False = True
  eq _     _     = False
instance Ord Boolean where
  compare False True  = LT
  compare True  False = GT
  compare _     _     = EQ
instance Enum Unit where
  pred False = False
  pred True  = False
  succ False = True
  succ True  = True
instance Bounded Unit where
  top = True
  bottom = False
instance BoundedEnum Unit where
  toEnum 0 = Just False
  toEnum 1 = Just True
  toEnum _ = Nothing
  fromEnum False = 0
  fromEnum True  = 1
instance HeytingAlgebra Unit where
  ff = False
  tt = True
  implies p q = if p then q else True
  disj False False = False
  disj _     _     = True
  conj True True = True
  conj _    _    = False
  not False = True
  not True  = False
instance BooleanAlgebra Unit
Operations
data BooleanOperation
  = BooleanBoundedEnum (BoundedEnumOperation Boolean)
  | BooleanBooleanAlgebra (BooleanAlgebraOperation Boolean)

performBoolean :: BooleanOperation -> Boolean -> Bool
performBoolean op x = case op of
  BooleanBoundedEnum op' ->
    performBoundedEnum op' x
  BooleanBooleanAlgebra op' ->
    performBooleanAlgebra op' x

encodeJson :: BooleanOperation -> Json
encodeJson op = case op of
  BooleanBoundedEnum op' ->
    {"boundedEnum": encodeJson op'}
  BooleanBooleanAlgebra op' ->
    {"booleanAlgebra": encodeJson op'}

encodeBinary :: BooleanOperation -> ByteString
encodeBinary op = case op of
  BooleanBoundedEnum op' ->
    (byteToByteString 1) ++ encodeBinary op'
  BooleanBooleanAlgebra op' ->
    (byteToByteString 2) ++ encodeBinary op'
Topic

String literal Topic used in the Symbiote Test Suite for this data type. Composed solely as Boolean.

"Boolean"

Integral

Signed

Int8

Range varies from -2^7 to 2^7-1

data Int8 = -2^7 | -2^7+1 | ... | 2^7-2 | 2^7-1
JSON

Uses standard JSON Integers

encodeJson :: Int8 -> Json
encodeJson x = intAsJson x
Binary

Int8 s are converted to Uint8`s before storing as a byte - where the negative range is stored as the upper values in the ``Uint8`.

encodeBinary :: Int8 -> ByteString
encodeBinary x =
  if x >= 0
  then byteAsByteString (intAsUint x)
  else byteAsByteString ((intAsUint (2^7 + x)) + 2^7)
Symbiote Test Suite Instance
  • Topic

String literal Topic used in the Symbiote Test Suite for this data type. Composed solely as Int8.

"Int8"

Int16

Range varies from -2^15 to 2^15-1

data Int16 = -2^15 | -2^15+1 | ... | 2^15-2 | 2^15-1
JSON

Uses standard JSON Integers

encodeJson :: Int16 -> Json
encodeJson x = intAsJson x
Binary

There are two byte encodings for any integer larger than 8 bits - big-endian or little-endian.

encodeBinary :: Int16 -> ByteString
encodeBinary x = intAsByteStringBE x
encodeBinary :: Int16 -> ByteString
encodeBinary x = intAsByteStringLE x
Symbiote Test Suite Instance
  • Topic

String literal Topic used in the Symbiote Test Suite for this data type. Composed solely as Int16.

"Int16"

Int32

Range varies from -2^31 to 2^31-1

data Int32 = -2^31 | -2^31+1 | ... | 2^31-2 | 2^31-1
JSON

Uses standard JSON Integers

encodeJson :: Int32 -> Json
encodeJson x = intAsJson x
Binary

There are two byte encodings for any integer larger than 8 bits - big-endian or little-endian.

encodeBinary :: Int32 -> ByteString
encodeBinary x = intAsByteStringBE x
encodeBinary :: Int32 -> ByteString
encodeBinary x = intAsByteStringLE x
Symbiote Test Suite Instance
  • Topic

String literal Topic used in the Symbiote Test Suite for this data type. Composed solely as Int32.

"Int32"

Int64

Range varies from -2^63 to 2^63-1

data Int64 = -2^63 | -2^63+1 | ... | 2^63-2 | 2^63-1
JSON

Uses standard JSON Integers

encodeJson :: Int64 -> Json
encodeJson x = intAsJson x
Binary

There are two byte encodings for any integer larger than 8 bits - big-endian or little-endian.

encodeBinary :: Int64 -> ByteString
encodeBinary x = intAsByteStringBE x
encodeBinary :: Int64 -> ByteString
encodeBinary x = intAsByteStringLE x
Symbiote Test Suite Instance
  • Topic

String literal Topic used in the Symbiote Test Suite for this data type. Composed solely as Int64.

"Int64"

Unsigned

Uint8

Range varies from 0 to 2^8-1

data Uint8 = 0 | 1 | ... | 2^8-2 | 2^8-1
JSON

Uses standard JSON Integers

encodeJson :: Uint8 -> Json
encodeJson x = uintAsJson x
Binary
encodeBinary :: Uint8 -> ByteString
encodeBinary x = byteAsByteString x
Symbiote Test Suite Instance
  • Topic

String literal Topic used in the Symbiote Test Suite for this data type. Composed solely as Uint8.

"Uint8"

Uint16

Range varies from 0 to 2^16-1


data Uint16 = 0 | 1 | … | 2^16-2 | 2^16-1

JSON

Uses standard JSON Integers

encodeJson :: Uint16 -> Json
encodeJson x = uintAsJson x
Binary

There are two byte encodings for any integer larger than 8 bits - big-endian or little-endian.

encodeBinary :: Uint16 -> ByteString
encodeBinary x = uintAsByteStringBE x
encodeBinary :: Uint16 -> ByteString
encodeBinary x = uintAsByteStringLE x
Symbiote Test Suite Instance
  • Topic

String literal Topic used in the Symbiote Test Suite for this data type. Composed solely as Uint16.

"Uint16"

Uint32

Range varies from 0 to 2^32-1

data Uint32 = 0 | 1 | ... | 2^32-2 | 2^32-1
JSON

Uses standard JSON Integers

encodeJson :: Uint32 -> Json
encodeJson x = uintAsJson x
Binary

There are two byte encodings for any integer larger than 8 bits - big-endian or little-endian.

encodeBinary :: Uint32 -> ByteString
encodeBinary x = uintAsByteStringBE x
encodeBinary :: Uint32 -> ByteString
encodeBinary x = uintAsByteStringLE x
Symbiote Test Suite Instance
  • Topic

String literal Topic used in the Symbiote Test Suite for this data type. Composed solely as Uint32.

"Uint32"

Uint64

Range varies from 0 to 2^64-1

data Uint64 = 0 | 1 | ... | 2^64-2 | 2^64-1
JSON

Uses standard JSON Integers

encodeJson :: Uint64 -> Json
encodeJson x = uintAsJson x
Binary

There are two byte encodings for any integer larger than 8 bits - big-endian or little-endian.

encodeBinary :: Uint64 -> ByteString
encodeBinary x = uintAsByteStringBE x
encodeBinary :: Uint64 -> ByteString
encodeBinary x = uintAsByteStringLE x
Symbiote Test Suite Instance
  • Topic

String literal Topic used in the Symbiote Test Suite for this data type. Composed solely as Uint64.

"Uint64"

Multiple Precision

Integer8

Arbitrary precision signed integer, implemented as (for instance) GNU MP, but with a max unrolled length of 2^8 bytes long.

JSON

Uses a string encoding of the integer value, because not every platform can support very large integer values during JSON decoding.

encodeJson :: Integer8 -> Json
encodeJson x = stringAsJson (integerAsString x)
Binary

Performed via cereal byte-unrolling, but with the concern that the length of unrolled bytes is an 8-bit unsigned integer.

Symbiote Test Suite Instance
  • Topic

String literal Topic used in the Symbiote Test Suite for this data type. Composed solely as Integer8.

"Integer8"

Integer16

Arbitrary precision signed integer, implemented as (for instance) GNU MP, but with a max unrolled length of 2^16 bytes long.

JSON

Uses a string encoding of the integer value, because not every platform can support very large integer values during JSON decoding.

encodeJson :: Integer16 -> Json
encodeJson x = stringAsJson (integerAsString x)
Binary

Performed via cereal byte-unrolling, but with the concern that the length of unrolled bytes is a 16-bit unsigned integer.

Symbiote Test Suite Instance
  • Topic

String literal Topic used in the Symbiote Test Suite for this data type. Composed solely as Integer16.

"Integer16"

Integer32

Arbitrary precision signed integer, implemented as (for instance) GNU MP, but with a max unrolled length of 2^32 bytes long.

JSON

Uses a string encoding of the integer value, because not every platform can support very large integer values during JSON decoding.

encodeJson :: Integer32 -> Json
encodeJson x = stringAsJson (integerAsString x)
Binary

Performed via cereal byte-unrolling, but with the concern that the length of unrolled bytes is a 32-bit unsigned integer.

Symbiote Test Suite Instance
  • Topic

String literal Topic used in the Symbiote Test Suite for this data type. Composed solely as Integer32.

"Integer32"

Integer64

Arbitrary precision signed integer, implemented as (for instance) GNU MP, but with a max unrolled length of 2^64 bytes long.

JSON

Uses a string encoding of the integer value, because not every platform can support very large integer values during JSON decoding.

encodeJson :: Integer64 -> Json
encodeJson x = stringAsJson (integerAsString x)
Binary

Performed via cereal byte-unrolling, but with the concern that the length of unrolled bytes is a 64-bit unsigned integer.

Symbiote Test Suite Instance
  • Topic

String literal Topic used in the Symbiote Test Suite for this data type. Composed solely as Integer64.

"Integer64"

Natural8

Arbitrary precision unsigned integer, implemented as (for instance) GNU MP, but with a max unrolled length of 2^8 bytes long.

JSON

Uses a string encoding of the integer value, because not every platform can support very large integer values during JSON decoding.

encodeJson :: Natural8 -> Json
encodeJson x = stringAsJson (naturalAsString x)
Binary

Performed via cereal byte-unrolling, but with the concern that the length of unrolled bytes is an 8-bit unsigned integer.

Symbiote Test Suite Instance
  • Topic

String literal Topic used in the Symbiote Test Suite for this data type. Composed solely as Natural8.

"Natural8"

Natural16

Arbitrary precision unsigned integer, implemented as (for instance) GNU MP, but with a max unrolled length of 2^16 bytes long.

JSON

Uses a string encoding of the integer value, because not every platform can support very large integer values during JSON decoding.

encodeJson :: Natural16 -> Json
encodeJson x = stringAsJson (naturalAsString x)
Binary

Performed via cereal byte-unrolling, but with the concern that the length of unrolled bytes is a 16-bit unsigned integer.

Symbiote Test Suite Instance
  • Topic

String literal Topic used in the Symbiote Test Suite for this data type. Composed solely as Natural16.

"Natural16"

Natural32

Arbitrary precision unsigned integer, implemented as (for instance) GNU MP, but with a max unrolled length of 2^32 bytes long.

JSON

Uses a string encoding of the integer value, because not every platform can support very large integer values during JSON decoding.

encodeJson :: Natural32 -> Json
encodeJson x = stringAsJson (naturalAsString x)
Binary

Performed via cereal byte-unrolling, but with the concern that the length of unrolled bytes is a 32-bit unsigned integer.

Symbiote Test Suite Instance
  • Topic

String literal Topic used in the Symbiote Test Suite for this data type. Composed solely as Natural32.

"Natural32"

Natural64

Arbitrary precision unsigned integer, implemented as (for instance) GNU MP, but with a max unrolled length of 2^64 bytes long.

JSON

Uses a string encoding of the integer value, because not every platform can support very large integer values during JSON decoding.

encodeJson :: Natural64 -> Json
encodeJson x = stringAsJson (naturalAsString x)
Binary

Performed via cereal byte-unrolling, but with the concern that the length of unrolled bytes is a 64-bit unsigned integer.

Symbiote Test Suite Instance
  • Topic

String literal Topic used in the Symbiote Test Suite for this data type. Composed solely as Natural64.

"Natural64"

Floating Point

Float32

A binary32 implementation of IEEE 754

JSON

Uses standard JSON Numbers

encodeJson :: Float32 -> Json
encodeJson x = floatAsJson x
Binary

There are two byte encodings for any floating point number - big-endian or little-endian.

encodeBinary :: Float32 -> ByteString
encodeBinary x = floatAsByteStringBE x
encodeBinary :: Float32 -> ByteString
encodeBinary x = floatAsByteStringLE x
Symbiote Test Suite Instance
Topic

String literal Topic used in the Symbiote Test Suite for this data type. Composed solely as Float32.

"Float32"

Float64

A binary64 implementation of IEEE 754

JSON

Uses standard JSON Numbers

encodeJson :: Float64 -> Json
encodeJson x = floatAsJson x
Binary

There are two byte encodings for any floating point number - big-endian or little-endian.

encodeBinary :: Float64 -> ByteString
encodeBinary x = floatAsByteStringBE x
encodeBinary :: Float64 -> ByteString
encodeBinary x = floatAsByteStringLE x
Symbiote Test Suite Instance
Topic

String literal Topic used in the Symbiote Test Suite for this data type. Composed solely as Float64.

"Float64"

Scientific

A scientific notation implementation

JSON

Encoded as a JSON String, in canonical scientific notation - an exponential field (*10^n) is always present, even when n == 0, and prefixes its sign in all cases (i.e. 9e3 is 9e+3). Likewise, the coefficient is always -10 < c < 10 - no engineering notation is allowed. Furthermore, the coefficient _never_ includes trailing zeros - i.e. 9.230e+0 is 9.23e+0. Moreover, when the value clearly doesn’t need a decimal place, it should be omitted - i.e. 9.0e+3 is 9e+3.

encodeJson :: Scientific -> Json
encodeJson x = stringAsJson (scientificToString x)
Binary

Uses the same UTF8 string format as JSON, but limited to a String32.

Symbiote Test Suite Instance
Topic

String literal Topic used in the Symbiote Test Suite for this data type. Composed solely as Scientific.

"Scientific"

Ratio

A (lossless) rational number implementation, by ratios.

data Ratio a = Ratio a a
JSON

Encoded as a tuple of the two already encoded values

encodeJson :: Ratio Json -> Json
encodeJson (Ratio x y) = [x,y]
Binary

Encoded as a tuple of the two already encoded values

encodeBinary :: Ratio ByteString -> ByteString
encodeBinary (Ratio x y) = x ++ y
Symbiote Test Suite Instance
Topic

String literal Topic used in the Symbiote Test Suite for this data type. Composed as Ratio Int32 Int32.

"Ratio"

UTF-8 Strings

Char

All characters must be valid UTF-8 characters, especially with respect to surrogate codes between 0xD800 and 0xDFFF - with respect to RFC 3629. Conversion a ‘la CESU-8 may or may not be defined with this data type.

JSON

Uses standard JSON Strings

encodeJson :: Char -> Json
encodeJson x = charAsJson x
Binary

Encodes to a ByteString as standard UTF-8.

encodeBinary :: Char -> ByteString
encodeBinary x = utf8AsByteString x
Symbiote Test Suite Instance
Topic

String literal Topic used in the Symbiote Test Suite for this data type. Composed solely as Char.

"Char"

String8

Where the length of the string is at most 2^8 characters long

data String8 = Vector8 Char
JSON

Uses standard JSON Strings

encodeJson :: String8 -> Json
encodeJson x = stringAsJson x
Binary

Encodes to a ByteString as a Vector8 of Char s

encodeBinary :: String8 -> ByteString
encodeBinary x = vector8ToByteString (map utf8AsByteString (string8AsVector8 x))
Symbiote Test Suite Instance
Topic

String literal Topic used in the Symbiote Test Suite for this data type. Composed solely as String8.

"String8"

String16

Where the length of the string is at most 2^16 characters long

data String16 = Vector16 Char
JSON

Uses standard JSON Strings

encodeJson :: String16 -> Json
encodeJson x = stringAsJson x
Binary

Encodes to a ByteString as a Vector16 of Char s

encodeBinary :: String16 -> ByteString
encodeBinary x = vector16ToByteString (map utf8AsByteString (string16AsVector16 x))
Symbiote Test Suite Instance
Topic

String literal Topic used in the Symbiote Test Suite for this data type. Composed solely as String16.

"String16"

String32

Where the length of the string is at most 2^32 characters long

data String32 = Vector32 Char
JSON

Uses standard JSON Strings

encodeJson :: String32 -> Json
encodeJson x = stringAsJson x
Binary

Encodes to a ByteString as a Vector32 of Char s

encodeBinary :: String32 -> ByteString
encodeBinary x = vector32ToByteString (map utf8AsByteString (string32AsVector32 x))
Symbiote Test Suite Instance
Topic

String literal Topic used in the Symbiote Test Suite for this data type. Composed solely as String32.

"String32"

String64

Where the length of the string is at most 2^64 characters long

data String64 = Vector64 Char
JSON

Uses standard JSON Strings

encodeJson :: String64 -> Json
encodeJson x = stringAsJson x
Binary

Encodes to a ByteString as a Vector64 of Char s

encodeBinary :: String64 -> ByteString
encodeBinary x = vector64ToByteString (map utf8AsByteString (string64AsVector64 x))
Symbiote Test Suite Instance
Topic

String literal Topic used in the Symbiote Test Suite for this data type. Composed solely as String64.

"String64"

Casual

Chronological

Date

Any date system that keeps track of year, month, and day. Years are biased in the Common Era, and can range from -2^15 to 2^15-1.

data Date = Date
  (year :: Int16)
  (month :: Uint8)
  (day :: Uint8)
JSON

Formatted as an ISO 8601 Calendar Date / “military date” string YYYYMMDD.

encodeJson :: Date -> Json
encodeJson x = stringAsJson (iso8601 "YYYYMMDD" x)
Binary

Encoded directly as one 16-bit signed integer as the year, and two bytes as the month and day. Although there could be a way to encode a practical calendar date as 21-bits (using a 13-bit year, 4-bit month, and 5-bit day), the conversions would be considerable overhead when dealing with large amounts of date data. And “practical” in the sense of Ancient History (3000 B.C.E.) being the limit of dating capability.

encodeByteString :: Date -> ByteString
encodeByteString (Date year month day) =
  (intAsByteStringBE year)
    ++ (uintAsByteString month)
    ++ (uintAsByteString day)
Symbiote Test Suite Instance
Topic

String literal Topic used in the Symbiote Test Suite for this data type. Composed solely as Date.

"Date"

Time

Any time system that keeps track of timezone, hour, minute, second, and millisecond. Milliseconds are included because most modern systems can emit logs with millisecond precision, and is a likely use case.

data Time = Time
  (tzhour :: Int8)
  (tzminute :: Uint8)
  (hour :: Uint8)
  (minute :: Uint8)
  (second :: Uint8)
  (millisecond :: Uint16)
JSON

Formatted as an ISO 8601 Time string hhmmss.sss.

encodeJson :: Time -> Json
encodeJson x = stringAsJson (iso8601 "hhmmss.sss" x)
Binary

Encoded directly as 5 bytes for timezone, hour, minute, and second, and one 16-bit unsigned integer for milliseconds. Although there could be a way to encode a practical time as 38-bits (5-bit hour and tzhour, 6-bit minute, tzminute and second, 10-bit millisecond), the conversions would be considerable overhead when dealing with large amounts of time data.

encodeByteString :: Time -> ByteString
encodeByteString
  (Time tzhour tzminute hour minute second millisecond) =
    (intAsByteString tzhour)
      ++ (uintAsByteString tzminute)
      ++ (uintAsByteString hour)
      ++ (uintAsByteString minute)
      ++ (uintAsByteString second)
      ++ (uintAsByteStringBE millisecond)
Symbiote Test Suite Instance
Topic

String literal Topic used in the Symbiote Test Suite for this data type. Composed solely as Time.

"Time"

DateTime

Can be represented internally as any “sane” date / time system.

data DateTime = Tuple Date Time
JSON

Formatted as an ISO 8601 Combined String

encodeJson :: DateTime -> Json
encodeJson x = stringAsJson (iso8601 x)
Binary

Concatenation of both formats (total of 11 bytes).

encodeByteString :: DateTime -> ByteString
encodeByteString (Tuple date time) =
  (encodeByteStringDate date)
    ++ (encodeByteStringTime time)

Todo

  • Intervals, Durations
Symbiote Test Suite Instance
Topic

String literal Topic used in the Symbiote Test Suite for this data type. Composed solely as DateTime.

"DateTime"

URI-Like

IPV4

data IPV4 = IPV4 Uint8 Uint8 Uint8 Uint8
JSON

Formatted as a string to remain unambiguous

encodeJson :: IPV4 -> Json
encodeJson x = stringAsJson (ipv4AsString x)
Binary

Encoded directly as 4 bytes

encodeByteString :: IPV4 -> ByteString
encodeByteString (IPV4 a b c d) =
  (uintAsByteStringBE a)
    ++ (uintAsByteStringBE b)
    ++ (uintAsByteStringBE c)
    ++ (uintAsByteStringBE d)
Symbiote Test Suite Instance
Topic

String literal Topic used in the Symbiote Test Suite for this data type. Composed solely as IPV4.

"IPV4"

IPV6

data IPV6 =
  IPV6
    Uint16 Uint16 Uint16 Uint16
    Uint16 Uint16 Uint16 Uint16
JSON

Formatted as a string to remain unambiguous

encodeJson :: IPV6 -> Json
encodeJson x = stringAsJson (ipv6AsString x)
Binary

Encoded directly as 16 bytes

encodeByteString :: IPV6 -> ByteString
encodeByteString (IPV6 a b c d e f g h) =
  (uintAsByteStringBE a)
    ++ (uintAsByteStringBE b)
    ++ (uintAsByteStringBE c)
    ++ (uintAsByteStringBE d)
    ++ (uintAsByteStringBE e)
    ++ (uintAsByteStringBE f)
    ++ (uintAsByteStringBE g)
    ++ (uintAsByteStringBE h)
Symbiote Test Suite Instance
Topic

String literal Topic used in the Symbiote Test Suite for this data type. Composed solely as IPV6.

"IPV6"

URI

Should be a valid URI with Percent Encoding for all reserved, non-valid, and UTF-8 characters in their appropriate components in the URI, while the query may have x-www-form-urlencoded data.

JSON

Formatted as its string representation

encodeJson :: URI -> Json
encodeJson x = stringAsJson (uriAsString x)
Binary

Encoded as a UTF-8 String32 (though there are only ASCII characters allowed) - other implementations of URI8 etc may exist in a future version.

encodeByteString :: URI -> ByteString
encodeByteString x = utf8AsByteString (uriAsString x)
Symbiote Test Suite Instance
Topic

String literal Topic used in the Symbiote Test Suite for this data type. Composed solely as URI.

"URI"

Email Address

Should be represented in a vaild ASCII Email Address format, as per Wikipedia / RFC 5322.

JSON

Formatted as the string representation

encodeJson :: EmailAddress -> Json
encodeJson x = stringAsJson (emailAddressAsString x)
Binary

Encoded as a UTF-8 String16 (though there are only ASCII characters allowed)

encodeByteString :: EmailAddress -> ByteString
encodeByteString x = utf8AsByteString (emailAddressAsString x)

Todo

Symbiote Test Suite Instance
Topic

String literal Topic used in the Symbiote Test Suite for this data type. Composed solely as EmailAddress.

"EmailAddress"

Primitive Composites

Collections

Array

A size-indexed array of homogeneous data.

data Array (n :: Nat) a where
  Nil :: Array 0 a
  Cons :: a -> Array n a -> Array (n + 1) a
JSON

Uses standard JSON Arrays

encodeJson :: Array n Json -> Json
encodeJson x = arrayAsJson x
Binary

Ommits a size parameter, because the size is encoded in the type signature.

encodeBinary :: Array n ByteString -> ByteString
encodeBinary x = case x of
  Nil -> emptyByteString
  Cons y ys -> y ++ (encodeBinary ys)
Symbiote Test Suite Instance
Topic

String literal Topic used in the Symbiote Test Suite for this data type. Composed as Array 20 Int32 (length of 20 Int32 s).

"Array"

Vector8

A dynamically sized array that limits the max size to 2^8 elements

JSON

Uses standard JSON Arrays

encodeJson :: Vector8 Json -> Json
encodeJson x = arrayAsJson x
Binary

Prefixes the length of the array as a 8-bit unsigned integer, big-endian, before concatenating all contents.

encodeBinary :: Vector8 ByteString -> ByteString
encodeBinary x = (uintAsByteStringBE l) ++ (concatVector8 x)
Symbiote Test Suite Instance
Topic

String literal Topic used in the Symbiote Test Suite for this data type. Composed as Vector8 Int32.

"Vector8"

Vector16

A dynamically sized array that limits the max size to 2^16 elements

JSON

Uses standard JSON Arrays

encodeJson :: Vector16 Json -> Json
encodeJson x = arrayAsJson x
Binary

Prefixes the length of the array as a 16-bit unsigned integer, big-endian, before concatenating all contents.

encodeBinary :: Vector16 ByteString -> ByteString
encodeBinary x = (uintAsByteStringBE l) ++ (concatVector16 x)
Symbiote Test Suite Instance
Topic

String literal Topic used in the Symbiote Test Suite for this data type. Composed as Vector16 Int32.

"Vector16"

Vector32

A dynamically sized array that limits the max size to 2^32 elements

JSON

Uses standard JSON Arrays

encodeJson :: Vector32 Json -> Json
encodeJson x = arrayAsJson x
Binary

Prefixes the length of the array as a 32-bit unsigned integer, big-endian, before concatenating all contents.

encodeBinary :: Vector32 ByteString -> ByteString
encodeBinary x = (uintAsByteStringBE l) ++ (concatVector32 x)
Symbiote Test Suite Instance
Topic

String literal Topic used in the Symbiote Test Suite for this data type. Composed as Vector32 Int32.

"Vector32"

Vector64

A dynamically sized array that limits the max size to 2^64 elements

JSON

Uses standard JSON Arrays

encodeJson :: Vector64 Json -> Json
encodeJson x = arrayAsJson x
Binary

Prefixes the length of the array as a 64-bit unsigned integer, big-endian, before concatenating all contents.

encodeBinary :: Vector64 ByteString -> ByteString
encodeBinary x = (uintAsByteStringBE l) ++ (concatVector64 x)
Symbiote Test Suite Instance
Topic

String literal Topic used in the Symbiote Test Suite for this data type. Composed as Vector64 Int32.

"Vector64"

Maybe

Standard option type

data Maybe a = Nothing | Maybe a

JSON

Uses standard JSON null if Nothing, otherwise just use its JSON - leverages backtracking

encodeJson :: Maybe Json -> Json
encodeJson x = case x of
  Nothing -> nullJson
  Just y -> y

Binary

Use a prefix byte flag to avoid backtracking

encodeBinary :: Maybe ByteString -> ByteString
encodeBinary x = case x of
  Nothing -> byteAsByteString 0
  Just y -> (byteAsByteString 1) ++ y

Symbiote Test Suite Instance

Topic

String literal Topic used in the Symbiote Test Suite for this data type. Composed as Maybe Int32.

"Maybe"

Tuple

data Tuple a b = Tuple a b

JSON

Uses a standard JSON Array to hold the two elements

encodeJson :: Tuple Json Json -> Json
encodeJson (Tuple x y) = [x,y]

Binary

Is equivalent to an array of size 2, therefore avoids a size prefix

encodeBinary :: Tuple ByteString ByteString -> ByteString
encodeBinary (Tuple x y) = x ++ y

Symbiote Test Suite Instance

Topic

String literal Topic used in the Symbiote Test Suite for this data type. Composed as Tuple Int32 Int32.

"Tuple"

Either

data Either a b = Left a | Right b

JSON

Flags each case with a unique object key

encodeJson :: Either Json Json -> Json
encodeJson x = case x of
  Left y -> {"l": y}
  Right z -> {"r": z}

Binary

Flags each case with a byte prefix

encodeBinary :: Either ByteString ByteString -> ByteString
encodeBinary x = case x of
  Left y -> (byteAsByteString 0) ++ y
  Right z -> (byteAsByteString 1) ++ z

Symbiote Test Suite Instance

Topic

String literal Topic used in the Symbiote Test Suite for this data type. Composed as Either Int32 Int32.

"Either"

Sophisticated Composites

Mappings

StringMap8

Mapping where String8 s are the keys - can be implemented as a hash-map internally, or as a JSON object as the case with JavaScript.

JSON

Serialized as a JSON object

encodeJson :: StringMap8 Json -> Json
encodeJson x = stringMap8AsJson x
Binary

Encodes as a dynamically sized array of key-value tuples, where the size is a 8-bit unsigned integer.

encodeBinary :: StringMap8 ByteString -> ByteString
encodeBinary x = concatVector8 (map tupleToByteString (stringMap8AsVector8 x))
  where
    tupleToByteString :: Tuple String ByteString -> ByteString
    tupleToByteString (Tuple k v) = (encodeByteString k) ++ v
Symbiote Test Suite Instance
Topic

String literal Topic used in the Symbiote Test Suite for this data type. Composed as StringMap8 Int32.

"StringMap8"

StringMap16

Mapping where String16 s are the keys - can be implemented as a hash-map internally, or as a JSON object as the case with JavaScript.

JSON

Serialized as a JSON object

encodeJson :: StringMap16 Json -> Json
encodeJson x = stringMap16AsJson x
Binary

Encodes as a dynamically sized array of key-value tuples, where the size is a 16-bit unsigned integer.

encodeBinary :: StringMap16 ByteString -> ByteString
encodeBinary x = concatVector16 (map tupleToByteString (stringMap16AsVector16 x))
  where
    tupleToByteString :: Tuple String ByteString -> ByteString
    tupleToByteString (Tuple k v) = (encodeByteString k) ++ v
Symbiote Test Suite Instance
Topic

String literal Topic used in the Symbiote Test Suite for this data type. Composed as StringMap16 Int32.

"StringMap16"

StringMap32

Mapping where String32 s are the keys - can be implemented as a hash-map internally, or as a JSON object as the case with JavaScript.

JSON

Serialized as a JSON object

encodeJson :: StringMap32 Json -> Json
encodeJson x = stringMap32AsJson x
Binary

Encodes as a dynamically sized array of key-value tuples, where the size is a 32-bit unsigned integer.

encodeBinary :: StringMap32 ByteString -> ByteString
encodeBinary x = concatVector32 (map tupleToByteString (stringMap32AsVector32 x))
  where
    tupleToByteString :: Tuple String ByteString -> ByteString
    tupleToByteString (Tuple k v) = (encodeByteString k) ++ v
Symbiote Test Suite Instance
Topic

String literal Topic used in the Symbiote Test Suite for this data type. Composed as StringMap32 Int32.

"StringMap32"

StringMap64

Mapping where String64 s are the keys - can be implemented as a hash-map internally, or as a JSON object as the case with JavaScript.

JSON

Serialized as a JSON object

encodeJson :: StringMap64 Json -> Json
encodeJson x = stringMap64AsJson x
Binary

Encodes as a dynamically sized array of key-value tuples, where the size is a 64-bit unsigned integer.

encodeBinary :: StringMap64 ByteString -> ByteString
encodeBinary x = concatVector64 (map tupleToByteString (stringMap64AsVector64 x))
  where
    tupleToByteString :: Tuple String ByteString -> ByteString
    tupleToByteString (Tuple k v) = (encodeByteString k) ++ v
Symbiote Test Suite Instance
Topic

String literal Topic used in the Symbiote Test Suite for this data type. Composed as StringMap64 Int32.

"StringMap64"

Map8

Polymorphic mapping - can be implemented any way: B-Tree, or unordered - serialization does not restrict the implementation.

JSON

Serialized as an array of arrays / tuples.

encodeJson :: Map8 Json Json -> Json
encodeJson x = map tupleToJson (map8AsVector8 x)
  where
    tupleToJson :: Tuple Json Json -> Json
    tupleToJson (Tuple k v) = [k,v]
Binary

Encodes as a dynamically sized array of key-value tuples, where the size is a 8-bit unsigned integer.

encodeBinary :: Map8 ByteString ByteString -> ByteString
encodeBinary x = concatVector8 (map tupleToByteString (map8AsVector8 x))
  where
    tupleToByteString :: Tuple ByteString ByteString -> ByteString
    tupleToByteString (Tuple k v) = k ++ v
Symbiote Test Suite Instance
Topic

String literal Topic used in the Symbiote Test Suite for this data type. Composed as Map8 Int32 Int32.

"Map8"

Map16

Polymorphic mapping - can be implemented any way: B-Tree, or unordered - serialization does not restrict the implementation.

JSON

Serialized as an array of arrays / tuples.

encodeJson :: Map16 Json Json -> Json
encodeJson x = map tupleToJson (map16AsVector16 x)
  where
    tupleToJson :: Tuple Json Json -> Json
    tupleToJson (Tuple k v) = [k,v]
Binary

Encodes as a dynamically sized array of key-value tuples, where the size is a 16-bit unsigned integer.

encodeBinary :: Map16 ByteString ByteString -> ByteString
encodeBinary x = concatVector16 (map tupleToByteString (map16AsVector16 x))
  where
    tupleToByteString :: Tuple ByteString ByteString -> ByteString
    tupleToByteString (Tuple k v) = k ++ v
Symbiote Test Suite Instance
Topic

String literal Topic used in the Symbiote Test Suite for this data type. Composed as Map16 Int32 Int32.

"Map16"

Map32

Polymorphic mapping - can be implemented any way: B-Tree, or unordered - serialization does not restrict the implementation.

JSON

Serialized as an array of arrays / tuples.

encodeJson :: Map32 Json Json -> Json
encodeJson x = map tupleToJson (map32AsVector32 x)
  where
    tupleToJson :: Tuple Json Json -> Json
    tupleToJson (Tuple k v) = [k,v]
Binary

Encodes as a dynamically sized array of key-value tuples, where the size is a 32-bit unsigned integer.

encodeBinary :: Map32 ByteString ByteString -> ByteString
encodeBinary x = concatVector32 (map tupleToByteString (map32AsVector32 x))
  where
    tupleToByteString :: Tuple ByteString ByteString -> ByteString
    tupleToByteString (Tuple k v) = k ++ v
Symbiote Test Suite Instance
Topic

String literal Topic used in the Symbiote Test Suite for this data type. Composed as Map32 Int32 Int32.

"Map32"

Map64

Polymorphic mapping - can be implemented any way: B-Tree, or unordered - serialization does not restrict the implementation.

JSON

Serialized as an array of arrays / tuples.

encodeJson :: Map64 Json Json -> Json
encodeJson x = map tupleToJson (map64AsVector64 x)
  where
    tupleToJson :: Tuple Json Json -> Json
    tupleToJson (Tuple k v) = [k,v]
Binary

Encodes as a dynamically sized array of key-value tuples, where the size is a 64-bit unsigned integer.

encodeBinary :: Map64 ByteString ByteString -> ByteString
encodeBinary x = concatVector64 (map tupleToByteString (map64AsVector64 x))
  where
    tupleToByteString :: Tuple ByteString ByteString -> ByteString
    tupleToByteString (Tuple k v) = k ++ v
Symbiote Test Suite Instance
Topic

String literal Topic used in the Symbiote Test Suite for this data type. Composed as Map64 Int32 Int32.

"Map64"

Tries

StringTrie8

Recursive StringMap8, with values along the way.

data StringTrie8 a = StringMap8 (Tuple (Maybe a) (StringTrie8 a))
JSON

Uses a standard JSON Object as the key index

encodeJson :: StringTrie8 Json -> Json
encodeJson x = stringMap8AsObject (map tupleToJson x)
  where
    tupleToJson :: Tuple (Maybe Json) (StringTrie8 Json) -> Json
    tupleToJson (Tuple v y) = [maybeToJson v, encodeJson y]
Binary

Encoded as a series of dynamically sized arrays - uses composite encodeByteString instances for each level.

encodeByteString :: StringTrie8 ByteString -> ByteString
encodeByteString x = encodeByteStringVector8 (stringMap8AsVector8 (map tupleToByteString x))
  where
    tupleToByteString :: Tuple (Maybe ByteString) (StringTrie8 ByteString) -> ByteString
    tupleToByteString (Tuple v y) = (maybeToByteString v) ++ (encodeByteString y)
Symbiote Test Suite Instance
Topic

String literal Topic used in the Symbiote Test Suite for this data type. Composed as StringTrie8 Int32.

"StringTrie8"

StringTrie16

Recursive StringMap16, with values along the way.

data StringTrie16 a = StringMap16 (Tuple (Maybe a) (StringTrie16 a))
JSON

Uses a standard JSON Object as the key index

encodeJson :: StringTrie16 Json -> Json
encodeJson x = stringMap16AsObject (map tupleToJson x)
  where
    tupleToJson :: Tuple (Maybe Json) (StringTrie16 Json) -> Json
    tupleToJson (Tuple v y) = [maybeToJson v, encodeJson y]
Binary

Encoded as a series of dynamically sized arrays - uses composite encodeByteString instances for each level.

encodeByteString :: StringTrie16 ByteString -> ByteString
encodeByteString x = encodeByteStringVector16 (stringMap16AsVector16 (map tupleToByteString x))
  where
    tupleToByteString :: Tuple (Maybe ByteString) (StringTrie16 ByteString) -> ByteString
    tupleToByteString (Tuple v y) = (maybeToByteString v) ++ (encodeByteString y)
Symbiote Test Suite Instance
Topic

String literal Topic used in the Symbiote Test Suite for this data type. Composed as StringTrie16 Int32.

"StringTrie16"

StringTrie32

Recursive StringMap32, with values along the way.

data StringTrie32 a = StringMap32 (Tuple (Maybe a) (StringTrie32 a))
JSON

Uses a standard JSON Object as the key index

encodeJson :: StringTrie32 Json -> Json
encodeJson x = stringMap32AsObject (map tupleToJson x)
  where
    tupleToJson :: Tuple (Maybe Json) (StringTrie32 Json) -> Json
    tupleToJson (Tuple v y) = [maybeToJson v, encodeJson y]
Binary

Encoded as a series of dynamically sized arrays - uses composite encodeByteString instances for each level.

encodeByteString :: StringTrie32 ByteString -> ByteString
encodeByteString x = encodeByteStringVector32 (stringMap32AsVector32 (map tupleToByteString x))
  where
    tupleToByteString :: Tuple (Maybe ByteString) (StringTrie32 ByteString) -> ByteString
    tupleToByteString (Tuple v y) = (maybeToByteString v) ++ (encodeByteString y)
Symbiote Test Suite Instance
Topic

String literal Topic used in the Symbiote Test Suite for this data type. Composed as StringTrie32 Int32.

"StringTrie32"

StringTrie64

Recursive StringMap64, with values along the way.

data StringTrie64 a = StringMap64 (Tuple (Maybe a) (StringTrie64 a))
JSON

Uses a standard JSON Object as the key index

encodeJson :: StringTrie64 Json -> Json
encodeJson x = stringMap64AsObject (map tupleToJson x)
  where
    tupleToJson :: Tuple (Maybe Json) (StringTrie64 Json) -> Json
    tupleToJson (Tuple v y) = [maybeToJson v, encodeJson y]
Binary

Encoded as a series of dynamically sized arrays - uses composite encodeByteString instances for each level.

encodeByteString :: StringTrie64 ByteString -> ByteString
encodeByteString x = encodeByteStringVector64 (stringMap64AsVector64 (map tupleToByteString x))
  where
    tupleToByteString :: Tuple (Maybe ByteString) (StringTrie64 ByteString) -> ByteString
    tupleToByteString (Tuple v y) = (maybeToByteString v) ++ (encodeByteString y)
Symbiote Test Suite Instance
Topic

String literal Topic used in the Symbiote Test Suite for this data type. Composed as StringTrie64 Int32.

"StringTrie64"

Trie8

Recursive Map8, with values along the way.

data Trie8 k a = Map8 k (Tuple (Maybe a) (Trie8 k a))
JSON

Uses nested Arrays

encodeJson :: Trie8 Json Json -> Json
encodeJson x = map8AsVector8 (map tupleToJson x)
  where
    tupleToJson :: Tuple (Maybe Json) (Trie8 Json Json) -> Json
    tupleToJson (Tuple v y) = [maybeToJson v, encodeJson y]
Binary

Encoded as a series of dynamically sized arrays - uses composite encodeByteString instances for each level.

encodeByteString :: Trie8 ByteString ByteString -> ByteString
encodeByteString x = encodeByteStringVector8 (map8AsVector8 (map tupleToByteString x))
  where
    tupleToByteString :: Tuple (Maybe ByteString) (Trie8 ByteString ByteString) -> ByteString
    tupleToByteString (Tuple v y) = (maybeToByteString v) ++ (encodeByteString y)
Symbiote Test Suite Instance
Topic

String literal Topic used in the Symbiote Test Suite for this data type. Composed as Trie8 Int32 Int32.

"Trie8"

Trie16

Recursive Map16, with values along the way.

data Trie16 k a = Map16 k (Tuple (Maybe a) (Trie16 k a))
JSON

Uses nested Arrays

encodeJson :: Trie16 Json Json -> Json
encodeJson x = map16AsVector16 (map tupleToJson x)
  where
    tupleToJson :: Tuple (Maybe Json) (Trie16 Json Json) -> Json
    tupleToJson (Tuple v y) = [maybeToJson v, encodeJson y]
Binary

Encoded as a series of dynamically sized arrays - uses composite encodeByteString instances for each level.

encodeByteString :: Trie16 ByteString ByteString -> ByteString
encodeByteString x = encodeByteStringVector16 (map16AsVector16 (map tupleToByteString x))
  where
    tupleToByteString :: Tuple (Maybe ByteString) (Trie16 ByteString ByteString) -> ByteString
    tupleToByteString (Tuple v y) = (maybeToByteString v) ++ (encodeByteString y)
Symbiote Test Suite Instance
Topic

String literal Topic used in the Symbiote Test Suite for this data type. Composed as Trie16 Int32 Int32.

"Trie16"

Trie32

Recursive Map32, with values along the way.

data Trie32 k a = Map32 k (Tuple (Maybe a) (Trie32 k a))
JSON

Uses nested Arrays

encodeJson :: Trie32 Json Json -> Json
encodeJson x = map32AsVector32 (map tupleToJson x)
  where
    tupleToJson :: Tuple (Maybe Json) (Trie32 Json Json) -> Json
    tupleToJson (Tuple v y) = [maybeToJson v, encodeJson y]
Binary

Encoded as a series of dynamically sized arrays - uses composite encodeByteString instances for each level.

encodeByteString :: Trie32 ByteString ByteString -> ByteString
encodeByteString x = encodeByteStringVector32 (map32AsVector32 (map tupleToByteString x))
  where
    tupleToByteString :: Tuple (Maybe ByteString) (Trie32 ByteString ByteString) -> ByteString
    tupleToByteString (Tuple v y) = (maybeToByteString v) ++ (encodeByteString y)
Symbiote Test Suite Instance
Topic

String literal Topic used in the Symbiote Test Suite for this data type. Composed as Trie32 Int32 Int32.

"Trie32"

Trie64

Recursive Map64, with values along the way.

data Trie64 k a = Map64 k (Tuple (Maybe a) (Trie64 k a))
JSON

Uses nested Arrays

encodeJson :: Trie64 Json Json -> Json
encodeJson x = map64AsVector64 (map tupleToJson x)
  where
    tupleToJson :: Tuple (Maybe Json) (Trie64 Json Json) -> Json
    tupleToJson (Tuple v y) = [maybeToJson v, encodeJson y]
Binary

Encoded as a series of dynamically sized arrays - uses composite encodeByteString instances for each level.

encodeByteString :: Trie64 ByteString ByteString -> ByteString
encodeByteString x = encodeByteStringVector64 (map64AsVector64 (map tupleToByteString x))
  where
    tupleToByteString :: Tuple (Maybe ByteString) (Trie64 ByteString ByteString) -> ByteString
    tupleToByteString (Tuple v y) = (maybeToByteString v) ++ (encodeByteString y)
Symbiote Test Suite Instance
Topic

String literal Topic used in the Symbiote Test Suite for this data type. Composed as Trie64 Int32 Int32.

"Trie64"