Exemplo n.º 1
0
        internal static EncodationStruct Encode(string content, ErrorCorrectionLevel ecLevel)
        {
            RecognitionStruct recognitionResult = InputRecognise.Recognise(content);
            EncoderBase       encoderBase       = CreateEncoder(recognitionResult.EncodingName);

            BitList encodeContent = encoderBase.GetDataBits(content);

            int encodeContentLength = encodeContent.Count;

            VersionControlStruct vcStruct =
                VersionControl.InitialSetup(encodeContentLength, ecLevel, recognitionResult.EncodingName);

            BitList dataCodewords = new BitList();

            // Eci header
            if (vcStruct.IsContainECI && !(vcStruct.ECIHeader is null))
            {
                dataCodewords.Add(vcStruct.ECIHeader);
            }

            // Header
            dataCodewords.Add(encoderBase.GetModeIndicator());
            int numLetter = encodeContentLength >> 3;

            dataCodewords.Add(encoderBase.GetCharCountIndicator(numLetter, vcStruct.VersionDetail.Version));

            // Data
            dataCodewords.Add(encodeContent);

            // Terminator Padding
            dataCodewords.TerminateBites(dataCodewords.Count, vcStruct.VersionDetail.NumDataBytes);

            int dataCodewordsCount = dataCodewords.Count;

            if ((dataCodewordsCount & 0x7) != 0)
            {
                throw new ArgumentException($"{nameof(dataCodewords)} is not byte sized.");
            }
            else if (dataCodewordsCount >> 3 != vcStruct.VersionDetail.NumDataBytes)
            {
                throw new ArgumentException($"{nameof(dataCodewords)} num of bytes not equal to {nameof(vcStruct.VersionDetail.NumDataBytes)} for current version");
            }

            var encStruct = new EncodationStruct(vcStruct)
            {
                DataCodewords = dataCodewords
            };

            return(encStruct);
        }
Exemplo n.º 2
0
        internal static EncodationStruct Encode(string content, ErrorCorrectionLevel ecLevel)
        {
            RecognitionStruct recognitionResult = InputRecognise.Recognise(content);
            EncoderBase       encoderBase       = CreateEncoder(recognitionResult.EncodingName);

            BitList encodeContent = encoderBase.GetDataBits(content);

            int encodeContentLength = encodeContent.Count;

            VersionControlStruct vcStruct =
                VersionControl.InitialSetup(encodeContentLength, ecLevel, recognitionResult.EncodingName);

            BitList dataCodewords = new();

            // Eci header
            if (vcStruct.IsContainECI && vcStruct.ECIHeader is { })