예제 #1
0
        /// <summary>
        /// Creates a new chunk using the given data.
        /// </summary>
        /// <param name="data">Data starting at the first byte of the chunk</param>
        public Chunk(byte[] data)
        {
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data), $"{nameof(data)} is null!");
            }
            if (data.Length == 0)
            {
                throw new ArgumentException($"{nameof(data)} is empty!");
            }

            var formatParser = new FormatParser(data);

            Type = ChunkTypeMapping.GetChunkId(formatParser.ParseString(4));

            int contentLength  = formatParser.ParseInt32();
            int childrenLength = formatParser.ParseInt32();

            Content  = formatParser.ParseBytes(contentLength);
            Children = formatParser.ParseChunks(childrenLength);

            TotalBytes = formatParser.CurrentOffset;
        }
예제 #2
0
 public static ChunkType GetChunkId(byte[] chunkData)
 {
     return(ChunkTypeMapping.GetChunkId(new string(Helper.GetCharArray(chunkData, 0, 4))));
 }