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_flen_enc_save_bytes(encoder));
status = mte_flen_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_flen_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 = flenEncoder.SaveState();
// Restore Encoder with byte[] state
MteStatus encoderStatus = flenEncoder.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: "
+ flenEncoder.GetStatusName(encoderStatus)+ " / "
+ flenEncoder.GetStatusDescription(encoderStatus));
}
// Save and restore Encoder state with string
// Get string of Encoder state
string encoderStrState = flenEncoder.SaveStateB64();
// Restore Encoder with string state
MteStatus encoderStatus = flenEncoder.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: "
+ flenEncoder.GetStatusName(encoderStatus)+ " / "
+ flenEncoder.GetStatusDescription(encoderStatus));
}
// Save and restore Encoder state with bytes
// Get byte[] of Encoder state
byte[] encoderByteState = flenEncoder.saveState();
// Restore Encoder with byte[] state
MteStatus encoderStatus = flenEncoder.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));
}
// Restore Encoder with string state
// Get string of Encoder state
string encoderStrState = flenEncoder.saveStateB64();
// Restore Encoder with byte[] state
MteStatus encoderStatus = flenEncoder.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 Encoder state as Uint8Array
const state = flenEncoder.saveState();
// restore Encoder from Uint8Array
const encoderStatus = flenEncoder.restoreState(state);
if (encoderStatus !== MteStatus.mte_status_success) {
// MTE cannot continue, handle restore failure appropriately
// Below is only an example
throw new Error(
`Failed to restore Encoder state.` +
`Status: ${flenEncoder.GetStatusName(encoderStatus)} / ` +
`${flenEncoder.GetStatusDescription(encoderStatus)}`,
);
}
// Save Encoder state as Base64 String
const state = flenEncoder.saveStateB64();
// restore Encoder from Base64 state
const encoderState = flenEncoder.restoreStateB64(state);
if (encoderStatus !== MteStatus.mte_status_success) {
// MTE cannot continue, handle restore failure appropriately
// Below is only an example
throw new Error(
`Failed to restore Encoder state.` +
`Status: ${flenEncoder.GetStatusName(encoderStatus)} / ` +
`${flenEncoder.GetStatusDescription(encoderStatus)}`,
);
}
// 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 = flen_encoder.save_state()
# Restore Encoder with byte[] state.
encoder_status = flen_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 strin.g
# Get string of Encoder state.
encoder_str_state = flen_encoder.save_state_b64()
# Restore Encoder with string state.
encoder_status = flen_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 FLEN Encoder state with bytes
// Get byte[] of Encoder state
encoderByteState := flenEncoder.SaveState()
encoderStatus := flenEncoder.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 FLEN Encoder state with bytes
// Get byte[] of Encoder state
encoderStrState := flenEncoder.SaveStateB64()
encoderStatus := flenEncoder.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 = $flenEncoder->saveState();
$restoreStatus = $flenEncoder->restoreState($encoderStrState);
if (constant($restoreStatus)!=mte_status_success){
// Handle an error here -- below is a sample
echo "FLEN Encoder restore state error: "
.$flenEncoder->getStatusName(constant($restoreStatus)).":"
.$flenEncoder->getStatusDescription(constant($restoreStatus));
return $flenEncoder->getStatusCode(constant($restoreStatus));
}
?>
<?php
$encoderB64State = $flenEncoder->saveStateB64();
$restoreStatus = $flenEncoder->restoreStateB64($encoderB64State);
if (constant($restoreStatus)!=mte_status_success){
// Handle an error here -- below is a sample
echo "FLEN Encoder restore base64 state error: "
.$flenEncoder->getStatusName(constant($restoreStatus)).":"
.$flenEncoder->getStatusDescription(constant($restoreStatus));
return $flenEncoder->getStatusCode(constant($restoreStatus));
}
?>