public void WriteThrowsAfterDispose() { using (var context = JsonOperationContext.ShortTermSingleUse()) { var buffer = new UnmanagedWriteBuffer(context, context.GetMemory(DefaultBufferSize)); buffer.Dispose(); #if DEBUG Assert.Throws(typeof(ObjectDisposedException), () => buffer.Write(AllocationsBatch, 0, AllocationsBatch.Length)); #else Assert.Throws(typeof(NullReferenceException), () => buffer.Write(AllocationsBatch, 0, AllocationsBatch.Length)); #endif } }
public void ClearResetsSizeAndEffectivellyClears() { using (var context = JsonOperationContext.ShortTermSingleUse()) { var allocation = context.GetMemory(DefaultBufferSize); using (var buffer = new UnmanagedWriteBuffer(context, allocation)) { Assert.Equal(buffer.SizeInBytes, 0); buffer.Write(AllocationsBatch, 0, AllocationsBatch.Length); Assert.Equal(buffer.SizeInBytes, AllocationsBatch.Length); buffer.Clear(); Assert.Equal(buffer.SizeInBytes, 0); byte[] outputBuffer = new byte[AllocationsBatch.Length]; for (var i = 0; i < outputBuffer.Length; i++) { outputBuffer[i] = 124; fixed(byte *outputBufferPtr = outputBuffer) buffer.CopyTo(outputBufferPtr); foreach (var b in outputBuffer) { Assert.Equal(b, 124); } } } }
public void CopyToWithAllocations() { using (var context = JsonOperationContext.ShortTermSingleUse()) { var allocation = context.GetMemory(DefaultBufferSize); using (var buffer = new UnmanagedWriteBuffer(context, allocation)) { Assert.Equal(buffer.SizeInBytes, 0); buffer.Write(NoAllocationsBatch, 0, NoAllocationsBatch.Length); Assert.Equal(buffer.SizeInBytes, NoAllocationsBatch.Length); for (var i = 0; i < NoAllocationsBatch.Length; i++) { Assert.Equal(allocation.Address[i], NoAllocationsBatch[i]); } byte[] outputBuffer = new byte[NoAllocationsBatch.Length]; fixed(byte *outputBufferPtr = outputBuffer) buffer.CopyTo(outputBufferPtr); for (var i = 0; i < NoAllocationsBatch.Length; i++) { Assert.Equal(outputBuffer[i], NoAllocationsBatch[i]); } } } }
private void ReadToken(ref uint pos, ref bool couldRead, byte[] tokenBuffer, string tokenString, JsonParserTokenContinuation jsonParserTokenContinuation) { _unmanagedWriteBuffer.Clear(); _state.CurrentTokenType = JsonParserToken.Float; _expectedTokenBuffer = tokenBuffer; _expectedTokenBufferPosition = 1; _expectedTokenString = tokenString; if (EnsureRestOfToken(ref pos) == false) { _state.Continuation = jsonParserTokenContinuation; return; } _unmanagedWriteBuffer.Write(tokenBuffer, 0, tokenBuffer.Length); _unmanagedWriteBuffer.EnsureSingleChunk(_state); couldRead = true; }
protected override unsafe Document DirectGet(Lucene.Net.Documents.Document input, string id, DocumentFields fields, IState state) { var reduceValue = input.GetField(Constants.Documents.Indexing.Fields.ReduceKeyValueFieldName).GetBinaryValue(state); var allocation = _context.GetMemory(reduceValue.Length); UnmanagedWriteBuffer buffer = new UnmanagedWriteBuffer(_context, allocation); buffer.Write(reduceValue, 0, reduceValue.Length); var result = new BlittableJsonReaderObject(allocation.Address, reduceValue.Length, _context, buffer); return(new Document { Data = result }); }
public void WriteMultipleBytesInBatchWithAllocations() { using (var context = JsonOperationContext.ShortTermSingleUse()) { var allocation = context.GetMemory(DefaultBufferSize); using (var buffer = new UnmanagedWriteBuffer(context, allocation)) { Assert.Equal(buffer.SizeInBytes, 0); buffer.Write(AllocationsBatch, 0, AllocationsBatch.Length); Assert.Equal(buffer.SizeInBytes, AllocationsBatch.Length); for (int i = 0; i < DefaultBufferSize; i++) { Assert.Equal(allocation.Address[i], AllocationsBatch[i]); } } } }
public void EnsureSingleChunkDoesNotChangeSizeOrContentsWithAllocations() { using (var context = JsonOperationContext.ShortTermSingleUse()) { using (var buffer = new UnmanagedWriteBuffer(context, context.GetMemory(DefaultBufferSize))) { buffer.Write(AllocationsBatch, 0, AllocationsBatch.Length); buffer.EnsureSingleChunk(out byte *address, out int size); Assert.Equal(size, AllocationsBatch.Length); for (int i = 0; i < AllocationsBatch.Length; i++) { Assert.Equal(address[i], AllocationsBatch[i]); } var outputBuffer = new byte[AllocationsBatch.Length]; fixed(byte *outputBufferPtr = outputBuffer) buffer.CopyTo(outputBufferPtr); for (int i = 0; i < AllocationsBatch.Length; i++) Assert.Equal(outputBuffer[i], AllocationsBatch[i]); } } }
public void Write(float f) { _buffer.Write((byte *)&f, sizeof(float)); }