murex Shell Docs

API Reference: lang.MarshalData()

Converts structured memory into a murex data-type (eg for stdio)

Description

Usage

b, err := lang.MarshalData(p, dataType, data)

Examples

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:

package lang

import (
    "errors"
)

// MarshalData is a global marshaller which should be called from within murex
// builtin commands (etc).
// See docs/apis/marshaldata.html for more details
func MarshalData(p *Process, dataType string, data interface{}) (b []byte, err error) {
    // This is one of the very few maps in Murex which isn't hidden behind a sync
    // lock of one description or other. The rational is that even mutexes can
    // add a noticeable overhead on the performance of tight loops and I expect
    // this function to be called _a lot_ while also only needing to be written
    // to via code residing in within builtin types init() function (ie while
    // murex is effectively single threaded). So there shouldn't be any data-
    // races -- PROVIDING developers strictly follow the pattern of only writing
    // to this map within init() func's.
    if Marshallers[dataType] == nil {
        return nil, errors.New("I don't know how to marshal `" + dataType + "`.")
    }

    b, err = Marshallers[dataType](p, data)
    if err != nil {
        return nil, errors.New("[" + dataType + " marshaller] " + err.Error())
    }

    return
}

Parameters

  1. *lang.Process: Process's runtime state. Typically expressed as the variable p
  2. string: murex data type
  3. interface{}: data you wish to marshal

See Also

This site is rebuilt weekly, the content is automatically generated from murex's source code. Last built on Mon May 25 06:11:51 UTC 2020 against commit aa3f3b7aa3f3b7e471543754fdcaf910d4920cad9112b91. Downloadable murex binaries are also built weekly. Current version is 0.48.0120 BETA which has been verified against 29375 tests.