lang.MarshalData()
(system API)Converts structured memory into a Murex data-type (eg for stdio)
b, err := lang.MarshalData(p, dataType, data)
func exampleCommand(p *lang.Process) error {
map[string]string {
data := "foo": "hello foo",
"bar": "hello bar",
}
"json"
dataType :=
b, err := lang.MarshalData(p, dataType, data)if err != nil {
return err
}
_, err := p.Stdout.Write(b)return err
}
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{}) ([]byte, 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 b, nil
}
*lang.Process
: Process’s runtime state. Typically expressed as the variable p
string
: Murex data typeinterface{}
: data you wish to marshalMarshal()
(type): Converts structured memory into a structured file format (eg for stdio)Unmarshal()
(type): Converts a structured file format into structured memorylang.UnmarshalData()
(system API): Converts a Murex data-type into structured memoryThis document was generated from lang/define_marshal_doc.yaml.
This site's content is rebuilt automatically from murex's source code after each merge to the master
branch. Downloadable murex binaries are also built with the website.
Last built on Wed Sep 18 21:18:57 UTC 2024 against commit c037883c03788357164e9846c84d9f777251495d9452a8e.
Current version is 6.3.4225 (develop) which has been verified against tests cases.