- DocumentID: Marshal
  Title: >-
    `Marshal()` (type)
  CategoryID: apis
  Summary: >-
    Converts structured memory into a structured file format (eg for stdio)
  Description: |-
    This is a function you would write when programming a Murex data-type.
    The marshal function takes in a Go (golang) `type` or `struct` and returns
    a byte slice of a "string" representation of that format (eg in JSON) or an
    error.

    This marshaller is then registered to Murex inside an `init()` function
    and Murex builtins can use that marshaller via the `MarshalData()` API.
  Usage: |-
    Registering `Marshal()` (for writing builtin data-types)
    
    ```go
    // To avoid data races, this should only happen inside func init()
    lang.Marshallers[ /* your type name */ ] = /* your readIndex func */
    ```

    Using an existing marshaller (eg inside a builtin command)

    ```go
    // See documentation on lang.MarshalData for more details
    b, err := lang.MarshalData(p, dataType, data)
    ```
  Examples: |-
    Defining a marshaller for a murex data-type

    ```go
    {{ include "builtins/types/example/marshal.go" }}
    ```
  Detail:
  Parameters:
  - "`*lang.Process`: Process's runtime state. Typically expressed as the variable `p` "
  - "`interface{}`: data you wish to marshal"
  Related:
  - lang.MarshalData
  - lang.UnmarshalData
  - Unmarshal


- DocumentID: lang.MarshalData
  Title: >-
    `lang.MarshalData()` (system API)
  CategoryID: apis
  Summary: >-
    Converts structured memory into a Murex data-type (eg for stdio)
  Description:
  Usage: |-
    ```go
    b, err := lang.MarshalData(p, dataType, data)
    ```
  Examples: |-
    ```go
    func exampleCommand(p *lang.Process) error {
        data := map[string]string {
            "foo": "hello foo",
            "bar": "hello bar",
        }

        dataType := "json"

        b, err := lang.MarshalData(p, dataType, data)
        if err != nil {
            return err
        }

        _, err := p.Stdout.Write(b)
        return err
    }
    ```
  Detail: |-
    Go source file:
    
    ```go
    {{ include "lang/define_marshal.go" }}
    ```
  Parameters:
  - "`*lang.Process`: Process's runtime state. Typically expressed as the variable `p` "
  - "`string`: Murex data type" 
  - "`interface{}`: data you wish to marshal"
  Related:
  - Marshal
  - lang.UnmarshalData
  - Unmarshal