encoder-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 encoder state. */
/* Saved state. */
MTE_UINT8_T* e_saved = MTE_ALLOCA(mte_mke_enc_save_bytes(encoder));
status = mte_mke_enc_state_save(encoder, e_saved);
if (status != mte_status_success)
{
fputs("Encoder state save error.", stderr);
return mte_status_unsupported;
}
Restore state.
/* Restore the encoder state. */
status = mte_mke_enc_state_restore(encoder, e_saved);
if (status != mte_status_success)
{
fprintf(stderr, "Encoder 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 encoder state.
size_t eSavedBytes = 0;
const void* esaved = encoder.saveState(eSavedBytes);
if (esaved == NULL)
{
std::cerr << "Encoder state save error." << std::endl;
return mte_status_unsupported;
}
Restore state.
// Restore the encoder state.
status = encoder.restoreState(esaved);
if (status != mte_status_success)
{
std::cerr << "Encoder state restore error." << std::endl;
return status;
}
// Save and restore Encoder state with bytes
// Get byte[] of Encoder state
byte[] encoderByteState = mkeEncoder.SaveState();
// Restore Encoder with byte[] state
MteStatus encoderStatus = mkeEncoder.RestoreState(encoderByteState);
if(encoderStatus != MteStatus.mte_status_success)
{
// Mte cannot continue, handle restore failure appropriately
// Below is only an example
throw new Exception("Failed to restore Encoder state. Status: "
+ mkeEncoder.GetStatusName(encoderStatus)+ " / "
+ mkeEncoder.GetStatusDescription(encoderStatus));
}
// Save and restore Encoder state with string
// Get string of Encoder state
string encoderStrState = mkeEncoder.SaveStateB64();
// Restore Encoder with string state
MteStatus encoderStatus = mkeEncoder.RestoreStateB64(encoderStrState);
if(encoderStatus != MteStatus.mte_status_success)
{
// Mte cannot continue, handle restore failure appropriately
// Below is only an example
throw new Exception("Failed to restore Encoder state. Status: "
+ mkeEncoder.GetStatusName(encoderStatus)+ " / "
+ mkeEncoder.GetStatusDescription(encoderStatus));
}
// Save and restore Encoder state with bytes
// Get byte[] of Encoder state
byte[] encoderByteState = mkeEncoder.saveState();
// Restore Encoder with byte[] state
MteStatus encoderStatus = mkeEncoder.restoreState(encoderByteState);
if(encoderStatus != MteStatus.mte_status_success)
{
// Mte cannot continue, handle restore failure appropriately
// Below is only an example
throw new Exception("Failed to restore Encoder state. Status: "
+ MteBase.getStatusName(encoderStatus)+ " / "
+ MteBase.getStatusDescription(encoderStatus));
}
// Save and restore Encoder state with bytes
// Get string of Encoder state
string encoderStrState = mkeEncoder.saveStateB64();
// Restore Encoder with string state
MteStatus encoderStatus = mkeEncoder.restoreStateB64(encoderStrState);
if(encoderStatus != MteStatus.mte_status_success)
{
// Mte cannot continue, handle restore failure appropriately
// Below is only an example
throw new Exception("Failed to restore Encoder state. Status: "
+ MteBase.getStatusName(encoderStatus)+ " / "
+ MteBase.getStatusDescription(encoderStatus));
}
// Save and restore Encoder state with bytes
// Get Uint8Array of Encoder state
const state = mkeEncoder.saveState();
// Restore Encoder with Uint8Array state
const encoderStatus = mkeEncoder.restoreState(state);
if (encoderStatus !== MteStatus.mte_status_success) {
// MTE cannot continue so handle failure appropriately
// Below is an Example
const status = mteBase.getStatusName(encoderStatus);
const message = mteBase.getStatusDescription(encoderStatus);
throw new Error(`Error instantiating MKE Encoder.\n${status}: ${message}`);
}
// Save and restore Encoder state with string
// Get string of Encoder state
const state = mkeEncoder.saveStateB64();
// Restore Encoder with string state
const encoderStatus = mkeEncoder.restoreStateB64(state);
if (encoderStatus !== MteStatus.mte_status_success) {
// MTE cannot continue so handle failure appropriately
// Below is an Example
const status = mteBase.getStatusName(encoderStatus);
const message = mteBase.getStatusDescription(encoderStatus);
throw new Error(`Error instantiating MKE Encoder.\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 encoder state.
let esaved = encoder.saveState()
if esaved == nil {
print("Encoder state save error.")
return Int32(mte_status_unsupported.rawValue)
}
# Save and restore Encoder state with bytes.
# Get byte[] of Encoder state.
encoder_byte_state = mke_encoder.save_state()
# Restore Encoder with byte[] state.
encoder_status = mke_encoder.restore_state(encoder_byte_state)
if encoder_status != MteStatus.mte_status_success:
# Mte cannot continue, handle restore failure appropriately.
# Below is only an example.
raise Exception("Failed to restore Encoder state. Status: {0} / {1}\n".format(MteBase.get_status_name(encoder_status),
MteBase.get_status_description(encoder_status)))
# Save and restore Encoder state with string.
# Get string of Encoder state.
encoder_str_state = mke_encoder.save_state_b64()
# Restore Encoder with string state.
encoder_status = mke_encoder.restore_state_b64(encoder_str_state)
if encoder_status != MteStatus.mte_status_success:
# Mte cannot continue, handle restore failure appropriately.
# Below is only an example.
raise Exception("Failed to restore Encoder state. Status: {0} / {1}\n".format(MteBase.get_status_name(encoder_status),
MteBase.get_status_description(encoder_status)))
// Save and restore MKE Encoder state with bytes
// Get byte[] of Encoder state
encoderByteState := mkeEncoder.SaveState()
encoderStatus := mkeEncoder.RestoreState(encoderByteState);
if(encoderStatus != mte.Status_mte_status_success){
// Handle Encoder restore state failure appropriately
// Below is only an example
fmt.Fprintf(os.Stderr, "Restore Encoder state error (%v): %v\n",
mte.GetStatusName(encoderStatus), mte.GetStatusDescription(encoderStatus))
return int(encoderStatus)
}
// Save and restore MKE Encoder state with bytes
// Get byte[] of Encoder state
encoderStrState := mkeEncoder.SaveStateB64()
encoderStatus := mkeEncoder.RestoreStateB64(encoderStrState);
if(encoderStatus != mte.Status_mte_status_success){
// Handle Encoder restore state failure appropriately
// Below is only an example
fmt.Fprintf(os.Stderr, "Restore Encoder state error (%v): %v\n",
mte.GetStatusName(encoderStatus), mte.GetStatusDescription(encoderStatus))
return int(encoderStatus)
}
<?php
$encoderStrState = $mkeEncoder->saveState();
$restoreStatus = $mkeEncoder->restoreState($encoderStrState);
if (constant($restoreStatus)!=mte_status_success){
// Handle an error here -- below is a sample
echo "Encoder restore state error: "
.$mkeEncoder->getStatusName(constant($restoreStatus)).":"
.$mkeEncoder->getStatusDescription(constant($restoreStatus));
return $mkeEncoder->getStatusCode(constant($restoreStatus));
}
?>
<?php
$encoderB64State = $mkeEncoder->saveStateB64();
$restoreStatus = $mkeEncoder->restoreStateB64($encoderB64State);
if (constant($restoreStatus)!=mte_status_success){
// Handle an error here -- below is a sample
echo "Encoder restore base64 state error: "
.$mkeEncoder->getStatusName(constant($restoreStatus)).":"
.$mkeEncoder->getStatusDescription(constant($restoreStatus));
return $mkeEncoder->getStatusCode(constant($restoreStatus));
}
?>