Skip to content
Anssi Halmeaho edited this page Jan 2, 2021 · 2 revisions

stdser

Implements FunL data serialization to format that can be stored or transmitted over network and also deserialization back to FunL data. JSON encoding/decoding does the same but it has limitations with maps converted to JSON objects as JSON objects require keys being strings.

Also opaque:bytearray is encoded as base64 encoded string.

Following types can be encode/decoded with stdser:

  • int
  • float
  • bool
  • string
  • list (containing items of these types)
  • map (values being one of these types)
  • opaque:bytearray

Encoding and decoding utilize JSON encoding and decoding at bottom. On top of JSON stdser converts data to/from to pairs of data (pairs being lists of two items):

  1. First item : type tag (string) ('int', 'float', 'bool', 'string', 'list', 'map', 'bytearray')
  2. Second item : value (which in list/map case contain more these pairs)

List value is presented list of pairs. Map value is presented as list of pairs:

  1. Key pair (2 item list)
    1. tag (string)
    2. value
  2. Value pair (2 item list)
    1. tag (string)
    2. value

Functions

encode

Encodes FunL values to bytearray (JSON underneath).

type: function

Format:

call(stdser.encode <value>) -> <list: is-ok error-description data-bytearray>

Return value: list

Returned list contains

  1. bool: true if encode succeeded, false otherwise
  2. error description (string), '' if succeeded
  3. target data as bytearray (stdbytes opaque type)

decode

Decodes bytearray data (JSON) to FunL value.

type: function

Format:

call(stdser.decode <data-bytearray>) -> <list: is-ok error-description value>

Return value: list

Returned list contains

  1. bool: true if encode succeeded, false otherwise
  2. error description (string), '' if succeeded
  3. decoded FunL value