-
Notifications
You must be signed in to change notification settings - Fork 29
/
define_unmarshal_doc.yaml
84 lines (73 loc) · 2.2 KB
/
define_unmarshal_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
- DocumentID: Unmarshal
Title: >-
`Unmarshal()` (type)
CategoryID: apis
Summary: >-
Converts a structured file format into structured memory
Description: |-
This is a function you would write when programming a Murex data-type.
The unmarshal function takes in a byte slice and returns a Go (golang)
`type` or `struct` or an error.
This unmarshaller is then registered to Murex inside an `init()` function
and Murex builtins can use that unmarshaller via the `UnmarshalData()`
API.
Usage: |-
Registering `Unmarshal()` (for writing builtin data-types)
```go
// To avoid data races, this should only happen inside func init()
lang.Unmarshallers[ /* your type name */ ] = /* your readIndex func */
```
Using an existing unmarshaller (eg inside a builtin command)
```go
// See documentation on lang.UnmarshalData for more details
v, err := lang.UnmarshalData(p *lang.Process, dataType string)
```
Examples: |-
Defining a marshaller for a murex data-type
```go
{{ include "builtins/types/example/unmarshal.go" }}
```
Detail: |-
Parameters:
- "`*lang.Process`: Process's runtime state. Typically expressed as the variable `p` "
Related:
- lang.MarshalData
- lang.UnmarshalData
- Marshal
- DocumentID: lang.UnmarshalData
Title: >-
`lang.UnmarshalData()` (system API)
CategoryID: apis
Summary: >-
Converts a Murex data-type into structured memory
Description: |-
Usage: |-
```go
data, err := lang.UnmarshalData(p, dataType)
```
Examples: |-
```go
func exampleCommand(p *lang.Process) error {
data := string `{ "foo": "hello foo", "bar": "hello bar" }`
dataType := "json"
v, err := lang.UnmarshalData(p, dataType)
if err != nil {
return err
}
s := fmt.Sprint(v)
_, err := p.Stdout.Write([]byte(s))
return err
}
```
Detail: |-
Go source file:
```go
{{ include "lang/define_unmarshal.go" }}
```
Parameters:
- "`*lang.Process`: Process's runtime state. Typically expressed as the variable `p` "
- "`string`: Murex data type"
Related:
- Marshal
- lang.MarshalData
- Unmarshal