lang.UnmarshalData()
(system API)Converts a Murex data-type into structured memory
, err := lang.UnmarshalData(p, dataType) data
func exampleCommand(p *lang.Process) error {
:= string `{ "foo": "hello foo", "bar": "hello bar" }`
data
:= "json"
dataType
, err := lang.UnmarshalData(p, dataType)
vif err != nil {
return err
}
:= fmt.Sprint(v)
s , err := p.Stdout.Write([]byte(s))
_return err
}
Go source file:
package lang
import (
"fmt"
)
type UnmarshallerT func(*Process) (any, error)
var (
// _unmarshallers defines the Go functions for converting a murex data type into a Go interface
= make(map[string]UnmarshallerT)
_unmarshallers )
func RegisterUnmarshaller(dataType string, unmarshaller UnmarshallerT) {
if _unmarshallers[dataType] != nil {
panic(fmt.Sprintf("unmarshaller already exists for %s", dataType))
}
[dataType] = unmarshaller
_unmarshallers}
// UnmarshalData is a global unmarshaller which should be called from within
// murex builtin commands (etc).
// See docs/apis/marshaldata.html for more details
func UnmarshalData(p *Process, dataType string) (v any, 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 _unmarshallers[dataType] == nil {
return nil, fmt.Errorf("unknown data type. I don't know how to unmarshal `%s`", dataType)
}
, err = _unmarshallers[dataType](p)
vif err != nil {
return nil, fmt.Errorf("[%s unmarshaller] %s", dataType, err.Error())
}
return v, nil
}
func UnmarshalDataBuffered(parent *Process, b []byte, dataType string) (interface{}, error) {
:= parent.Fork(F_BACKGROUND | F_CREATE_STDIN | F_NO_STDOUT | F_NO_STDERR)
fork defer fork.Kill()
, err := fork.Stdin.Write(b)
_defer fork.Stdin.Close()
if err != nil {
return nil, fmt.Errorf("cannot write value to unmarshaller's buffer: %s", err.Error())
}
, err := UnmarshalData(fork.Process, dataType)
vif err != nil {
return nil, fmt.Errorf("cannot unmarshal buffer: %s", err.Error())
}
return v, nil
}
*lang.Process
: Process’s runtime state. Typically
expressed as the variable p
string
: Murex data typeMarshal()
(type):
Converts structured memory into a structured file format (eg for
stdio)Unmarshal()
(type): Converts a structured file format into structured
memorylang.MarshalData()
(system API): Converts structured memory into a Murex data-type (eg
for stdio)This document was generated from lang/define_unmarshal_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 Sat Aug 23 22:28:13 UTC 2025 against commit ad23f13ad23f131bfecd82ea8a12d9b3e92aab5d8398ae9.
Current version is 7.0.2129 (website) which has been verified against tests cases.