You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Serializer call includes two `static` methods that allow you serialize (nearly) any Squirrel object into a blob, and deserialize perviously serialized objects. This is particulairly useful if you're planning to store information with [hardware.spiflash](https://electricimp.com/docs/api/hardware/spiflash) or the with the [SPIFlash Library](https://github.com/electricimp/spiflash/tree/v1.0.0).
3
+
The Serializer call includes two `static` methods that allow you serialize (nearly) any Squirrel object into a blob, and deserialize perviously serialized objects. This is particulairly useful if you're planning to store information with [hardware.spiflash](https://developer.electricimp.com/api/hardware/spiflash) or the with the [SPIFlash Library](https://github.com/electricimp/spiflash/tree/v1.0.0).
4
4
5
-
*NOTE:* The *Serializer* class only uses `static` methods, and as a result does not to be initialized through a constructor.
5
+
*Note* The *Serializer* class only uses `static` methods, and as a result does not to be initialized through a constructor.
6
6
7
-
**To add this library to your project, add `#require "Serializer.class.nut:1.0.0"`` to the top of your device code.**
7
+
**To add this library to your project, add**`#require "Serializer.class.nut:1.0.0"`**to the top of your device code.**
8
8
9
-
You can view the library’s source code on [GitHub](https://github.com/electricimp/serializer/tree/v1.0.0).
10
-
11
-
## Serializable Squirrel
9
+
## Serializable Squirrel ##
12
10
13
11
The Serializer class currently supports the following types:
The Serializer cannot serialize the following types:
@@ -27,6 +25,10 @@ The Serializer cannot serialize the following types:
27
25
-`instance` - Class instances.
28
26
-`meta` - Meta objects such as *device* and *hardware*.
29
27
28
+
## Development ##
29
+
30
+
This repository uses [git-flow](http://jeffkreeftmeijer.com/2010/why-arent-you-using-git-flow/). Please make your pull requests to the **develop** branch.
31
+
30
32
## Class Methods
31
33
32
34
### Serializer.serialize(*obj, [prefix]*)
@@ -37,13 +39,13 @@ The *Serializer.serialize* method allows you to transform an arbitrary Squirrel
The *Serializer.deserialize* method will deserialize a blob that was previous serialized with the *Serializer.serialize* method. If the blob was serialized with a *prefix*, the same *prefix* must be passed into the *Serializer.deserialize* method.
71
73
72
74
```squirrel
73
-
# require "Serializer.class.nut:1.0.0"
74
-
75
75
// Setup SpiFlash object
76
76
// ...
77
-
78
77
spiFlash.enable();
79
78
80
79
// Read the header information
81
80
local dataBlob = spiFlash.read(0x00, 3);
81
+
82
82
// Get the length from the first two bytes
83
83
local len = dataBlob.readn('w');
84
84
@@ -94,46 +94,36 @@ spiFlash.disable();
94
94
// Deserialize the blob
95
95
local data = Serializer.deserialize(dataBlob);
96
96
97
-
98
-
99
97
// Log some data to make sure it worked:
100
98
server.log(data.foo); // bar
101
99
server.log(data.otherData.state); // true
102
100
server.log(data.otherData.test); // test
103
101
104
102
server.log("Readings:");
105
103
for(local i = 0; i < data.timestamps.len(); i++) {
The *Serializer* class needs to add a variety of metadata to Serialized objects in order to properly know how to deserialize the blobs. The *Serializer.sizeof* method can be used to quickly determin the size of an object after serialization.
0 commit comments