Skip to content

Commit a9166e8

Browse files
author
Mad Sheogorath
committed
Initial commit
0 parents  commit a9166e8

22 files changed

+2813
-0
lines changed

.gitignore

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# If you're building an application, you may want to check-in your pubspec.lock
2+
package-lock.json
3+
4+
# Miscellaneous
5+
*.class
6+
*.log
7+
*.pyc
8+
*.swp
9+
.DS_Store
10+
.svn/
11+
12+
# IntelliJ related
13+
.idea/
14+
15+
# Node.JS related
16+
**/doc/api/
17+
node_modules/
18+
build/

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
## v1.0.0
2+
3+
* Enums and Types can be referenced from another manifest files.
4+
* Enum declaration implemented.
5+
* Type (nested object) declaration implemented.
6+
* Single message or request and response messages declaration implemented.
7+
* $response method for request messages implemented.
8+
* Example provided.
9+

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Mad Sheogorath
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
## What is PackMe
2+
PackMe is a lightweight library for packing your data into binary buffer (presumably in order to be sent over tcp connection) and unpacking it back to class objects described in a simple way via JSON manifest files.
3+
4+
## It is Fast
5+
Spoiler alert! ~500k pack/unpack cycles per second for data of average size and complexity. Of course it depends on system configuration :)
6+
7+
Since PackMe generates .dart classes, there is no need for any resource demanding serialization/deserialization process. No intermediate steps involved, every class has it's own efficient methods to quickly put all data to Uint8List buffer and extract it. Comparing to popular solutions it's performance is similar to FlatBuffers and greatly outperforms Proto Buffers.
8+
9+
## It is Simple
10+
No special file formats (like for FlatBuffers or Proto Buffers manifest files), just use JSON. Objects, types and messages declarations are very simple and intuitive.
11+
12+
## Usage
13+
The best way of using it for client-server applications is by using ConnectMe package which provides all necessary stuff like adding message listeners, calling asynchronous queries etc. But you can use it separately as well.
14+
15+
Here's a simple manifest.json file (located in packme directory) for some hypothetical client-server application:
16+
```json
17+
{
18+
"get_user": [
19+
{
20+
"id": "string"
21+
},
22+
{
23+
"first_name": "string",
24+
"last_name": "string",
25+
"age": "uint8"
26+
}
27+
]
28+
}
29+
```
30+
Generate dart files:
31+
```bash
32+
node compile.js packme generated
33+
```
34+
Using on client side:
35+
```dart
36+
import 'generated/manifest.generated.js';
37+
import 'package:packme/packme.dart';
38+
39+
...
40+
41+
PackMe packMe = PackMe();
42+
packMe.register(manifestMessageFactory); // Required by PackMe to create class instances while unpacking messages
43+
44+
GetUserRequest request = GetUserRequest(id: 'a7db84cc2ef5012a6498bc64334ffa7d');
45+
socket.send(packMe.pack(request)); // Some socket implementation
46+
47+
socket.listen((Uint8List data) {
48+
final PackMeMessage? message = packMe.unpack(data);
49+
if (message is GetUserResponse) {
50+
print('He is awesome: ${message.firstName} ${message.lastName}, ${message.age} y.o.');
51+
}
52+
});
53+
```
54+
Using on server side:
55+
```dart
56+
import 'generated/manifest.generated.dart';
57+
import 'package:packme/packme.dart';
58+
59+
...
60+
61+
PackMe packMe = PackMe();
62+
packMe.register(manifestMessageFactory); // Required by PackMe to create class instances while unpacking messages
63+
64+
server.listen((Uint8List data, SomeSocket socket) { // Some server implementation
65+
final PackMeMessage? message = packMe.unpack(data);
66+
if (message is GetUserRequest) {
67+
GetUserResponse response = GetUserResponse(
68+
firstName: 'Peter',
69+
lastName: 'Hollens',
70+
age: '39'
71+
);
72+
socket.send(packMe.pack(response));
73+
}
74+
});
75+
```
76+
77+
## Supported platforms
78+
Now it's only for Dart. Will it be cross platform? Well it depends... If developers will find this package useful then it will be implemented for JavaScript and C++ I guess.

