Skip to main content

async

//For this sample sequence window is being set to -2
MteDec decoderA = new MteDec(0, -2);

// Instantiate the Decoder
decoderA.SetEntropy(entropy);
decoderA.SetNonce(0);
status = decoderA.Instantiate(personal);

if (status != MteStatus.mte_status_success) {
Console.Error.WriteLine("Decoder instantiate error ({0}): {1}",
decoderV.GetStatusName(status),
decoderV.GetStatusDescription(status));
return (int)status;
}

// Save the async Decoder state.
byte[] dsaved = decoderA.SaveState();

// String to decode to.
string decoded;

// Create the corrupt version of message #2.
// Doing this so we can intentionally fail
char first = encodings[2][0];
++first;
string corrupt =
encodings[2].Substring(1).Insert(0, new string(first, 1));

// Output that decoding is in Async sequencing mode
Console.WriteLine("\nAsync mode (sequence window = -2):");

// Decode the first message
// Output: Decode #1: mte_status_success, message 1
decoded = decoderA.DecodeStrB64(encodings[0], out status);
Console.WriteLine("Decode #0: {0}, {1}",
decoderA.GetStatusName(status),
decoded);

// Try to decode the first message again -- out of sequence, should not work
// Output: Decode #0: mte_status_seq_outside_window,
decoded = decoderA.DecodeStrB64(encodings[0], out status);
Console.WriteLine("Decode #1: {0}, {1}",
decoderA.GetStatusName(status),
decoded);

// Try to decode the corrupted second message -- should not work
// Output: Corrupt #3: mte_status_seq_mismatch,
decoded = decoderA.DecodeStrB64(corrupt, out status);
Console.WriteLine("Corrupt #3: {0}, {1}",
decoderA.GetStatusName(status),
decoded);

// Decode third message
// Output: Decode #3: mte_status_success, message 3
decoded = decoderA.DecodeStrB64(encodings[2], out status);
Console.WriteLine("Decode #3: {0}, {1}",
decoderA.GetStatusName(status),
decoded);

// Decode second message (async should work because we have NOT decoded yet)
// Output: Decode #2: mte_status_success, message 2
decoded = decoderA.DecodeStrB64(encodings[1], out status);
Console.WriteLine("Decode #2: {0}, {1}",
decoderA.GetStatusName(status),
decoded);


// Decode third message again (since after message 1 and 2 different error)
// Output: Decode #3: mte_status_seq_outside_window,
decoded = decoderA.DecodeStrB64(encodings[2], out status);
Console.WriteLine("Decode #3: {0}, {1}",
decoderA.GetStatusName(status),
decoded);

// Decode fourth message
// Output: Decode #4: mte_status_success, message 4
decoded = decoderA.DecodeStrB64(encodings[3], out status);
Console.WriteLine("Decode #4: {0}, {1}",
decoderA.GetStatusName(status),
decoded);

// Restore and decode again in a different order.
decoderA.RestoreState(dsaved);
Console.WriteLine("\nAsync mode (sequence window = -2):");

// Decode fourth message first
// Output: Decode #4: mte_status_success, message 4
decoded = decoderA.DecodeStrB64(encodings[3], out status);
Console.WriteLine("Decode #4: {0}, {1}",
decoderA.GetStatusName(status),
decoded);

// Decode first message (error - sequence window too large)
// Output: Decode #1: mte_status_seq_outside_window,
decoded = decoderA.DecodeStrB64(encodings[0], out status);
Console.WriteLine("Decode #1: {0}, {1}",
decoderA.GetStatusName(status),
decoded);

// Decode third message (inside sequence window)
// Output: Decode #3: mte_status_success, message 3
decoded = decoderA.DecodeStrB64(encodings[2], out status);
Console.WriteLine("Decode #3: {0}, {1}",
decoderA.GetStatusName(status),
decoded);

// Decode non-corrupted second message (still inside sequence window)
// Output: Decode #2: mte_status_success, message 2
decoded = decoderA.DecodeStrB64(encodings[1], out status);
Console.WriteLine("Decode #2: {0}, {1}",
decoderA.GetStatusName(status),
decoded);