Provides a stream for encoding Erlang terms to external format, for transmission or storage.
Inheritance: System.IO.MemoryStream
        public void Write_8BE()
        {
            byte[] want = { 0x12, 0xAD, 0xBE, 0xEF, 0x98, 0x76,  0xAB, 0xCD };
            byte[] got;
            using (var os = new OtpOutputStream())
            {
                os.Write8BE(0x12ADBEEF9876ABCD);
                got = os.ToArray();
            }

            CollectionAssert.AreEqual(want, got);
        }
        public void Write_2BE()
        {
            byte[] want = { 0xAB, 0xCD };
            byte[] got;
            using (var os = new OtpOutputStream())
            {
                os.Write2BE(0xFFFFABCD);
                got = os.ToArray();
            }

            CollectionAssert.AreEqual(want, got);
        }
        public void Write_Byte()
        {
            byte want = 123;
            byte[] got;
            using (var os = new OtpOutputStream())
            {
                os.Write(want);
                got = os.ToArray();
            }

            Assert.AreEqual(want, got[0]);
        }
        public void Can_Parse_Bare_RpbErrorResp()
        {
            byte[] b = null;
            using (var os = new OtpOutputStream())
            {
                os.WriteAtom(TtbErrorDecoder.RpbErrorRespAtom);
                os.Flush();
                b = os.ToArray();
            }

            var ex = Assert.Throws<RiakException>(() => new TsTtbResp(b));
            Assert.IsTrue(ex.Message.Contains(TtbErrorDecoder.RpbErrorRespEmpty));
        }
        public void Write_Atom()
        {
            byte[] want = { 131, 100, 0, 18, 102, 114, 97, 122, 122, 108, 101, 100, 97, 122, 122, 108, 101, 45, 49, 50, 51, 52 };
            byte[] got;
            using (var os = new OtpOutputStream())
            {
                os.Write(OtpExternal.VersionTag);
                os.WriteAtom("frazzledazzle-1234");
                Assert.AreEqual(want.Length, os.Position);
                got = os.ToArray();
            }

            CollectionAssert.AreEqual(want, got);
        }
        public void Read_Binary(string want)
        {
            byte[] buf = null;
            using (var os = new OtpOutputStream())
            {
                os.WriteStringAsBinary(want);
                buf = os.ToArray();
            }

            using (var s = new OtpInputStream(buf))
            {
                string got = s.ReadBinaryAsString();
                Assert.AreEqual(want, got);
            }
        }
        public void Can_Parse_RpbErrorResp_In_2_Tuple_With_Code()
        {
            byte[] b = null;
            using (var os = new OtpOutputStream())
            {
                os.WriteTupleHead(2);
                os.WriteAtom(TtbErrorDecoder.RpbErrorRespAtom);
                os.WriteLong(ErrCode);
                os.Flush();
                b = os.ToArray();
            }

            var ex = Assert.Throws<RiakException>(() => new TsTtbResp(b));
            Assert.IsTrue(ex.Message.Contains(ErrCode.ToString()));
        }
        public void Write_Binary()
        {
            var r = new Random();
            byte[] rnd = new byte[65536];
            r.NextBytes(rnd);

            byte[] want = BuildBinBuffer(rnd);
            byte[] got;
            using (var os = new OtpOutputStream())
            {
                os.WriteBinary(rnd);
                Assert.AreEqual(want.Length, os.Position);
                got = os.ToArray();
            }

            CollectionAssert.AreEqual(want, got);
        }
        public void Write_List_And_Tuple()
        {
            byte[] want = new byte[]
            {
                131, 108, 0, 0, 0, 2, 104, 2, 100, 0, 4, 116, 114, 117, 101, 100, 0, 5, 
                102, 97, 108, 115, 101, 108, 0, 0, 0, 2, 100, 0, 4, 116, 114, 117, 101, 
                100, 0, 5, 102, 97, 108, 115, 101, 106, 106
            };
            byte[] got;
            using (var os = new OtpOutputStream())
            {
                os.WriteByte(OtpExternal.VersionTag);
                os.WriteListHead(2);
                os.WriteTupleHead(2);
                os.WriteBoolean(true);
                os.WriteBoolean(false);
                os.WriteListHead(2);
                os.WriteBoolean(true);
                os.WriteBoolean(false);
                os.WriteNil();
                os.WriteNil();
                Assert.AreEqual(want.Length, os.Position);
                got = os.ToArray();
            }

            CollectionAssert.AreEqual(want, got);
        }
        public void Write_Long(long l, byte[] want)
        {
            byte[] got;
            using (var os = new OtpOutputStream())
            {
                os.WriteByte(OtpExternal.VersionTag);
                os.WriteLong(l);
                Assert.AreEqual(want.Length, os.Position);
                got = os.ToArray();
            }

            CollectionAssert.AreEqual(want, got);
        }
        public void Write_String_As_Binary(string s)
        {
            byte[] str = Encoding.UTF8.GetBytes(s);
            byte[] want = BuildBinBuffer(str);
            byte[] got;
            using (var os = new OtpOutputStream())
            {
                os.WriteStringAsBinary(s);
                Assert.AreEqual(want.Length, os.Position);
                got = os.ToArray();
            }

            CollectionAssert.AreEqual(want, got);
        }