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. */
MTE_UINT8_T* e_saved = MTE_ALLOCA(mte_enc_save_bytes(encoder));
status = mte_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_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 = mteEncoder.SaveState();
// Restore Encoder with byte[] state
MteStatus encoderStatus = mteEncoder.RestoreState(encoderByteState);
if(encoderStatus != MteStatus.mte_status_success)
{
// Encoder restore failed, handle appropriately
// Below is only an example
throw new Exception("Failed to restore Encoder state. Status: "
+ mteEncoder.GetStatusName(encoderStatus)+ " / "
+ mteEncoder.GetStatusDescription(encoderStatus));
}
// Save and restore Encoder state with string
// Get string of Encoder state
string encoderStrState = mteEncoder.SaveStateB64();
// Restore Encoder with string state
MteStatus encoderStatus = mteEncoder.RestoreStateB64(encoderStrState);
if(encoderStatus != MteStatus.mte_status_success)
{
// Encoder restore failed, handle appropriately
// Below is only an example
throw new Exception("Failed to restore encoder state. Status: "
+ mteEncoder.GetStatusName(encoderStatus)+ " / "
+ mteEncoder.GetStatusDescription(encoderStatus));
}
// Save and restore Encoder state with bytes
// Get byte[] of Encoder state
byte[] encoderByteState = mteEncoder.saveState();
// Restore Encoder with byte[] state
MteStatus encoderStatus = mteEncoder.restoreState(encoderByteState);
if(encoderStatus != MteStatus.mte_status_success)
{
// Encoder restore failed, handle 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 string
// Get string of Encoder state
String encoderStrState = mteEncoder.saveStateB64();
// Restore Encoder with string state
MteStatus encoderStatus = mteEncoder.restoreStateB64(encoderStrState);
if(encoderStatus != MteStatus.mte_status_success)
{
// Encoder restore failed, handle 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 = mteEncoder.saveState();
// restore Encoder from Uint8Array
mteEncoder.restoreState(state);
// save Encoder state as Base64 String
const state = mteEncoder.saveStateB64();
// restore Encoder from Base64 state
mteEncoder.restoreStateB64(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.
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 = mte_encoder.save_state()
# Restore Encoder with byte[] state.
encoder_status = mte_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 = mte_encoder.save_state_b64()
# Restore Encoder with string state.
encoder_status = mte_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 Encoder state with bytes
// Get byte[] of encoder state
encoderByteState := mteEncoder.SaveState()
encoderStatus := mteEncoder.RestoreState(encoderByteState);
if(encoderStatus != mte.Status_mte_status_success){
// Encoder restore failed, handle 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 Encoder state with bytes
// Get byte[] of Encoder state
encoderStrState := mteEncoder.SaveStateB64()
encoderStatus := mteEncoder.RestoreStateB64(encoderStrState);
if(encoderStatus != mte.Status_mte_status_success){
// Encoder restore failed, handle 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 = $mteEncoder->saveState();
$restoreStatus = $mteEncoder->restoreState($encoderStrState);
if (constant($restoreStatus)!=mte_status_success){
// Handle an error here -- below is a sample
echo "Encoder restore state error: "
.$mteEncoder->getStatusName(constant($restoreStatus)).":"
.$mteEncoder->getStatusDescription(constant($restoreStatus));
return $mteEncoder->getStatusCode(constant($restoreStatus));
}
?>
<?php
$encoderB64State = $mteEncoder->saveStateB64();
$restoreStatus = $mteEncoder->restoreStateB64($encoderB64State);
if (constant($restoreStatus)!=mte_status_success){
// Handle an error here -- below is a sample
echo "Encoder restore base64 state error: "
.$mteEncoder->getStatusName(constant($restoreStatus)).":"
.$mteEncoder->getStatusDescription(constant($restoreStatus));
return $mteEncoder->getStatusCode(constant($restoreStatus));
}
?>