lang.MarshalData()
(system API)Converts structured memory into a Murex data-type (eg for stdio)
, err := lang.MarshalData(p, dataType, data) b
func exampleCommand(p *lang.Process) error {
:= map[string]string {
data "foo": "hello foo",
"bar": "hello bar",
}
:= "json"
dataType
, err := lang.MarshalData(p, dataType, data)
bif err != nil {
return err
}
, err := p.Stdout.Write(b)
_return err
}
Go source file:
package lang
import (
"errors"
"fmt"
)
// type DeMetaT func(any) error
type MarshallerT func(*Process, any) ([]byte, error)
var (
//_demetaers = make(map[string]DeMetaT)
// _marshallers defines the Go functions for converting a Go interface into a murex data type
= make(map[string]MarshallerT)
_marshallers )
/*func RegisterDeMetaer(dataType string, demetaer DeMetaT) {
if _demetaers[dataType] != nil {
panic(fmt.Sprintf("premarshaller already exists for %s", dataType))
}
_demetaers[dataType] = demetaer
}
func DeMetaData(dataType string, data any) error {
if _demetaers[dataType] == nil {
return nil // we shouldn't assume there is a demetaer
}
return _demetaers[dataType](data)
}*/
func RegisterMarshaller(dataType string, marshaller MarshallerT) {
if _marshallers[dataType] != nil {
panic(fmt.Sprintf("marshaller already exists for %s", dataType))
}
[dataType] = marshaller
_marshallers}
// 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 any) ([]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 + "`.")
}
, err := _marshallers[dataType](p, data)
bif 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 Jul 2 22:12:32 UTC 2025 against commit bb72b6fbb72b6fdd502f835172d7d06207ba4ec2c70886c.
Current version is 7.0.2107 (develop) which has been verified against tests cases.