public override string ToTextualConvention(Container.Node node) { if (node.Master.Equals(this)) { return(NutReader.ToTextualConvention(node.Identifier)); } return(base.ToTextualConvention(node)); }
public static byte[] GetFrameHeader(NutReader reader, Node node) { if (node == null) { throw new ArgumentNullException("node"); } if (!IsFrame(node)) { return(Media.Common.MemorySegment.EmptyBytes); } return(reader.EllisionHeaders[node.Identifier[5]]); }
public static FrameFlags GetFrameFlags(NutReader reader, Node node) { if (node == null) { throw new ArgumentNullException("node"); } if (!IsFrame(node)) { return(FrameFlags.Unknown); } return((FrameFlags)reader.HeaderOptions[node.Identifier[IdentifierBytesSize]].Item1); }
public static byte[] GetFrameData(NutReader reader, Node node, out byte[] sideData, out byte[] metaData) { FrameFlags flags = GetFrameFlags(reader, node); sideData = metaData = null; //Always include the frame header IEnumerable <byte> frameData = GetFrameHeader(reader, node); //Check if data needs to be removed if (flags.HasFlag(FrameFlags.SideMetaData)) { //Compatibility //If SizeData in the header was set this is a draft version and the data is at the end of the frame. //In such a case the sidedata size was already read from the frame header and is stored in the Identifier. long sidedata_size = node.Identifier[4]; //Just incase it was indicated that this frame uses a normal side data size of 0 and includes specific side data for the frame //Check the header and frame headers value which was stored when reading the frame. if (sidedata_size > 0) { metaData = null; //Not included in spec. int dataSize = (int)(node.DataSize - sidedata_size); frameData = Enumerable.Concat(frameData, node.Data.Take(dataSize)); sideData = node.Data.Skip(dataSize).ToArray(); } else //Current Spec { int bytesReadNow = 0, bytesReadTotal = 0; //Get a stream of the data using (var stream = node.DataStream) { int size = (int)reader.DecodeVariableLength(stream, out bytesReadNow); //Side Data Count (From Info) and read if (size > 0) { bytesReadTotal += bytesReadNow; sideData = new byte[size]; reader.Read(sideData, 0, size); bytesReadTotal += size; } //Meta Data Count (From Info) and read size = (int)reader.DecodeVariableLength(stream, out bytesReadNow); if (size > 0) { bytesReadTotal += bytesReadNow; metaData = new byte[size]; reader.Read(sideData, 0, size); bytesReadTotal += size; } //The position of this stream is now @ the end of the data which does not belong to the frame itself. frameData = Enumerable.Concat(frameData, node.Data.Skip(bytesReadTotal)); } } } else //The data of the frame is as it is { frameData = Enumerable.Concat(frameData, node.Data); } //Return the allocated array return(frameData.ToArray()); }