예제 #1
0
        /// <summary>
        /// Writes binary data
        /// </summary>
        /// <param name="elementId"></param>
        /// <param name="data"></param>
        /// <param name="offset"></param>
        /// <param name="length"></param>
        /// <returns></returns>
        public int Write(VInt elementId, byte[] data, int offset, int length)
        {
            var headLen = elementId.Write(_stream) + EncodeWidth((uint)length).Write(_stream);

            _stream.Write(data, offset, length);
            return(headLen + length);
        }
예제 #2
0
        /// <summary>
        /// Writes floating point number with double precision
        /// </summary>
        /// <param name="elementId"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public int Write(VInt elementId, double value)
        {
            var u = new Union {
                dval = value
            }.ulval;

            return(elementId.Write(_stream) + EncodeWidth(8).Write(_stream) + WriteUInt(u, 8));
        }
예제 #3
0
        /// <summary>
        /// Writes floating point number
        /// </summary>
        /// <param name="elementId"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public int Write(VInt elementId, float value)
        {
            var u = new Union {
                fval = value
            }.uival;

            return(elementId.Write(_stream) + EncodeWidth(4).Write(_stream) + WriteInt(u, 4));
        }
예제 #4
0
        /// <summary>
        /// Writes unsigned integer value
        /// </summary>
        /// <param name="elementId"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public int Write(VInt elementId, ulong value)
        {
            var length = 0u;

            for (var mask = UInt64.MaxValue; (value & mask) != 0 && length < 8; mask <<= 8)
            {
                length++;
            }

            return(elementId.Write(_stream) + EncodeWidth(length).Write(_stream) + WriteUInt(value, length));
        }
예제 #5
0
        /// <summary>
        /// Writes signed integer value
        /// </summary>
        /// <param name="elementId"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public int Write(VInt elementId, long value)
        {
            var length = value == 0 ? 0u : 1u;

            unchecked
            {
                var mask = (long)0xffffffffffffff80L;
                for (var expected = value < 0L ? mask : 0L; length < 8 && (mask & value) != expected; mask <<= 8, expected <<= 8)
                {
                    length++;
                }
            }

            return(elementId.Write(_stream) + EncodeWidth(length).Write(_stream) + WriteInt(value, length));
        }
예제 #6
0
파일: EbmlWriter.cs 프로젝트: juanii/NEbml
        /// <summary>
        /// Writes signed integer value
        /// </summary>
        /// <param name="elementId"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public int Write(VInt elementId, Int64 value)
        {
            var length = value == 0 ? 0u : 1u;
            unchecked
            {
                var mask = (long)0xffffffffffffff80L;
                for (var expected = value < 0L ? mask : 0L; length < 8 && (mask & value) != expected; mask <<= 8, expected <<= 8)
                {
                    length++;
                }
            }

            return elementId.Write(_stream) + EncodeWidth(length).Write(_stream) + WriteInt(value, length);
        }
예제 #7
0
파일: EbmlWriter.cs 프로젝트: juanii/NEbml
 /// <summary>
 /// Writes element header
 /// </summary>
 /// <param name="elementId"></param>
 /// <param name="size"></param>
 /// <returns></returns>
 public int WriteElementHeader(VInt elementId, VInt size)
 {
     return elementId.Write(_stream) + size.Write(_stream);
 }
예제 #8
0
파일: EbmlWriter.cs 프로젝트: juanii/NEbml
 /// <summary>
 /// Writes binary data
 /// </summary>
 /// <param name="elementId"></param>
 /// <param name="data"></param>
 /// <param name="offset"></param>
 /// <param name="length"></param>
 /// <returns></returns>
 public int Write(VInt elementId, byte[] data, int offset, int length)
 {
     var headLen = elementId.Write(_stream) + EncodeWidth((uint) length).Write(_stream);
     _stream.Write(data, offset, length);
     return headLen + length;
 }
예제 #9
0
파일: EbmlWriter.cs 프로젝트: juanii/NEbml
 /// <summary>
 /// Writes floating point number with double precision
 /// </summary>
 /// <param name="elementId"></param>
 /// <param name="value"></param>
 /// <returns></returns>
 public int Write(VInt elementId, double value)
 {
     var u = new Union { dval = value }.ulval;
     return elementId.Write(_stream) + EncodeWidth(8).Write(_stream) + WriteUInt(u, 8);
 }
예제 #10
0
파일: EbmlWriter.cs 프로젝트: juanii/NEbml
 /// <summary>
 /// Writes floating point number
 /// </summary>
 /// <param name="elementId"></param>
 /// <param name="value"></param>
 /// <returns></returns>
 public int Write(VInt elementId, float value)
 {
     var u = new Union {fval = value}.uival;
     return elementId.Write(_stream) + EncodeWidth(4).Write(_stream) + WriteInt(u, 4);
 }
예제 #11
0
파일: EbmlWriter.cs 프로젝트: juanii/NEbml
 /// <summary>
 /// Writes datetime value
 /// </summary>
 /// <param name="elementId"></param>
 /// <param name="dateTime"></param>
 /// <returns></returns>
 public int Write(VInt elementId, DateTime dateTime)
 {
     var d = (dateTime - EbmlReader.MilleniumStart).Ticks * 100;
     return elementId.Write(_stream) + EncodeWidth(8).Write(_stream) + WriteInt(d, 8);
 }
예제 #12
0
파일: EbmlWriter.cs 프로젝트: juanii/NEbml
        /// <summary>
        /// Writes unsigned integer value
        /// </summary>
        /// <param name="elementId"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public int Write(VInt elementId, UInt64 value)
        {
            var length = 0u;
            for (var mask = UInt64.MaxValue; (value & mask) != 0 && length < 8; mask <<= 8)
            {
                length++;
            }

            return elementId.Write(_stream) + EncodeWidth(length).Write(_stream) + WriteUInt(value, length);
        }
예제 #13
0
 /// <summary>
 /// Writes element header
 /// </summary>
 /// <param name="elementId"></param>
 /// <param name="size"></param>
 /// <returns></returns>
 public int WriteElementHeader(VInt elementId, VInt size)
 {
     return(elementId.Write(_stream) + size.Write(_stream));
 }
예제 #14
0
        /// <summary>
        /// Writes datetime value
        /// </summary>
        /// <param name="elementId"></param>
        /// <param name="dateTime"></param>
        /// <returns></returns>
        public int Write(VInt elementId, DateTime dateTime)
        {
            var d = (dateTime - EbmlReader.MilleniumStart).Ticks * 100;

            return(elementId.Write(_stream) + EncodeWidth(8).Write(_stream) + WriteInt(d, 8));
        }