static size_t DecodeSeqHeaders()

in csharp/src/ZStdDecompress.cs [1110:1180]


		static size_t DecodeSeqHeaders(ZSTD_DCtx dctx, int* nbSeqPtr, void* src, size_t srcSize)
		{
			BYTE* istart = (BYTE*)src;
			BYTE* iend = istart + srcSize;
			BYTE* ip = istart;

			/* check */
			if (srcSize < MIN_SEQUENCES_SIZE) return ERROR(Error.srcSize_wrong);

			/* SeqHead */
			{
				int nbSeq = *ip++;
				if (nbSeq == 0) { *nbSeqPtr = 0; return 1; }
				if (nbSeq > 0x7F)
				{
					if (nbSeq == 0xFF)
					{
						if (ip + 2 > iend) return ERROR(Error.srcSize_wrong);
						nbSeq = (int)MEM_readLE16(ip) + LONGNBSEQ; ip += 2;
					}
					else
					{
						if (ip >= iend) return ERROR(Error.srcSize_wrong);
						nbSeq = ((nbSeq - 0x80) << 8) + *ip++;
					}
				}
				*nbSeqPtr = nbSeq;
			}

			/* FSE table descriptors */
			if (ip + 4 > iend) return ERROR(Error.srcSize_wrong); /* minimum possible size */
			{
				symbolEncodingType_e LLtype = (symbolEncodingType_e)(*ip >> 6);
				symbolEncodingType_e OFtype = (symbolEncodingType_e)((*ip >> 4) & 3);
				symbolEncodingType_e MLtype = (symbolEncodingType_e)((*ip >> 2) & 3);
				ip++;

				/* Build DTables */
				{
					size_t llhSize = BuildSeqTable(dctx.entropy.LLTable, ref dctx.LLTptr,
															  LLtype, MaxLL, LLFSELog,
															  ip, (size_t)(iend - ip),
															  LL_base, LL_bits,
															  LL_defaultDTable, dctx.fseEntropy);
					if (IsError(llhSize)) return ERROR(Error.corruption_detected);
					ip += llhSize;
				}

				{
					size_t ofhSize = BuildSeqTable(dctx.entropy.OFTable, ref dctx.OFTptr,
															  OFtype, MaxOff, OffFSELog,
															  ip, (size_t)(iend - ip),
															  OF_base, OF_bits,
															  OF_defaultDTable, dctx.fseEntropy);
					if (IsError(ofhSize)) return ERROR(Error.corruption_detected);
					ip += ofhSize;
				}

				{
					size_t mlhSize = BuildSeqTable(dctx.entropy.MLTable, ref dctx.MLTptr,
															  MLtype, MaxML, MLFSELog,
															  ip, (size_t)(iend - ip),
															  ML_base, ML_bits,
															  ML_defaultDTable, dctx.fseEntropy);
					if (IsError(mlhSize)) return ERROR(Error.corruption_detected);
					ip += mlhSize;
				}
			}

			return (size_t)(ip - istart);
		}