-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed some bugs around generating logic for reading/writing lists.
- Loading branch information
1 parent
69095e4
commit 01a61a9
Showing
26 changed files
with
467 additions
and
291 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
Schema Build Tests/attributes/sequence/RSequenceLengthSourceAttributeTests.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,17 @@ | ||
using System.Collections.Generic; | ||
|
||
using schema.binary; | ||
using schema.binary.attributes; | ||
|
||
namespace build.attributes.sequence { | ||
public partial class RSequenceLengthSourceAttributeTests { | ||
[BinarySchema] | ||
public partial class ReadonlyListClass : IBinaryConvertible { | ||
[WLengthOfSequence(nameof(Values))] | ||
private uint count_; | ||
|
||
[RSequenceLengthSource(nameof(count_))] | ||
public readonly List<int> Values = new(); | ||
} | ||
} | ||
} |
176 changes: 176 additions & 0 deletions
176
Schema Tests/binary/attributes/sequence/RSequenceLengthSourceAttributeTests.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,176 @@ | ||
using NUnit.Framework; | ||
|
||
|
||
namespace schema.binary.attributes { | ||
internal class RSequenceUntilEndOfStreamAttributeTests { | ||
[Test] | ||
public void TestByteArrayUntilEndOfStream() { | ||
BinarySchemaTestUtil.AssertGenerated(@" | ||
using schema.binary; | ||
using schema.binary.attributes; | ||
namespace foo.bar { | ||
[BinarySchema] | ||
public partial class Wrapper : IBinaryConvertible { | ||
[RSequenceUntilEndOfStream] | ||
public byte[] Field { get; set; } | ||
} | ||
}", | ||
@"using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
namespace foo.bar { | ||
public partial class Wrapper { | ||
public void Read(IEndianBinaryReader er) { | ||
this.Field = er.ReadBytes(er.Length - er.Position); | ||
} | ||
} | ||
} | ||
", | ||
@"using System; | ||
using System.IO; | ||
namespace foo.bar { | ||
public partial class Wrapper { | ||
public void Write(ISubEndianBinaryWriter ew) { | ||
ew.WriteBytes(this.Field); | ||
} | ||
} | ||
} | ||
"); | ||
} | ||
|
||
[Test] | ||
public void TestByteListUntilEndOfStream() { | ||
BinarySchemaTestUtil.AssertGenerated(@" | ||
using System.Collections.Generic; | ||
using schema.binary; | ||
using schema.binary.attributes; | ||
namespace foo.bar { | ||
[BinarySchema] | ||
public partial class Wrapper : IBinaryConvertible { | ||
[RSequenceUntilEndOfStream] | ||
public List<byte> Field { get; } = new(); | ||
} | ||
}", | ||
@"using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
namespace foo.bar { | ||
public partial class Wrapper { | ||
public void Read(IEndianBinaryReader er) { | ||
{ | ||
this.Field.Clear(); | ||
while (!er.Eof) { | ||
this.Field.Add(er.ReadByte()); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
", | ||
@"using System; | ||
using System.IO; | ||
namespace foo.bar { | ||
public partial class Wrapper { | ||
public void Write(ISubEndianBinaryWriter ew) { | ||
for (var i = 0; i < this.Field.Count; ++i) { | ||
ew.WriteByte(this.Field[i]); | ||
} | ||
} | ||
} | ||
} | ||
"); | ||
} | ||
|
||
[Test] | ||
public void TestIntArrayUntilEndOfStream() { | ||
BinarySchemaTestUtil.AssertGenerated(@" | ||
using schema.binary; | ||
using schema.binary.attributes; | ||
namespace foo.bar { | ||
[BinarySchema] | ||
public partial class Wrapper : IBinaryConvertible { | ||
[RSequenceUntilEndOfStream] | ||
public int[] Field { get; set; } | ||
} | ||
}", | ||
@"using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
namespace foo.bar { | ||
public partial class Wrapper { | ||
public void Read(IEndianBinaryReader er) { | ||
this.Field = er.ReadInt32s((er.Length - er.Position) / 4); | ||
} | ||
} | ||
} | ||
", | ||
@"using System; | ||
using System.IO; | ||
namespace foo.bar { | ||
public partial class Wrapper { | ||
public void Write(ISubEndianBinaryWriter ew) { | ||
ew.WriteInt32s(this.Field); | ||
} | ||
} | ||
} | ||
"); | ||
} | ||
|
||
[Test] | ||
public void TestIntListUntilEndOfStream() { | ||
BinarySchemaTestUtil.AssertGenerated(@" | ||
using System.Collections.Generic; | ||
using schema.binary; | ||
using schema.binary.attributes; | ||
namespace foo.bar { | ||
[BinarySchema] | ||
public partial class Wrapper : IBinaryConvertible { | ||
[RSequenceUntilEndOfStream] | ||
public List<int> Field { get; } = new(); | ||
} | ||
}", | ||
@"using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
namespace foo.bar { | ||
public partial class Wrapper { | ||
public void Read(IEndianBinaryReader er) { | ||
{ | ||
this.Field.Clear(); | ||
while (!er.Eof) { | ||
this.Field.Add(er.ReadInt32()); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
", | ||
@"using System; | ||
using System.IO; | ||
namespace foo.bar { | ||
public partial class Wrapper { | ||
public void Write(ISubEndianBinaryWriter ew) { | ||
for (var i = 0; i < this.Field.Count; ++i) { | ||
ew.WriteInt32(this.Field[i]); | ||
} | ||
} | ||
} | ||
} | ||
"); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.