decoder-state
- C
- C++
- CSharp
- Java
- JavaScript
- Swift
- Python
- Go
- PHP
Save state.
/* There are different functions available to use depending on program needs.
* The versions with b64 in the function name involve base 64 conversion,
* suitable for protocols requiring a string representation.
* Otherwise the default will use raw bytes.
*/
/* Save the decoder state. */
/* Saved state. */
MTE_UINT8_T* d_saved = MTE_ALLOCA(mte_mke_dec_save_bytes(decoder));
status = mte_mke_dec_state_save(decoder, d_saved);
if (status != mte_status_success)
{
fputs("Decoder state save error.", stderr);
return mte_status_unsupported;
}
Restore state.
/* Restore the decoder state. */
status = mte_mke_dec_state_restore(decoder, d_saved);
if (status != mte_status_success)
{
fprintf(stderr, "Decoder state restore error (%s): %s\n",
mte_base_status_name(status),
mte_base_status_description(status));
return status;
}
Save state.
// There are different functions available to use depending on program needs.
// The versions with b64 in the function name involve base 64 conversion,
// suitable for protocols requiring a string representation.
// Otherwise the default will use raw bytes.
// Save the decoder state.
size_t dSavedBytes = 0;
const void* dsaved = decoder.saveState(dSavedBytes);
if (dsaved == NULL)
{
std::cerr << "Decoder state save error." << std::endl;
return mte_status_unsupported;
}
Restore state.
// Restore the decoder state.
status = decoder.restoreState(dsaved);
if (status != mte_status_success)
{
std::cerr << "Decoder state restore error." << std::endl;
return status;
}
// Save and restore Decoder state with bytes
// Get byte[] of decoder state
byte[] decoderByteState = mkeDecoder.SaveState();
// Restore Decoder with byte[] state
MteStatus decoderStatus = mkeDecoder.RestoreState(decoderByteState);
if(decoderStatus != MteStatus.mte_status_success)
{
// Mte cannot continue, handle restore failure appropriately
// Below is only an example
throw new Exception("Failed to restore Decoder state. Status: "
+ mkeDecoder.GetStatusName(decoderStatus)+ " / "
+ mkeDecoder.GetStatusDescription(decoderStatus));
}
// Save and restore Decoder state with string
// Get string of Decoder state
string decoderStrState = mkeDecoder.SaveStateB64();
// Restore Decoder with string state
MteStatus decoderStatus = mkeDecoder.RestoreStateB64(decoderStrState);
if(decoderStatus != MteStatus.mte_status_success)
{
// Mte cannot continue, handle restore failure appropriately
// Below is only an example
throw new Exception("Failed to restore Decoder state. Status: "
+ mkeDecoder.GetStatusName(decoderStrStatus)+ " / "
+ mkeDecoder.GetStatusDescription(decoderStrStatus));
}
// Save and restore Decoder state with bytes
// Get byte[] of Decoder state
byte[] decoderByteState = mkeDecoder.saveState();
// Restore Decoder with byte[] state
MteStatus decoderStatus = mkeDecoder.restoreState(decoderByteState);
if(decoderStatus != MteStatus.mte_status_success)
{
// Mte cannot continue, handle restore failure appropriately
// Below is only an example
throw new Exception("Failed to restore Decoder state. Status: "
+ MteBase.getStatusName(decoderStatus)+ " / "
+ MteBase.getStatusDescription(decoderStatus));
}
// Save and restore Decoder state with string
// Get string of Decoder state
string decoderStrState = mkeDecoder.saveStateB64();
// Restore Decoder with string state
MteStatus decoderStatus = mkeDecoder.restoreStateB64(decoderStrState);
if(decoderStatus != MteStatus.mte_status_success)
{
// Mte cannot continue, handle restore failure appropriately
// Below is only an example
throw new Exception("Failed to restore Decoder state. Status: "
+ MteBase.getStatusName(decoderStrStatus)+ " / "
+ MteBase.getStatusDescription(decoderStrStatus));
}
// Save and restore Decoder state with bytes
// Get Uint8Array of Decoder state
const state = mkeDecoder.saveState();
// Restore Decoder with Uint8Array state
const decoderStatus = mkeDecoder.restoreState(state);
if (decoderStatus !== MteStatus.mte_status_success) {
// MTE cannot continue so handle failure appropriately
// Below is an Example
const status = mteBase.getStatusName(decoderStatus);
const message = mteBase.getStatusDescription(decoderStatus);
throw new Error(`Error instantiating MKE Decoder.\n${status}: ${message}`);
}
// Save and restore Decoder state with bytes
// Get Uint8Array of Decoder state
const state = mkeDecoder.saveStateB64();
// Restore Decoder with Uint8Array state
const decoderStatus = mkeDecoder.restoreStateB64(state);
if (decoderStatus !== MteStatus.mte_status_success) {
// MTE cannot continue so handle failure appropriately
// Below is an Example
const status = mteBase.getStatusName(decoderStatus);
const message = mteBase.getStatusDescription(decoderStatus);
throw new Error(`Error instantiating MKE Decoder.\n${status}: ${message}`);
}
// There are different functions available to use depending on program needs.
// The versions with b64 in the function name involve base 64 conversion,
// suitable for protocols requiring a string representation.
// Otherwise the default will use raw bytes.
// Save the decoder state.
let dsaved = decoder.saveState()
if dsaved == nil {
print("Decoder state save error.")
return Int32(mte_status_unsupported.rawValue)
}
# Save and restore Decoder state with bytes.
decoder_byte_state = mke_decoder.save_state()
# Restore Decoder with byte[] state.
decoder_status = mke_decoder.restore_state(decoder_byte_state)
if decoder_status != MteStatus.mte_status_success:
# Mte cannot continue, handle restore failure appropriately.
# Below is only an example.
raise Exception("Failed to restore Decoder state. Status: {0} / {1}\n".format(MteBase.get_status_name(decoder_status),
MteBase.get_status_description(decoder_status)))
# Save and restore Decoder state with string.
# Get string of Decoder state.
decoder_str_state = mke_decoder.save_state_b64()
# Restore Decoder with string state.
decoder_status = mke_decoder.restore_state_b64(decoder_str_state)
if decoder_status != MteStatus.mte_status_success:
# Mte cannot continue, handle restore failure appropriately.
# Below is only an example.
raise Exception("Failed to restore Decoder state. Status: {0} / {1}\n".format(MteBase.get_status_name(decoder_status),
MteBase.get_status_description(decoder_status)))
// Save and restore Decoder state with bytes
// Get byte[] of Decoder state
decoderByteState := mkeDecoder.SaveState()
decoderStatus := mkeDecoder.RestoreState(decoderByteState);
if(decoderStatus != mte.Status_mte_status_success){
// Handle deocder restore state failure appropriately
// Below is only an example
fmt.Fprintf(os.Stderr, "Restore Decoder state error (%v): %v\n",
mte.GetStatusName(decoderStatus), mte.GetStatusDescription(decoderStatus))
return int(decoderStatus)
}
// Save and restore Decoder state with bytes
// Get byte[] of Decoder state
decoderStrState := mkeDecoder.SaveStateB64()
decoderStatus := mkeDecoder.RestoreStateB64(decoderStrState);
if(decoderStatus != mte.Status_mte_status_success){
// Handle Decoder restore state failure appropriately
// Below is only an example
fmt.Fprintf(os.Stderr, "Restore Decoder state error (%v): %v\n",
mte.GetStatusName(decoderStatus), mte.GetStatusDescription(decoderStatus))
return int(decoderStatus)
}
<?php
$decoderStrState = $mkeDecoder->saveState();
$restoreStatus = $mkeDecoder->restoreState($decoderStrState);
if (constant($restoreStatus)!=mte_status_success){
// Handle an error here -- below is a sample
echo "Decoder restore state error: "
.$mkeDecoder->getStatusName(constant($restoreStatus)).":"
.$mkeDecoder->getStatusDescription(constant($restoreStatus));
return $mkeDecoder->getStatusCode(constant($restoreStatus));
}
?>
<?php
$decoderB64State = $mkeDecoder->saveStateB64();
$restoreStatus = $mkeDecoder->restoreStateB64($decoderB64State);
if (constant($restoreStatus)!=mte_status_success){
// Handle an error here -- below is a sample
echo "Decoder restore base64 state error: "
.$mkeDecoder->getStatusName(constant($restoreStatus)).":"
.$mkeDecoder->getStatusDescription(constant($restoreStatus));
return $mkeDecoder->getStatusCode(constant($restoreStatus));
}
?>