-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: imrpoves serialization, splitting out a utility namespace, and …
…making it simple to serialize classes and nodes
- Loading branch information
1 parent
0558e18
commit 1e50081
Showing
13 changed files
with
645 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
--- | ||
priority: 0 | ||
priority: 1 | ||
title: mc.tasks (maestro task utils) | ||
--- | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
--- | ||
priority: 3 | ||
title: mc.utils.Collections | ||
--- | ||
|
||
# Overview | ||
|
||
Maestro contains utility functions to aid with working with collections, and node wrappers for certain types of common collections. | ||
|
||
## Functions | ||
|
||
### mapArray | ||
|
||
Takes a raw array, and runs it through the mc.Collections.BaseMapper subclass (i.e. CallFuncMapper, FuncMapper, FieldMapper, your own Mapper), returning the result. | ||
|
||
## getSortedArrayByKey | ||
|
||
Sorts the given array by key name. | ||
|
||
## getItemAtOffset | ||
|
||
Ascertains the index of the given item, in the passed in array, and returns whatever item is found offset from that index. By default, will use `id` field to compare objects; but the key can be specified. | ||
|
||
## getArrayIndex | ||
|
||
Ascertains the index of the given item, in the passed in array. By default, will use `id` field to compare objects; but the key can be specified. | ||
|
||
## filterArray | ||
|
||
Returns the filtered array using a filterPredicate. The filterPredicate can be either a function (taking one item as the argument), or a mc.Collections.AbstractPredicate subclass (i.e. ValuePredicate, FuncPredicate, CallFuncPredicate, or your own predicate) | ||
|
||
## arrayContains | ||
|
||
Returns true if the array contains the passed in value. By default, will use `id` field to compare objects; but the key can be specified. | ||
|
||
# Wrapped types | ||
|
||
Associative arrays and arrays are copied whenever they are assigned to nodes. This can be expensive computationally, and undesirable. Maestro offers a solution to this with the following nodes: | ||
|
||
- mc_Map - a node wrapper for AssociativeArray | ||
- mc_Array - a node wrapper for Array | ||
|
||
## mc_Map | ||
|
||
Has the following api | ||
- clear() | ||
- remove(key) | ||
- set(key, value) | ||
- append({}) - appends a dictionary | ||
- get(key) | ||
- hasKey(key) | ||
- getValues() - returns a raw dictionary copy | ||
|
||
### Serialization support | ||
|
||
The mc_Map supports maestro serialization, and can therefore be used in the registry's `writeSerializable` and `readSerializable` as well as `mc.utils.Serializable` methods. | ||
|
||
### Debugging | ||
|
||
You can see the stored values of the collection in RALE by checking the `_debug` value, which will dump the current values to the `__contents` field | ||
|
||
## mc_Array | ||
|
||
Has the following api | ||
- clear() | ||
- remove(item) | ||
- push(item) | ||
- append([]) - appends an array | ||
- get(index) | ||
- getIndex(item, key = invalid) - gets index of item, the string key can be used to direct the comparison | ||
- hasItem(index, key = invalid) - returns true if the item is present, the string key can be used to direct the comparison | ||
- getValues() - returns a raw array copy | ||
|
||
### Serialization support | ||
|
||
The mc_Array supports maestro serialization, and can therefore be used in the registry's `writeSerializable` and `readSerializable` as well as `mc.utils.Serializable` methods. | ||
|
||
### Debugging | ||
|
||
You can see the stored values of the collection in RALE by checking the `_debug` value, which will dump the current values to the `__contents` field |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
--- | ||
priority: 2 | ||
title: mc.utils.Serialization | ||
--- | ||
|
||
# Overview | ||
|
||
Maestro supports serialization apis to make it easy to write objects to registry, or to json for other purposes. | ||
|
||
Objects that can be serialized are classes, or nodes, which implement the Serializable interface | ||
|
||
## Implementing serialization | ||
|
||
Your node or class must adhere to the Serializable interface | ||
|
||
- have isSerializable field set to true | ||
- have public functions (i.e. for nodes, a func interface) for: | ||
- public function serialize() as mc.types.assocarray - returns an aa of the values to serialize the node | ||
- public function deserialize(data as mc.types.assocarray) - takes the values in data, and assigns them to itself | ||
|
||
## Serializing and Deserializing | ||
|
||
### Using mc.utils.Serialization | ||
|
||
#### Serializing | ||
|
||
Objects are serialized with: | ||
|
||
`mc.utils.Serialization.serialize(serializable as object) as mc.types.assocarray` | ||
|
||
Which returns an associative array, if successful, invalid otherwise | ||
If the passed in object is a node, then the field `_serializationType` with the type of the node will be appended to the serialized data | ||
|
||
#### Deserializing | ||
|
||
Objects can be deserialized with: | ||
`mc.utils.Serialization.deSerialize(data as mc.types.assocarray, serializable = invalid as object) as object` | ||
|
||
note, one can pass in a target serializable object to serialize into. If an object is not passed in the function will assume that the serialize object is node, and will use the `data._serializationType` to create an instance of that node, and serialize it. | ||
|
||
#### Checking if an object can be deserialized | ||
`mc.utils.Serialization.isSerializable(item as object) as boolean` | ||
|
||
|
||
### Using mc.Registry | ||
|
||
You can easily work with serializable objects by using the registry functions: | ||
|
||
- `readSerializable(section as string, key as string, serializable as object) as boolean` | ||
- if the data was successfully read from the registry, returns the serialized object. A target serializable can be passed in to receive the data. | ||
- `writeSerializable(section as string, key as string, serializable as object) as boolean` | ||
- returns true if the object was successfully deserialized and written to the registry |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
namespace tests | ||
|
||
@nocatch | ||
@suite("JsonCombinerTests") | ||
class JsonCombinerTests extends rooibos.BaseTestSuite | ||
|
||
|
Oops, something went wrong.