public unsafe byte[] Write <T>(bool ignoreCustomSerialization, T obj) { var writerAndCounter = GetWriterAndSizeCounter <T>(ignoreCustomSerialization); var context = new WriterContext(serializerId, 0, 0, trackReferences); var size = writerAndCounter.Item2(obj, true, context); size = context.references > 0 ? size + 5 : size; var result = new byte[size]; context.length = size; int index = 0; fixed(byte *r = &result[0]) Write(obj, (IntPtr)r, ref index, writerAndCounter.Item1, context); if (index != size) { throw new Exception("Bug: at the end of serialization index must point at the end of array"); } return(result); }
public void Write(object obj, bool writeEmpty, IntPtr result, ref int index, WriterContext context) { groBufWriter.Write(type, ignoreCustomSerializer, obj, writeEmpty, result, ref index, context); }
public int CountSize(object obj, bool writeEmpty, WriterContext context) { return(groBufWriter.GetSize(type, ignoreCustomSerializer, obj, writeEmpty, context)); }
public void Write(object obj, bool writeEmpty, IntPtr result, ref int index, WriterContext context) { writerDelegate(obj, writeEmpty, result, ref index, context); }
public int CountSize(object obj, bool writeEmpty, WriterContext context) { return(sizeCounter(obj, writeEmpty, context)); }
private unsafe void Write <T>(T obj, IntPtr data, ref int index, WriterDelegate <T> writer, WriterContext context) { if (context.references > 0) { var r = (byte *)(data + index); * r = (byte)GroBufTypeCode.Reference; *(int *)(r + 1) = context.references; index += 5; } context.start = index; writer(obj, true, data, ref index, new WriterContext(serializerId, context.length, context.start, trackReferences)); }
public int GetSize(Type type, bool ignoreCustomSerialization, object obj, bool writeEmpty, WriterContext context) { return(GetWriterAndSizeCounter(type, ignoreCustomSerialization).Item2(obj, writeEmpty, context)); }
public void Write(Type type, bool ignoreCustomSerialization, object obj, bool writeEmpty, IntPtr result, ref int index, WriterContext context) { GetWriterAndSizeCounter(type, ignoreCustomSerialization).Item1(obj, writeEmpty, result, ref index, context); }