public ElementInfo(EBMLDocElement docElement, Int64 idPos, Int64 vintPos, Int64 dataPos, Int64? dataLength) { DocElement = docElement; IdPos = idPos; VIntPos = vintPos; DataPos = dataPos; DataLength = dataLength; }
public ElementInfo WriteElement(EBMLDocElement elem, Stream data) { Int64 idPos = dataSrc.Position; dataSrc.WriteIdentifier(elem.Id); Int64 vIntPos = dataSrc.Position; dataSrc.WriteFakeVInt(8); Int64 dataPos = dataSrc.Position; dataSrc.Write(data); var elemInfo = new ElementInfo(elem, idPos, vIntPos, dataPos, null); UpdateElementLength(elemInfo); return elemInfo; }
protected override byte[] TransformElement(EBMLDocElement elem, object value) { throw new NotImplementedException(); }
protected override object RetrieveByExtension(EBMLDocElement docElem, byte[] data, long offset, long length) { if(docElem.Id == (int)Block.Id || docElem.Id == (int)SimpleBlock.Id) { return new MatroskaBlock(data, offset, (int)length); } else { throw new Exception("Unhandled ElementType"); } }
public ElementInfo WriteElement(EBMLDocElement elem, byte[] b, int offset, int length) { Int64 idPos = dataSrc.Position; dataSrc.WriteIdentifier(elem.Id); Int64 vIntPos = dataSrc.Position; dataSrc.WriteVInt(length); Int64 dataPos = dataSrc.Position; dataSrc.Write(b, offset, length); return new ElementInfo(elem, idPos, vIntPos, dataPos, b.Length); }
public ElementInfo WriteElement(EBMLDocElement elem, Object value) { var binElem = ebmlDoc.TransformDocElement(elem, value); return WriteElement(elem, binElem, 0, binElem.Length); }
public MasterElementInfo WriteMasterElement(EBMLDocElement elem) { Int64 idPos = dataSrc.Position; dataSrc.WriteIdentifier(elem.Id); Int64 vIntPos = dataSrc.Position; dataSrc.WriteFakeVInt(8); var elemInfo = new MasterElementInfo(elem, idPos, vIntPos, dataSrc.Position, null); elemInfo.Disposed += (s, e) => UpdateElementLength((ElementInfo)s); return elemInfo; }
protected virtual Byte[] TransformElement(EBMLDocElement elem, Object value) { throw new NotSupportedException(); }
protected virtual object RetrieveByExtension(EBMLDocElement docElem, byte[] data, long offset, long length) { throw new NotSupportedException(); }
public Byte[] TransformDocElement(EBMLDocElement elem, Object value) { switch(elem.Type) { case EBMLElementType.Binary: return (Byte[])value; case EBMLElementType.SInteger: return TransformElement((Int64)value); case EBMLElementType.UInteger: return TransformElement((UInt64)value); case EBMLElementType.Float: return value is Single ? TransformElement((Single)value) : TransformElement((Double)value); case EBMLElementType.UTF8: return TransformElement((String)value, false); case EBMLElementType.ASCII: return TransformElement((String)value, true); case EBMLElementType.Date: return TransformElement((DateTime)value); case EBMLElementType.Custom: return TransformDocElement(elem, value); case EBMLElementType.Unknown: case EBMLElementType.Master: default: throw new Exception(); } }
public object RetrieveValue(EBMLDocElement docElem, Byte[] data, Int64 offset, Int64 length) { if(offset > Int32.MaxValue || length > Int32.MaxValue) throw new Exception(); switch(docElem.Type) { case EBMLElementType.Master: case EBMLElementType.Unknown: case EBMLElementType.Binary: return RetrieveBinary(data, offset, length); case EBMLElementType.SInteger: return RetrieveSInteger(data, offset, length); case EBMLElementType.UInteger: return RetrieveInteger(data, offset, length); //case EBMLElementType.Double: return RetrieveDouble(data, offset); case EBMLElementType.Float: return length == 4 ? (double)RetrieveFloat(data, offset) : RetrieveDouble(data, offset); case EBMLElementType.UTF8: return RetrieveUTF8(data, offset, length); case EBMLElementType.ASCII: return RetrieveASCII(data, offset, length); case EBMLElementType.Date: return RetrieveDate(data, offset, length); case EBMLElementType.Custom: return RetrieveByExtension(docElem, data, offset, length); default: throw new Exception("Unhandled ElementType"); } }
public EBMLDocElement RetrieveDocElement(Int32 id) { EBMLDocElement elementType = (docElementMap.TryGetValue(id, out elementType) ? elementType : null); if(elementType == null) elementType = new EBMLDocElement(id, EBMLElementType.Unknown, "Unknown"); return elementType; }
protected override object RetrieveByExtension(EBMLDocElement docElem, byte[] data, long offset, long length) { if(docElem.Id == Position.Id || docElem.Id == Motion.Id) { return new double[] { EBMLDocType.RetrieveDouble(data, offset), EBMLDocType.RetrieveDouble(data, offset + 8), EBMLDocType.RetrieveDouble(data, offset + 16) }; } else if(docElem.Id == Rotation.Id) { return new Single[] { EBMLDocType.RetrieveFloat(data, offset), EBMLDocType.RetrieveFloat(data, offset + 4), }; } else if(docElem.Id == IntegralPosition.Id) { Byte[] b = new Byte[length]; Buffer.BlockCopy(data, (Int32)offset, b, 0, (Int32)length); if(BitConverter.IsLittleEndian) { Array.Reverse(b, 0, 4); Array.Reverse(b, 4, 4); Array.Reverse(b, 8, 4); } return new int[] { BitConverter.ToInt32(b, 0), BitConverter.ToInt32(b, 4), BitConverter.ToInt32(b, 8), }; } else if(docElem.Id == Coordinates.Id) { Byte[] b = new Byte[length]; Buffer.BlockCopy(data, (Int32)offset, b, 0, (Int32)length); if(BitConverter.IsLittleEndian) { Array.Reverse(b, 0, 8); Array.Reverse(b, 8, 8); } return new long[] { BitConverter.ToInt64(b, 0), BitConverter.ToInt64(b, 8), }; } else if(docElem.Id == CubesSym.Id || docElem.Id == ChunksSym.Id || docElem.Id == RegionsSym.Id || docElem.Id == WorldStatesSym.Id) { Byte[] b = new Byte[length]; Buffer.BlockCopy(data, (Int32)offset, b, 0, (Int32)length); if(BitConverter.IsLittleEndian) { for(int i = 0;i < b.Length;i += 8) Array.Reverse(b, i, 8); } var values = new ulong[length / 8]; for(int i = 0;i < values.Length;i++) values[i] = BitConverter.ToUInt64(b, i * 8); return values; } throw new Exception("Unknown Element"); }
protected override byte[] TransformElement(EBMLDocElement docElem, object value) { if(docElem.Id == Position.Id || docElem.Id == Motion.Id) { var v = (double[])value; var b = new Byte[24]; Buffer.BlockCopy(EBMLDocType.TransformElement(v[0]), 0, b, 0, 8); Buffer.BlockCopy(EBMLDocType.TransformElement(v[1]), 0, b, 8, 8); Buffer.BlockCopy(EBMLDocType.TransformElement(v[2]), 0, b, 16, 8); return b; } else if(docElem.Id == Rotation.Id) { var v = (Single[])value; var b = new Byte[8]; Buffer.BlockCopy(EBMLDocType.TransformElement(v[0]), 0, b, 0, 4); Buffer.BlockCopy(EBMLDocType.TransformElement(v[1]), 0, b, 4, 4); return b; } else if(docElem.Id == IntegralPosition.Id) { var v = (Int32[])value; var b = new Byte[12]; Buffer.BlockCopy(EBMLDocType.TransformElement(v[0]), 0, b, 0, 8); Buffer.BlockCopy(EBMLDocType.TransformElement(v[1]), 0, b, 4, 8); Buffer.BlockCopy(EBMLDocType.TransformElement(v[2]), 0, b, 8, 8); return b; } else if(docElem.Id == Coordinates.Id) { var v = (Int64[])value; var b = new Byte[v.Length * 8]; for(int i = 0;i < v.Length;i++) Buffer.BlockCopy(EBMLDocType.TransformElement(v[i]), 0, b, i * 8, 8); return b; } else if(docElem.Id == CubesSym.Id || docElem.Id == ChunksSym.Id || docElem.Id == RegionsSym.Id || docElem.Id == WorldStatesSym.Id) { var v = (UInt64[])value; var b = new Byte[v.Length * 8]; for(int i = 0;i < v.Length;i++) Buffer.BlockCopy(EBMLDocType.TransformElement(v[i]), 0, b, i * 8, 8); return b; } throw new Exception("Unknown Element"); }
public MasterElementInfo(EBMLDocElement docElement, Int64 idPos, Int64 vintPos, Int64 dataPos, Int64? dataLength) : base(docElement, idPos, vintPos, dataPos, dataLength) { }