-
Notifications
You must be signed in to change notification settings - Fork 29
/
define_marshal_doc.yaml
88 lines (77 loc) · 2.34 KB
/
define_marshal_doc.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
- DocumentID: Marshal
Title: >-
`Marshal()` (type)
CategoryID: apis
Summary: >-
Converts structured memory into a structured file format (eg for stdio)
Description: |-
This is a function you would write when programming a Murex data-type.
The marshal function takes in a Go (golang) `type` or `struct` and returns
a byte slice of a "string" representation of that format (eg in JSON) or an
error.
This marshaller is then registered to Murex inside an `init()` function
and Murex builtins can use that marshaller via the `MarshalData()` API.
Usage: |-
Registering `Marshal()` (for writing builtin data-types)
```go
// To avoid data races, this should only happen inside func init()
lang.Marshallers[ /* your type name */ ] = /* your readIndex func */
```
Using an existing marshaller (eg inside a builtin command)
```go
// See documentation on lang.MarshalData for more details
b, err := lang.MarshalData(p, dataType, data)
```
Examples: |-
Defining a marshaller for a murex data-type
```go
{{ include "builtins/types/example/marshal.go" }}
```
Detail:
Parameters:
- "`*lang.Process`: Process's runtime state. Typically expressed as the variable `p` "
- "`interface{}`: data you wish to marshal"
Related:
- lang.MarshalData
- lang.UnmarshalData
- Unmarshal
- DocumentID: lang.MarshalData
Title: >-
`lang.MarshalData()` (system API)
CategoryID: apis
Summary: >-
Converts structured memory into a Murex data-type (eg for stdio)
Description:
Usage: |-
```go
b, err := lang.MarshalData(p, dataType, data)
```
Examples: |-
```go
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:
```go
{{ include "lang/define_marshal.go" }}
```
Parameters:
- "`*lang.Process`: Process's runtime state. Typically expressed as the variable `p` "
- "`string`: Murex data type"
- "`interface{}`: data you wish to marshal"
Related:
- Marshal
- lang.UnmarshalData
- Unmarshal