-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
related to #12 Adds the deserialize proc overload that accepts mutable object to fill with deserialized content. If the deserialization was not complete (due to lack of data in the stream) the part of the object passed for which data has not obtained will be left untouched
- Loading branch information
Showing
4 changed files
with
136 additions
and
38 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
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,55 @@ | ||
import unittest | ||
from nesm import serializable | ||
from streams import setPosition | ||
import helpers/rnw | ||
|
||
|
||
suite "Default values tests": | ||
test "Basic": | ||
serializable: | ||
type | ||
IncompleteObj = object | ||
a: int32 | ||
SimpleObj = object | ||
a: int32 | ||
b: int32 | ||
let rnw = get_reader_n_writer() | ||
let aval = rand(1000).int32 | ||
let bval = rand(1001..2000).int32 | ||
let x = IncompleteObj(a: aval) | ||
x.serialize(rnw) | ||
rnw.setPosition(0) | ||
var y = SimpleObj(a: rand(2001..3000).int32, b: bval) | ||
try: | ||
y.deserialize(rnw) | ||
except: | ||
discard | ||
check(aval == y.a) | ||
check(bval == y.b) | ||
|
||
test "Seq": | ||
serializable: | ||
type | ||
IncompleteSeqObj = object | ||
a: int32 | ||
b: int32 | ||
c: int32 | ||
SeqObj = object | ||
a: int32 | ||
b: seq[int32] | ||
let rnw = get_reader_n_writer() | ||
let aval = rand(1001..2000).int32 | ||
let bval = random_seq_with(int32(rand(1000))) | ||
let cval = rand(4001..5000).int32 | ||
let x = IncompleteSeqObj(a: aval, b: bval.len.int32, | ||
c: cval) | ||
x.serialize(rnw) | ||
rnw.setPosition(0) | ||
var y = SeqObj(a: rand(2001..3000).int32, b: bval) | ||
try: | ||
y.deserialize(rnw) | ||
except: | ||
discard | ||
check(aval == y.a) | ||
require(bval.len == y.b.len) | ||
check(cval == y.b[0]) |
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