示例#1
0
 internal void HandleResult(BarcodeDecodeResult result)
 {
     if (Decoded != null)
     {
         Decoded.Invoke(this, result);
     }
 }
示例#2
0
    public static void decode3NoChecks(Decoded decoded, char [] data)
    {
        double [] table;

        table = getRevTable();
        decode3NoChecksTable(decoded, data, table);
    }
        public void decode()
        {
            //Read the instruction from IR
            string inst = IR;

            //Decode it's opcode to see if it's I, or R or J:
            string opcode = IR.Substring(0, 6);

            switch (opcode)
            {
            case "000000":
                //RFormat
                string funct = inst.Substring(26);
                instruction = Rformat[funct];

                break;

            case "000010":
                //J
                instruction = Jformat[opcode];
                break;

            case "000011":
                //J
                instruction = Jformat[opcode];
                //Jformat.TryGetValue(opcode, out instruction);
                break;

            case "010000":
                //Coproc1
                Terminate_Error.Invoke("COPROC Instructions aren't supported by simulator");
                break;

            case "010001":
                //Coproc2
                Terminate_Error.Invoke("COPROC Instructions aren't supported by simulator");
                break;

            case "010010":
                //Coproc3
                Terminate_Error.Invoke("COPROC Instructions aren't supported by simulator");
                break;

            //Coproc4
            case "010011":
                Terminate_Error.Invoke("COPROC Instructions aren't supported by simulator");
                break;

            default:
                //I instruction
                instruction = Iformat[opcode];
                //Iformat.TryGetValue(opcode, out instruction);
                break;
            }
            //Increment Clock;

            Decoded.Invoke();
        }
 public override void Encode(BinaryWriter writer)
 {
     if (Invalid)
     {
         Decoded.Encode(writer);
     }
     else
     {
         writer.Write(buffer, mapStart, byteCount);
     }
 }
示例#5
0
        public void html_encode()
        {
            Assert.Throws <ArgumentNullException>(() => StringExtensions.HtmlEncode(null));

            Assert.True(ReferenceEquals(string.Empty.HtmlEncode(), string.Empty));

            const string Decoded = "<p>5 is < 10 and > 1</p>";
            const string Encoded = "<p>5 is &lt; 10 and &gt; 1</p>";

            Assert.Equal(Decoded, Encoded.HtmlDecode());
            Assert.Equal(Decoded, Decoded.HtmlEncode().HtmlDecode());
        }
 public override EsfNode CreateCopy()
 {
     if (!Invalid)
     {
         return(new MemoryMappedRecordNode(Codec, buffer, mapStart + 1)
         {
             Name = this.Name
         });
     }
     else
     {
         return(Decoded.CreateCopy());
     }
 }
示例#7
0
    public static void decode3NoChecksTable(Decoded decoded, char [] data, double [] table)
    {
        double total, i, n, r;

        total = 0d;
        for (i = 0d; i < 4d; i = i + 1d)
        {
            n     = getNumber(data[(int)(4d - i - 1d)], table);
            total = total + n * Pow(2d, i * 6d);
        }

        for (i = 0d; i < 3d; i = i + 1d)
        {
            r = total % Pow(2d, 8d);
            decoded.data[(int)(3d - i - 1d)] = r;
            total = (total - r) / Pow(2d, 8d);
        }
    }
示例#8
0
    public static Decoded decode3table(char [] data, double [] table, bool [] validTable)
    {
        double  i, valid;
        Decoded decoded;

        decoded = new Decoded();
        /* Alloc r*/
        decoded.success      = false;
        decoded.data         = new double [3];
        decoded.errorMessage = "".ToCharArray();

        if (data.Length == 4d)
        {
            valid = 0d;
            for (i = 0d; i < 4d; i = i + 1d)
            {
                if (isValidBase64characterTable(data[(int)(i)], validTable))
                {
                    valid = valid + 1d;
                }
            }
            if (valid == 4d)
            {
                decode3NoChecksTable(decoded, data, table);
                decoded.success = true;
            }
            else
            {
                decoded.errorMessage = "Invalid character in input string.".ToCharArray();
                decoded.success      = false;
            }
        }
        else
        {
            decoded.errorMessage = "There must be exactly four characters in the input string.".ToCharArray();
            decoded.success      = false;
        }

        return(decoded);
    }
示例#9
0
    public static Decoded decode(char [] data)
    {
        bool done;

        char [] data4;
        double  quads, i, currentQuad, currentTriplet, padding;
        Decoded decoded3, decoded;

        double [] table;
        bool []   validTable;

        decoded = new Decoded();
        table   = getRevTable();
        /* Alloc 1*/
        validTable = getValidTable();
        /* Alloc 3*/
        padding = 0d;
        if (data.Length > 1d)
        {
            if (data[(int)(data.Length - 1d)] == '=')
            {
                padding = padding + 1d;
            }
        }
        /* TODO: Evaluate && left to right and stop if false?*/
        if (data.Length > 2d)
        {
            if (data[(int)(data.Length - 2d)] == '=')
            {
                padding = padding + 1d;
            }
        }
        quads = data.Length / 4d;

        /* TODO: Require init?*/
        /* Init*/
        decoded.data         = new double [(int)(quads * 3d - padding)];
        decoded.errorMessage = new char [0];
        decoded.success      = true;

        done = false;
        for (i = 0d; i < quads && !done; i = i + 1d)
        {
            data4          = new char [4];
            currentQuad    = i * 4d;
            currentTriplet = i * 3d;
            if (padding > 0d && (i + 1d) == quads)
            {
                if (padding == 2d)
                {
                    data4[0] = data[(int)(currentQuad + 0d)];
                    data4[1] = data[(int)(currentQuad + 1d)];
                    data4[2] = 'A';
                    data4[3] = 'A';
                }
                else if (padding == 1d)
                {
                    data4[0] = data[(int)(currentQuad + 0d)];
                    data4[1] = data[(int)(currentQuad + 1d)];
                    data4[2] = data[(int)(currentQuad + 2d)];
                    data4[3] = 'A';
                }
            }
            else
            {
                data4[0] = data[(int)(currentQuad + 0d)];
                data4[1] = data[(int)(currentQuad + 1d)];
                data4[2] = data[(int)(currentQuad + 2d)];
                data4[3] = data[(int)(currentQuad + 3d)];
            }
            decoded3 = decode3table(data4, table, validTable);
            if (decoded3.success)
            {
                if (padding > 0d && i + 1d == quads)
                {
                    if (padding == 2d)
                    {
                        decoded.data[(int)(currentTriplet + 0d)] = decoded3.data[0];
                    }
                    else if (padding == 1d)
                    {
                        decoded.data[(int)(currentTriplet + 0d)] = decoded3.data[0];
                        decoded.data[(int)(currentTriplet + 1d)] = decoded3.data[1];
                    }
                }
                else
                {
                    decoded.data[(int)(currentTriplet + 0d)] = decoded3.data[0];
                    decoded.data[(int)(currentTriplet + 1d)] = decoded3.data[1];
                    decoded.data[(int)(currentTriplet + 2d)] = decoded3.data[2];
                }
            }
            else
            {
                decoded.success      = false;
                decoded.errorMessage = decoded3.errorMessage;
                done = true;
            }
            delete(decoded3);
        }

        delete(table);
        /* Unalloc 1*/
        return(decoded);
    }
示例#10
0
        public async void DecodeAsync()
        {
            var(code, bytes) = await Task.Run(() => Decode());

            Decoded?.Invoke(this, new RSExtEventArgs(code, bytes, isNoised));
        }