Skip to content

Commit d601072

Browse files
committed
Split the tokenizer into a validator and tokenizer.
The main benefit is reduced memory allocations, as we now count the tokens during the validation step and then work off of a flat array without nesting children. I have also slightly loosened the coupling between tokenizer and deserializer. Lastly there has been some housekeeping with naming and file locations.
1 parent dd3763a commit d601072

15 files changed

+554
-315
lines changed

PhpSerializerNET.Test/Deserialize/ArrayDeserialization.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ public void ExplicitToStructWrongField() {
160160
public void ExplicitToList() {
161161
var result = PhpSerialization.Deserialize<List<string>>("a:3:{i:0;s:5:\"Hello\";i:1;s:5:\"World\";i:2;i:12345;}");
162162

163+
Assert.AreEqual(3, result.Count);
163164
CollectionAssert.AreEqual(new List<string>() { "Hello", "World", "12345" }, result);
164165
}
165166

PhpSerializerNET.Test/Deserialize/Options/EmptyStringToDefault.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public void Enabled_StringArrayToIntList() {
164164

165165
[TestMethod]
166166
public void Enabled_StringArrayToNullableIntList() {
167-
var result = PhpSerialization.Deserialize<List<int?>>("a:1:{i:0;s:0:\"\";}");
167+
var result = PhpSerialization.Deserialize<List<int?>>("a:1:{i:1;s:0:\"\";}");
168168
CollectionAssert.AreEqual(new List<int?> { default }, result);
169169
}
170170

PhpSerializerNET.Test/Deserialize/Options/UseLists.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public void Option_Default_NonConsequetive() {
5252
}
5353
);
5454

55+
Assert.AreEqual(typeof (Dictionary<object, object>), result.GetType());
5556
var dictionary = result as Dictionary<object, object>;
5657
Assert.IsNotNull(dictionary);
5758
Assert.AreEqual(2, dictionary.Count);
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
This Source Code Form is subject to the terms of the Mozilla Public
3+
License, v. 2.0. If a copy of the MPL was not distributed with this
4+
file, You can obtain one at http://mozilla.org/MPL/2.0/.
5+
**/
6+
7+
namespace PhpSerializerNET;
8+
9+
/// <summary>
10+
/// PHP data types that can be de/serialized.
11+
/// </summary>
12+
internal enum PhpDataType : byte {
13+
/// <summary>
14+
/// Null (N;)
15+
/// </summary>
16+
Null,
17+
/// <summary>
18+
/// Boolean value (b:n;)
19+
/// </summary>
20+
Boolean,
21+
/// <summary>
22+
/// Integer value (i:[value];)
23+
/// </summary>
24+
Integer,
25+
/// <summary>
26+
/// Floating point number (f:[value];)
27+
/// </summary>
28+
Floating,
29+
/// <summary>
30+
/// String (s:[length]:"[value]")
31+
/// </summary>
32+
String,
33+
/// <summary>
34+
/// Array (a:[length]:{[children]})
35+
/// </summary>
36+
Array,
37+
/// <summary>
38+
/// Object (O:[identLength]:"[ident]":[length]:{[children]})
39+
/// </summary>
40+
Object
41+
}
42+

0 commit comments

Comments
 (0)