public static ArraySegment <byte> GetSegment(ArraySegment <byte> originalBytes, int index, int nextIndex, int lastIndex, DirtyTracker tracker) { var offset = GetOffset(originalBytes, index, lastIndex, tracker); if (offset == -1) { return(default(ArraySegment <byte>)); // note:very very dangerous. } int count; if (nextIndex == -1 || nextIndex > lastIndex) { count = originalBytes.Offset + originalBytes.Count - offset; // last index } else { var nextOffset = ObjectSegmentHelper.GetOffset(originalBytes, nextIndex, lastIndex, tracker); if (nextOffset == -1) { return(default(ArraySegment <byte>)); // note: precondition failed. } count = nextOffset - offset; } return(new ArraySegment <byte>(originalBytes.Array, offset, count)); }
public static T DeserializeSegment <T>(ArraySegment <byte> originalBytes, int index, int lastIndex, DirtyTracker tracker) { var offset = ObjectSegmentHelper.GetOffset(originalBytes, index, lastIndex, tracker); if (offset == -1) { return(default(T)); } int size; var array = originalBytes.Array; return(Formatter <T> .Default.Deserialize(ref array, offset, tracker, out size)); }
public static void SetFixedProperty <T>(ArraySegment <byte> bytes, int index, int lastIndex, byte[] extraBytes, T value, DirtyTracker tracker) { if (index <= lastIndex) { var array = bytes.Array; Formatter <T> .Default.Serialize(ref array, ObjectSegmentHelper.GetOffset(bytes, index, lastIndex, tracker), value); } else { // from extraBytes var offset = GetExtraBytesOffset(extraBytes, lastIndex, index); Formatter <T> .Default.Serialize(ref extraBytes, offset, value); } }
public static T GetFixedProperty <T>(ArraySegment <byte> bytes, int index, int lastIndex, byte[] extraBytes, DirtyTracker tracker) { if (index <= lastIndex) { var array = bytes.Array; int _; return(Formatter <T> .Default.Deserialize(ref array, ObjectSegmentHelper.GetOffset(bytes, index, lastIndex, tracker), tracker, out _)); } else { // from extraBytes var offset = GetExtraBytesOffset(extraBytes, lastIndex, index); int _; return(Formatter <T> .Default.Deserialize(ref extraBytes, offset, tracker, out _)); } }