-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #157 from agocke/fix-type-wrap
Fix type wrapping order
- Loading branch information
Showing
6 changed files
with
176 additions
and
0 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
78 changes: 78 additions & 0 deletions
78
...n.Test/test_output/DeserializeTests/NestedPartialClasses#A.B.C.D.IDeserialize.verified.cs
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,78 @@ | ||
//HintName: A.B.C.D.IDeserialize.cs | ||
|
||
#nullable enable | ||
using System; | ||
using Serde; | ||
|
||
partial class A | ||
{ | ||
partial class B | ||
{ | ||
partial class C | ||
{ | ||
partial class D : Serde.IDeserialize<A.B.C.D> | ||
{ | ||
static A.B.C.D Serde.IDeserialize<A.B.C.D>.Deserialize<D>(ref D deserializer) | ||
{ | ||
var visitor = new SerdeVisitor(); | ||
var fieldNames = new[] | ||
{ | ||
"Field" | ||
}; | ||
return deserializer.DeserializeType<A.B.C.D, SerdeVisitor>("D", fieldNames, visitor); | ||
} | ||
|
||
private sealed class SerdeVisitor : Serde.IDeserializeVisitor<A.B.C.D> | ||
{ | ||
public string ExpectedTypeName => "A.B.C.D"; | ||
|
||
private struct FieldNameVisitor : Serde.IDeserialize<byte>, Serde.IDeserializeVisitor<byte> | ||
{ | ||
public static byte Deserialize<D>(ref D deserializer) | ||
where D : IDeserializer => deserializer.DeserializeString<byte, FieldNameVisitor>(new FieldNameVisitor()); | ||
public string ExpectedTypeName => "string"; | ||
|
||
byte Serde.IDeserializeVisitor<byte>.VisitString(string s) => VisitUtf8Span(System.Text.Encoding.UTF8.GetBytes(s)); | ||
public byte VisitUtf8Span(System.ReadOnlySpan<byte> s) | ||
{ | ||
switch (s[0]) | ||
{ | ||
case (byte)'f'when s.SequenceEqual("field"u8): | ||
return 1; | ||
default: | ||
return 0; | ||
} | ||
} | ||
} | ||
|
||
A.B.C.D Serde.IDeserializeVisitor<A.B.C.D>.VisitDictionary<D>(ref D d) | ||
{ | ||
int _l_field = default !; | ||
byte _r_assignedValid = 0b0; | ||
while (d.TryGetNextKey<byte, FieldNameVisitor>(out byte key)) | ||
{ | ||
switch (key) | ||
{ | ||
case 1: | ||
_l_field = d.GetNextValue<int, Int32Wrap>(); | ||
_r_assignedValid |= ((byte)1) << 0; | ||
break; | ||
} | ||
} | ||
|
||
if (_r_assignedValid != 0b1) | ||
{ | ||
throw new Serde.InvalidDeserializeValueException("Not all members were assigned"); | ||
} | ||
|
||
var newType = new A.B.C.D() | ||
{ | ||
Field = _l_field, | ||
}; | ||
return newType; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...ation.Test/test_output/SerializeTests/NestedPartialClasses#A.B.C.D.ISerialize.verified.cs
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 @@ | ||
//HintName: A.B.C.D.ISerialize.cs | ||
|
||
#nullable enable | ||
using System; | ||
using Serde; | ||
|
||
partial class A | ||
{ | ||
partial class B | ||
{ | ||
partial class C | ||
{ | ||
partial class D : Serde.ISerialize | ||
{ | ||
void Serde.ISerialize.Serialize(ISerializer serializer) | ||
{ | ||
var type = serializer.SerializeType("D", 1); | ||
type.SerializeField("field"u8, new Int32Wrap(this.Field)); | ||
type.End(); | ||
} | ||
} | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...ion.Test/test_output/SerializeTests/NestedPartialClasses#A.B.C.D.ISerialize`1.verified.cs
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 @@ | ||
//HintName: A.B.C.D.ISerialize`1.cs | ||
|
||
#nullable enable | ||
using System; | ||
using Serde; | ||
|
||
partial class A | ||
{ | ||
partial class B | ||
{ | ||
partial class C | ||
{ | ||
partial class D : Serde.ISerialize<A.B.C.D> | ||
{ | ||
void ISerialize<A.B.C.D>.Serialize(A.B.C.D value, ISerializer serializer) | ||
{ | ||
var type = serializer.SerializeType("D", 1); | ||
type.SerializeField<int, Int32Wrap>("field", value.Field); | ||
type.End(); | ||
} | ||
} | ||
} | ||
} | ||
} |