public static byte[] GetEncodedPropertyNameWithoutQuotation(string propertyName) { var writer = new JsonWriterUtf8(); writer.WriteString(propertyName); // "propname" var buf = writer.GetBuffer(); var result = new byte[buf.Count - 2]; Buffer.BlockCopy(buf.Array, buf.Offset + 1, result, 0, result.Length); // without quotation return(result); }
public static ArraySegment <byte> SerializeUnsafe <T>(T value, IJsonFormatterResolver resolver) { if (resolver == null) { resolver = JsonSerializer.DefaultResolver; } var writer = new JsonWriterUtf8(MemoryPool.GetBuffer()); var formatter = resolver.GetFormatterWithVerify <T>(); formatter.Serialize(writer, value, resolver); return(writer.GetBuffer()); }
public static async System.Threading.Tasks.Task SerializeAsync <T>(Stream stream, T value, IJsonFormatterResolver resolver) { if (resolver == null) { resolver = JsonSerializer.DefaultResolver; } var buf = BufferPool.Default.Rent(); try { var writer = new JsonWriterUtf8(buf); var formatter = resolver.GetFormatterWithVerify <T>(); formatter.Serialize(writer, value, resolver); var buffer = writer.GetBuffer(); await stream.WriteAsync(buffer.Array, buffer.Offset, buffer.Count).ConfigureAwait(false); } finally { BufferPool.Default.Return(buf); } }