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_dec_save_bytes(decoder));
status = mte_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_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 = mteDecoder.SaveState();
// Restore Decoder with byte[] state
MteStatus decoderStatus = mteDecoder.RestoreState(decoderByteState);
if(decoderStatus != MteStatus.mte_status_success)
{
// Decoder restore failed, handle appropriately
// Below is only an example
throw new Exception("Failed to restore Decoder state. Status: "
+ mteDecoder.GetStatusName(decoderStatus)+ " / "
+ mteDecoder.GetStatusDescription(decoderStatus));
}
// save and restore Decoder state with string
// Get string of Decoder state
string decoderStrState = mteDecoder.SaveStateB64();
// Restore Decoder with string state
MteStatus decoderStatus = mteDecoder.RestoreStateB64(decoderStrState);
if(decoderStatus != MteStatus.mte_status_success)
{
// Decoder restore failed, handle appropriately
// Below is only an example
throw new Exception("Failed to restore Decoder state. Status: "
+ mteDecoder.GetStatusName(decoderStrStatus)+ " / "
+ mteDecoder.GetStatusDescription(decoderStrStatus));
}
// Save and restore Decoder state with bytes
// Get byte[] of decoder state
byte[] decoderByteState = mteDecoder.saveState();
// Restore Decoder with byte[] state
MteStatus decoderStatus = mteDecoder.restoreState(decoderByteState);
if(decoderStatus != MteStatus.mte_status_success)
{
// Decoder restore failed, handle 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 = mteDecoder.saveStateB64();
// Restore Decoder with string state
MteStatus decoderStatus = mteDecoder.restoreStateB64(decoderStrState);
if(decoderStatus != MteStatus.mte_status_success)
{
// Decoder restore failed, handle appropriately
// Below is only an example
throw new Exception("Failed to restore Decoder state. Status: "
+ MteBase.getStatusName(decoderStrStatus)+ " / "
+ MteBase.getStatusDescription(decoderStrStatus));
}
// save Decoder state as Uint8Array
let state = mteDecoder.saveState();
// restore Decoder from Uint8Array
mteDecoder.restoreState(state);
// save Decoder state as Base64 String
const state = mteDecoder.saveStateB64();
// restore Decoder from Base64 state
mteDecoder.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 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 = mte_decoder.save_state()
# Restore Decoder with byte[] state.
decoder_status = mte_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 = mte_decoder.save_state_b64()
# Restore Decoder with string state.
decoder_status = mte_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 := mteDecoder.SaveState()
decoderStatus := mteDecoder.RestoreState(decoderByteState);
if(decoderStatus != mte.Status_mte_status_success){
// Handle Decoder restore 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 := mteDecoder.SaveStateB64()
decoderStatus := mteDecoder.RestoreStateB64(decoderStrState);
if(decoderStatus != mte.Status_mte_status_success){
// Handle Decoder restore 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 = $mteDecoder->saveState();
$restoreStatus = $mteDecoder->restoreState($decoderStrState);
if (constant($restoreStatus)!=mte_status_success){
// Handle an error here -- below is a sample
echo "Decoder restore state error: "
.$mteDecoder->getStatusName(constant($restoreStatus)).":"
.$mteDecoder->getStatusDescription(constant($restoreStatus));
return $mteDecoder->getStatusCode(constant($restoreStatus));
}
?>
<?php
$decoderB64State = $mteDecoder->saveStateB64();
$restoreStatus = $mteDecoder->restoreStateB64($decoderB64State);
if (constant($restoreStatus)!=mte_status_success){
// Handle an error here -- below is a sample
echo "Decoder restore base64 state error: "
.$mteDecoder->getStatusName(constant($restoreStatus)).":"
.$mteDecoder->getStatusDescription(constant($restoreStatus));
return $mteDecoder->getStatusCode(constant($restoreStatus));
}
?>