Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make StreamValueNode aware of FieldOffset. #233

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions BinarySerializer/Graph/ValueGraph/StreamValueNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ internal override void SerializeOverride(BoundedStream stream, EventShuttle even
var valueStream = (Stream) Value;

var length = GetConstFieldLength();
var offset = GetFieldOffset() == null ? stream.Position : GetFieldOffset().Value;

if (length != null)
{
var valueStreamlet = new Streamlet(valueStream, valueStream.Position, length.ByteCount);
var valueStreamlet = new Streamlet(valueStream, offset, length.ByteCount);
valueStreamlet.CopyTo(stream);
}
else
Expand All @@ -38,10 +39,11 @@ internal override async Task SerializeOverrideAsync(BoundedStream stream, EventS
var valueStream = (Stream)Value;

var length = GetConstFieldLength();
var offset = GetFieldOffset() == null ? stream.Position : GetFieldOffset().Value;

if (length != null)
{
var valueStreamlet = new Streamlet(valueStream, valueStream.Position, length.ByteCount);
var valueStreamlet = new Streamlet(valueStream, offset, length.ByteCount);
await valueStreamlet.CopyToAsync(stream, CopyToBufferSize, cancellationToken).ConfigureAwait(false);
}
else
Expand All @@ -55,10 +57,11 @@ internal override void DeserializeOverride(BoundedStream stream, SerializationOp
var rootStream = GetRootStream(stream);

var length = GetFieldLength();
var offset = GetFieldOffset() == null ? stream.Position : GetFieldOffset().Value;

Value = length != null
? new Streamlet(rootStream, rootStream.Position, length.ByteCount)
: new Streamlet(rootStream, rootStream.Position);
? new Streamlet(rootStream, offset, length.ByteCount)
: new Streamlet(rootStream, offset);

if (length != null)
{
Expand All @@ -77,10 +80,11 @@ internal override async Task DeserializeOverrideAsync(BoundedStream stream, Seri
var rootStream = GetRootStream(stream);

var length = GetFieldLength();
var offset = GetFieldOffset() == null ? stream.Position : GetFieldOffset().Value;

Value = length != null
? new Streamlet(rootStream, rootStream.Position, length.ByteCount)
: new Streamlet(rootStream, rootStream.Position);
? new Streamlet(rootStream, offset, length.ByteCount)
: new Streamlet(rootStream, offset);

if (length != null)
{
Expand Down
Loading