emp/decode/json.rs
1//! Decoding EMP bytecode into json data
2
3use crate::decode;
4use crate::errors;
5use crate::value;
6use serde_json;
7
8/// Decodes EMP bytecode data into serde_json values
9///
10/// If an error is encountered the function will just return `serde_json::Value::Null`
11pub fn decode_json(val: &[u8]) -> serde_json::Value {
12 return value::json::to_json(decode::decode_safe(val));
13}
14
15/// Decodes EMP bytecode data into serde_json values
16///
17/// If an error is encountered it will simply return the error
18pub fn decode_json_unsafe(val: &[u8]) -> Result<serde_json::Value, errors::DecodeError> {
19 return match decode::decode(val) {
20 Ok((v, _)) => Ok(value::json::to_json(v)),
21 Err(d) => Err(d),
22 };
23}