private void WriteByteString(int indentLevel, BByteString byteString) { Console.WriteLine("{0}{1}", GetIndentSpaces(indentLevel), byteString.ConvertToText(Encoding.ASCII)); }
public void Encode(BByteString input, Stream outputStream) { if (input == null) throw new ArgumentNullException("input"); if (outputStream == null) throw new ArgumentNullException("outputStream"); // Write byte string "header": byte[] strLengthBytes = Encoding.ASCII.GetBytes(input.Value.Length.ToString()); outputStream.Write(strLengthBytes, 0, strLengthBytes.Length); outputStream.WriteByte(Definitions.ASCII_colon); outputStream.Write(input.Value, 0, input.Value.Length); }
public void EncodeByteString_NullOutputStream_Exception() { BByteString bstrObj = new BByteString() { Value = new byte[] { } }; var transform = new ByteStringTransform(); transform.Encode(bstrObj, null); }
public void EncodeByteString_SimpleScenario_Positive() { // Prepare input and expected output value byte[] inputBytes = {1,2,3,4}; byte[] expectedBytes = {0,0,1,2,3,4}; expectedBytes[0] = EncodingHelper.GetASCIIValue('4'); expectedBytes[1] = EncodingHelper.GetASCIIValue(':'); MemoryStream outputStream = new MemoryStream(6); // Do encoding BByteString bstrObj = new BByteString() { Value = inputBytes }; var transform = new ByteStringTransform(); transform.Encode(bstrObj, outputStream); // Check results Assert.AreEqual<long>(expectedBytes.LongLength, outputStream.Position); // Ensure 6 bytes were (likely) written outputStream.Position = 0; byte[] outputtedBytes = outputStream.ToArray(); Assert.IsTrue(outputtedBytes.IsEqualWith(expectedBytes), "Outputted bytes are different than expected"); }
public void EncodeByteString_NoBytesInInput_Positive() { // Prepare input and expected output value byte[] inputBytes = { }; byte[] expectedBytes = { 0, 0 }; expectedBytes[0] = EncodingHelper.GetASCIIValue('0'); expectedBytes[1] = EncodingHelper.GetASCIIValue(':'); MemoryStream outputStream = new MemoryStream(6); // Do encoding BByteString bstrObj = new BByteString() { Value = inputBytes }; var transform = new ByteStringTransform(); transform.Encode(bstrObj, outputStream); // Check results outputStream.Position = 0; byte[] outputtedBytes = outputStream.ToArray(); Assert.IsTrue(outputtedBytes.IsEqualWith(expectedBytes), "Outputted bytes are different than expected"); }