Skip to content

Commit 91d4029

Browse files
Update README.md
1 parent 1321ddd commit 91d4029

File tree

1 file changed

+36
-46
lines changed

1 file changed

+36
-46
lines changed

Diff for: README.md

+36-46
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
1-
# Serializer 1.0.0
1+
# Serializer #
22

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://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).
44

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.
66

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.**
88

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 ##
1210

1311
The Serializer class currently supports the following types:
1412

15-
- [arrays](https://electricimp.com/docs/squirrel/array/)
16-
- [blobs](https://electricimp.com/docs/squirrel/blob/)
17-
- [booleans](https://electricimp.com/docs/squirrel/bool/)
18-
- [floats](https://electricimp.com/docs/squirrel/float/)
19-
- [integers](https://electricimp.com/docs/squirrel/integer/)
20-
- [strings](https://electricimp.com/docs/squirrel/string/)
21-
- [tables](https://electricimp.com/docs/squirrel/table/)
13+
- [arrays](https://developer.electricimp.com/squirrel/array/)
14+
- [blobs](https://developer.electricimp.com/squirrel/blob/)
15+
- [booleans](https://developer.electricimp.com/squirrel/bool/)
16+
- [floats](https://developer.electricimp.com/squirrel/float/)
17+
- [integers](https://developer.electricimp.com/squirrel/integer/)
18+
- [strings](https://developer.electricimp.com/squirrel/string/)
19+
- [tables](https://developer.electricimp.com/squirrel/table/)
2220
- `null`
2321

2422
The Serializer cannot serialize the following types:
@@ -27,6 +25,10 @@ The Serializer cannot serialize the following types:
2725
- `instance` - Class instances.
2826
- `meta` - Meta objects such as *device* and *hardware*.
2927

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+
3032
## Class Methods
3133

3234
### Serializer.serialize(*obj, [prefix]*)
@@ -37,13 +39,13 @@ The *Serializer.serialize* method allows you to transform an arbitrary Squirrel
3739
# require "Serializer.class.nut:1.0.0"
3840
3941
local data = {
40-
"foo": "bar",
41-
"timestamps": [ 1436983175, 1436984975, 1436986775, 1436988575, 1436990375],
42-
"readings": [ 32.5, 33.6, 32.8, 32.9, 32.5 ],
43-
"otherData": {
44-
"state": true,
45-
"test": "test"
46-
}
42+
"foo": "bar",
43+
"timestamps": [ 1436983175, 1436984975, 1436986775, 1436988575, 1436990375],
44+
"readings": [ 32.5, 33.6, 32.8, 32.9, 32.5 ],
45+
"otherData": {
46+
"state": true,
47+
"test": "test"
48+
}
4749
}
4850
4951
local serializedData = Serializer.serialize(data);
@@ -63,22 +65,20 @@ If a *prefix* was passed to the method, the Serializer will write this data at t
6365
| 1 | The upper byte of the length |
6466
| 2 | The CRC byte |
6567

66-
**NOTE:** The 16-but length value does include the length of the prefix (if included) or the header data (3 bytes).
68+
**Note** The 16-bit length value does include the length of the prefix (if included) or the header data (3 bytes).
6769

68-
### Serializer.deserialize(*serializedBlob, [prefix]*)
70+
### Serializer.deserialize(*serializedBlob[, prefix]*)
6971

7072
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.
7173

7274
```squirrel
73-
# require "Serializer.class.nut:1.0.0"
74-
7575
// Setup SpiFlash object
7676
// ...
77-
7877
spiFlash.enable();
7978
8079
// Read the header information
8180
local dataBlob = spiFlash.read(0x00, 3);
81+
8282
// Get the length from the first two bytes
8383
local len = dataBlob.readn('w');
8484
@@ -94,46 +94,36 @@ spiFlash.disable();
9494
// Deserialize the blob
9595
local data = Serializer.deserialize(dataBlob);
9696
97-
98-
9997
// Log some data to make sure it worked:
10098
server.log(data.foo); // bar
10199
server.log(data.otherData.state); // true
102100
server.log(data.otherData.test); // test
103101
104102
server.log("Readings:");
105103
for(local i = 0; i < data.timestamps.len(); i++) {
106-
server.log(data.timestamps[i] + ": " + data.readings[i]);
104+
server.log(data.timestamps[i] + ": " + data.readings[i]);
107105
}
108-
109106
```
110107

111-
### Serializer.sizeof(obj)
108+
### Serializer.sizeof(*obj*) ###
112109

113110
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.
114111

115112
```squirrel
116-
# require "Serializer.class.nut:1.0.0"
117-
118113
local data = {
119-
"foo": "bar",
120-
"timestamps": [ 1436983175, 1436984975, 1436986775, 1436988575, 1436990375],
121-
"readings": [ 32.5, 33.6, 32.8, 32.9, 32.5 ],
122-
"otherData": {
123-
"state": true,
124-
"test": "test"
125-
}
114+
"foo": "bar",
115+
"timestamps": [ 1436983175, 1436984975, 1436986775, 1436988575, 1436990375],
116+
"readings": [ 32.5, 33.6, 32.8, 32.9, 32.5 ],
117+
"otherData": {
118+
"state": true,
119+
"test": "test"
120+
}
126121
}
127122
128123
// Check how large our blob will be before serializing
129124
server.log(Serializer.sizeof(data));
130125
```
131126

132-
# License
127+
## License ##
133128

134129
The Serializer class is licensed under [MIT License](https://github.com/electricimp/serializer/tree/master/LICENSE).
135-
136-
## Development
137-
138-
This repository uses [git-flow](http://jeffkreeftmeijer.com/2010/why-arent-you-using-git-flow/).
139-
Please make your pull requests to the __develop__ branch.

0 commit comments

Comments
 (0)