/// <summary> /// Serializes an indexing operation in a bulk request /// </summary> /// <param name="message">Message to serialize.</param> private void SerializeIndexingRequest(LocalLogMessage message) { // serialize bulk request item object for indexing mRequestContentWriter.Reset(); mStage.WriteBulkRequestIndexAction_ECS110(mRequestContentWriter); // finalize line with a newline character mContentStream.WriteByte((byte)'\n'); // serialize the actual log message mRequestContentWriter.Reset(); mStage.WriteJsonMessage_ECS110(mRequestContentWriter, message); // finalize line with a newline character mContentStream.WriteByte((byte)'\n'); }
private void PerformMutationOp() { int outcome = DiscreteDistribution.Sample(_rng, _opDistribution); switch (outcome) { case 0: // Write. { PerformMutationOp_Write(); break; } case 1: // Write byte. { byte b = (byte)_rng.Next(); _strmA.WriteByte(b); _strmB.WriteByte(b); Debug.WriteLine("WriteByte"); break; } case 2: // Change read/write head position. { PerformMutationOp_Position(); break; } case 3: // SetLength { PerformMutationOp_SetLength(); break; } case 4: // Seek { PerformMutationOp_Seek(); break; } case 5: // Trim { _strmB.Trim(); Debug.WriteLine("Trim"); break; } case 6: // Read byte. { int a = _strmA.ReadByte(); int b = _strmB.ReadByte(); if (a != b) { throw new Exception("ReadByte mismatch"); } Debug.WriteLine("ReadByte"); break; } case 7: // Read { int len = _rng.Next(20000); byte[] abuf = new byte[len]; byte[] bbuf = new byte[len]; int alen = _strmA.Read(abuf, 0, len); int blen = _strmB.Read(bbuf, 0, len); if (alen != blen) { throw new Exception("Read mismatch"); } if (!Utils.AreEqual(abuf, bbuf)) { throw new Exception("Read mismatch"); } Debug.WriteLine("Read"); break; } } }
public string ReadText(int MaxLength, TextEncodings TEncoding, ref int ReadedLength, bool DetectEncoding) { if (MaxLength <= 0) { return(""); } long Pos = this.FS.Position; // store current position MemoryBlockStream MStream = new MemoryBlockStream(); if (DetectEncoding && MaxLength >= 3) { byte[] Buffer = new byte[3]; FS.Read(Buffer, 0, Buffer.Length); if (Buffer[0] == 0xFF && Buffer[1] == 0xFE) { // FF FE TEncoding = TextEncodings.UTF_16; // UTF-16 (LE) this.FS.Position--; MaxLength -= 2; } else if (Buffer[0] == 0xFE && Buffer[1] == 0xFF) { // FE FF TEncoding = TextEncodings.UTF_16BE; this.FS.Position--; MaxLength -= 2; } else if (Buffer[0] == 0xEF && Buffer[1] == 0xBB && Buffer[2] == 0xBF) { // EF BB BF TEncoding = TextEncodings.UTF8; MaxLength -= 3; } else { this.FS.Position -= 3; } } // Indicate text seprator type for current string encoding bool Is2ByteSeprator = (TEncoding == TextEncodings.UTF_16 || TEncoding == TextEncodings.UTF_16BE); byte Buf, Buf2; while (MaxLength > 0) { if (Is2ByteSeprator) { Buf = ReadByte(FS); Buf2 = ReadByte(FS); if (Buf == 0 && Buf2 == 0) { break; } else { MStream.WriteByte(Buf); MStream.WriteByte(Buf2); } MaxLength--; } else { Buf = ReadByte(FS); // Read First/Next byte from stream if (Buf == 0) { break; } else { MStream.WriteByte(Buf); } } MaxLength--; } if (MaxLength < 0) { this.FS.Position += MaxLength; } ReadedLength -= Convert.ToInt32(this.FS.Position - Pos); return(StaticMethods.GetEncoding(TEncoding).GetString(MStream.ToArray())); }