-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lint: use double quotes in all imports
- Loading branch information
Showing
4 changed files
with
49 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export "src/serializers/cbor.dart" show CBORSerializer; | ||
export "src/serializers/json.dart" show JsonSerializer; |
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,23 @@ | ||
import "dart:typed_data"; | ||
|
||
import "package:cbor/simple.dart"; | ||
import "package:wampproto/src/messages/message.dart"; | ||
import "package:wampproto/src/serializers/serializer.dart"; | ||
|
||
class CBORSerializer implements Serializer { | ||
@override | ||
Uint8List serialize(Message message) { | ||
final encoded = cbor.encode(message.marshal()); | ||
return Uint8List.fromList(encoded); | ||
} | ||
|
||
@override | ||
Message deserialize(Uint8List message) { | ||
final decoded = cbor.decode(message); | ||
if (decoded is! List) { | ||
throw "bad type"; | ||
} | ||
|
||
return toMessage(decoded); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import "package:test/test.dart"; | ||
import "package:wampproto/messages.dart"; | ||
import "package:wampproto/serializers.dart"; | ||
|
||
void main() { | ||
test("test serialize and deserialize", testCBOR); | ||
} | ||
|
||
void testCBOR() { | ||
var hello = Hello.parse([1, "realm1"]); | ||
|
||
var serializer = CBORSerializer(); | ||
var data = serializer.serialize(hello); | ||
|
||
var obj = serializer.deserialize(data); | ||
if (obj.messageType() != 1) { | ||
fail("message"); | ||
} | ||
|
||
var deserialized = obj as Hello; | ||
|
||
expect(hello.realm, deserialized.realm); | ||
expect(hello.messageType(), deserialized.messageType()); | ||
} |