example/example-posts.json

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
"get_all": [
3+
{},
4+
{
5+
"posts": [{
6+
"id": ["uint8"],
7+
"author": {
8+
"id": ["uint8"],
9+
"nickname": "string",
10+
"avatar": "string"
11+
},
12+
"title": "string",
13+
"short_content": "string",
14+
"posted": "datetime"
15+
}]
16+
}
17+
],
18+
"get": [
19+
{
20+
"post_id": ["uint8"]
21+
},
22+
{
23+
"title": "string",
24+
"content": "string",
25+
"posted": "datetime",
26+
"author": {
27+
"id": ["uint8"],
28+
"nickname": "string",
29+
"avatar": "string",
30+
"?facebook_id": "string",
31+
"?twitter_id": "string",
32+
"?instagram_id": "string"
33+
},
34+
"stats": {
35+
"likes": "uint32",
36+
"dislikes": "uint32"
37+
},
38+
"comments": [{
39+
"author": {
40+
"id": ["uint8"],
41+
"nickname": "string",
42+
"avatar": "string"
43+
},
44+
"comment": "string",
45+
"posted": "datetime"
46+
}]
47+
}
48+
],
49+
"delete": [
50+
{
51+
"post_id": ["uint8"]
52+
},
53+
{
54+
"?error": "string"
55+
}
56+
]
57+
}

example/example-users.json

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
{
2+
"get_all": [
3+
{},
4+
{
5+
"users": [{
6+
"id": ["uint8"],
7+
"nickname": "string",
8+
"?first_name": "string",
9+
"?last_name": "string",
10+
"?age": "uint8"
11+
}]
12+
}
13+
],
14+
"get": [
15+
{
16+
"user_id": ["uint8"]
17+
},
18+
{
19+
"email": "string",
20+
"nickname": "string",
21+
"hidden": "bool",
22+
"created": "datetime",
23+
"info": {
24+
"?first_name": "string",
25+
"?last_name": "string",
26+
"?male": "uint8",
27+
"?age": "uint8",
28+
"?birth_date": "datetime"
29+
},
30+
"social": {
31+
"?facebook_id": "string",
32+
"?twitter_id": "string",
33+
"?instagram_id": "string"
34+
},
35+
"stats": {
36+
"posts": "uint32",
37+
"comments": "uint32",
38+
"likes": "uint32",
39+
"dislikes": "uint32",
40+
"rating": "float"
41+
},
42+
"?last_active": {
43+
"datetime": "datetime",
44+
"ip": "string"
45+
},
46+
"sessions": [{
47+
"created": "datetime",
48+
"ip": "string",
49+
"active": "bool"
50+
}]
51+
}
52+
],
53+
"delete": [
54+
{
55+
"user_id": ["uint8"]
56+
},
57+
{
58+
"?error": "string"
59+
}
60+
],
61+
"update_session": [
62+
{
63+
"user_id": ["uint8"],
64+
"session_id": "string"
65+
}
66+
]
67+
}

example/example.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"type_enum": [
3+
"one",
4+
"two",
5+
"four"
6+
],
7+
"nested_object": {
8+
"a": "uint8",
9+
"b": "string"
10+
},
11+
"test": [
12+
{
13+
"req_int8": "int8",
14+
"req_uint16": "uint16",
15+
"req_double": "double",
16+
"req_bool": "bool",
17+
"req_string": "string",
18+
"?opt_int8": "int8",
19+
"?opt_uint16": "uint16",
20+
"?opt_double": "double",
21+
"?opt_bool": "bool",
22+
"?opt_string": "string",
23+
"req_list": ["uint8"],
24+
"?opt_list": ["uint8"],
25+
"req_enum": "@type_enum",
26+
"?opt_enum": "@type_enum",
27+
"req_nested": "@nested_object",
28+
"?opt_nested": "@nested_object"
29+
}
30+
]
31+
}

0 commit comments

Comments
 (0)