/// <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); }
/// <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)); }
/// <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)); }
/// <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)); }
/// <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)); }
/// <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); }
/// <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); }
/// <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; }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
/// <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)); }
/// <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)); }