ReadMap()
(type)Treat data type as a key/value structure and read its contents
This is a function you would write when programming a Murex data-type.
It’s called by builtins to allow them to read data structures one key/value pair at a time.
The purpose of this function is to allow builtins to support sequential reads (where possible) and also create a standard interface for builtins, thus allowing them to be data-type agnostic.
Registering your ReadMap()
// To avoid confusion, this should only happen inside func init()
/* your type name */, /* your readMap func */) stdio.RegisterReadMap(
Example ReadMap()
function:
package json
import (
"github.com/lmorg/murex/config"
"github.com/lmorg/murex/lang"
"github.com/lmorg/murex/lang/stdio"
"github.com/lmorg/murex/lang/types"
"github.com/lmorg/murex/utils/json"
)
func readMap(read stdio.Io, _ *config.Config, callback func(*stdio.Map)) error {
// Create a marshaller function to pass to ArrayWithTypeTemplate
func(v interface{}) ([]byte, error) {
marshaller := return json.Marshal(v, read.IsTTY())
}
return lang.MapTemplate(types.Json, marshaller, json.Unmarshal, read, callback)
}
There isn’t (yet) a template read function for types to call. However that might follow in a future release of Murex.
stdio.Io
: stream to read from (eg stdin)*config.Config
: scoped config (eg your data type might have configurable parsing rules)func(key, value string, last bool)
: callback function: key and value of map plus boolean which is true if last element in row (eg reading from tables rather than key/values)ReadArray()
(type): Read from a data type one array element at a timeReadArrayWithType()
(type): Read from a data type one array element at a time and return the elements contents and data typeReadIndex()
(type): Data type handler for the index, [
, builtinReadNotIndex()
(type): Data type handler for the bang-prefixed index, ![
, builtinWriteArray()
(type): Write a data type, one array element at a timeThis document was generated from lang/stdio/interface_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.