public static int WriteAndProvisionString <TSpanWriter>(this TSpanWriter spanWriter, Span <byte> span, string value, SerializationContext context) where TSpanWriter : ISpanWriter { checked { var encoding = SerializationHelpers.Encoding; // Allocate more than we need and then give back what we don't use. int maxItems = encoding.GetMaxByteCount(value.Length) + 1; int stringStartOffset = context.AllocateVector(sizeof(byte), maxItems, sizeof(byte)); int bytesWritten = spanWriter.GetStringBytes(span.Slice(stringStartOffset + sizeof(uint), maxItems), value, encoding); // null teriminator span[stringStartOffset + bytesWritten + sizeof(uint)] = 0; // write length spanWriter.WriteInt(span, bytesWritten, stringStartOffset); // give back unused space. Account for null terminator. context.Offset -= maxItems - (bytesWritten + 1); return(stringStartOffset); } }
public static void WriteReadOnlyByteMemoryBlock <TSpanWriter>( this TSpanWriter spanWriter, Span <byte> span, ReadOnlyMemory <byte> memory, int offset, SerializationContext ctx) where TSpanWriter : ISpanWriter { int numberOfItems = memory.Length; int vectorStartOffset = ctx.AllocateVector(itemAlignment: sizeof(byte), numberOfItems, sizePerItem: sizeof(byte)); spanWriter.WriteUOffset(span, offset, vectorStartOffset); spanWriter.WriteInt(span, numberOfItems, vectorStartOffset); memory.Span.CopyTo(span.Slice(vectorStartOffset + sizeof(uint))); }
private static void WriteInlineValueOf_36d43cc8bc8e4fbd92e5d1e6822467b6 <TSpanWriter>( TSpanWriter spanWriter, Span <byte> span, System.Collections.Generic.IList <BenchmarkCore.SortedVectorTableItem> value, int offset, SerializationContext context) where TSpanWriter : ISpanWriter { checked { int count = value.Count; int vectorOffset = context.AllocateVector(4, count, 4); spanWriter.WriteUOffset(span, offset, vectorOffset, context); spanWriter.WriteInt(span, count, vectorOffset, context); vectorOffset += sizeof(int); for (int i = 0; i < count; ++i) { var current = value[i]; SerializationHelpers.EnsureNonNull(current); WriteInlineValueOf_96c3a6fa438049bf89a78192c2c3e4aa(spanWriter, span, current, vectorOffset, context); vectorOffset += 4; } } }