public IList <Memory <byte> > GetSegments() { var list = new List <Memory <byte> >(); foreach (var segment in _completedSegments) { list.Add(segment); } if (CurrentSegment.Length > 0) { list.Add(CurrentSegment.Slice(0, Position)); } return(list); }
public Memory <byte> GetMemory(int sizeHint = 0) { // Need special handling for sizeHint == 0, because for that we want to enter the if even if there are "sizeHint" (i.e. 0) bytes left :). if ((sizeHint == 0 && CurrentSegment.Length == Position) || (CurrentSegment.Length - Position < sizeHint)) { if (Position > 0) { // Complete the current segment _completedSegments.Add(CurrentSegment.Slice(0, Position)); } // Allocate a new segment and reset the position. CurrentSegment = new Memory <byte>(new byte[_segmentSize]); Position = 0; } return(CurrentSegment.Slice(Position, CurrentSegment.Length - Position)); }
public static List <PointCollection> SlplitPlot(PointCollection Plot, double Width, double Height, RepresentationParameters RepresentationParameters) { PointCollection CurrentSegment = new PointCollection(); List <PointCollection> PointCollectionList = new List <PointCollection>(); CurrentSegment.Add(Plot[0]); for (int i = 1; i < Width; i++) { if (Math.Abs(Plot[i - 1].Y - Plot[i].Y) > Height) { PointCollectionList.Add(CurrentSegment); CurrentSegment = new PointCollection(); } else { CurrentSegment.Add(Plot[i]); } } PointCollectionList.Add(CurrentSegment); return(PointCollectionList); }
void Validate() { try { switch (Kind) { case ObjectKind.Struct: CurrentSegment.Slice(Offset, StructDataCount + StructPtrCount); break; case ObjectKind.ListOfBits: GetRawBits(); break; case ObjectKind.ListOfBytes: GetRawBytes(); break; case ObjectKind.ListOfInts: GetRawInts(); break; case ObjectKind.ListOfLongs: case ObjectKind.ListOfPointers: GetRawLongs(); break; case ObjectKind.ListOfStructs: CurrentSegment.Slice(Offset, checked (ListElementCount * (StructDataCount + StructPtrCount))); break; } } catch (Exception problem) { throw new DeserializationException("Invalid wire pointer", problem); } }
public byte[] ToArray() { if (CurrentSegment.IsEmpty && _completedSegments.Count == 0) { return(Array.Empty <byte>()); } var result = new byte[_totalLength]; var totalWritten = 0; // Copy completed segments foreach (var segment in _completedSegments) { segment.CopyTo(result.AsMemory(totalWritten, segment.Length)); totalWritten += segment.Length; } // Copy current segment CurrentSegment.Slice(0, Position).CopyTo(result.AsMemory(totalWritten, Position)); return(result); }
ReadOnlySpan <ulong> GetRawLongs() => CurrentSegment.Slice(Offset, ListElementCount);
ReadOnlySpan <ulong> GetRawInts() => CurrentSegment.Slice(Offset, (ListElementCount + 1) / 2);
ReadOnlySpan <ulong> GetRawShorts() => CurrentSegment.Slice(Offset, (ListElementCount + 3) / 4);
ReadOnlySpan <ulong> GetRawBytes() => CurrentSegment.Slice(Offset, (ListElementCount + 7) / 8);
ReadOnlySpan <ulong> GetRawBits() => CurrentSegment.Slice(Offset, (ListElementCount + 63) / 64);
public void VisitCurrent(CurrentSegment node, GlobVisitorContext context) { node.Next.Accept(this, context); }