pub fn encode(value: &DxValue) -> Result<Vec<u8>>Expand description
Encode a value with default config
Converts a DxValue into DX machine format bytes using default settings.
This is the inverse of parse().
§Example
use serializer::{encode, DxValue, DxObject};
let mut obj = DxObject::new();
obj.insert("name".to_string(), DxValue::String("Alice".to_string()));
obj.insert("age".to_string(), DxValue::Int(30));
let bytes = encode(&DxValue::Object(obj)).unwrap();§Errors
Returns a DxError in the following cases:
DxError::Io- Failed to write to the internal buffer. This is rare since encoding writes to an in-memoryVec<u8>, but can occur if memory allocation fails.
§Note
The encoding process is generally infallible for valid DxValue inputs.
The Result return type is used for consistency with the streaming
encode_to_writer() function and to handle potential I/O errors.