You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: json_codec.rs
    path of file: ./repos/flutter-rs/flutter-engine/src/codec
    
    the code of the file until where you have to start completion: use log::error;
use serde_json::json;

use super::{MessageCodec, MethodCall, MethodCallResult, MethodCodec, Value};

pub struct JsonMethodCodec;

pub const JSON_CODEC: JsonMethodCodec = JsonMethodCodec {};

impl MethodCodec for JsonMethodCodec {
    fn decode_method_call(&self, buf: &[u8]) -> Option<MethodCall> {
        unsafe {
            let s = std::str::from_utf8_unchecked(buf);
            serde_json::from_str::<MethodCall>(s).ok()
        }
    }


    
    fn decode_envelope(&self, buf: &[u8]) -> Option<MethodCallResult> {
        unsafe {
            let s = std::str::from_utf8_unchecked(buf);
            let json: Value = serde_json::from_str(s).unwrap();
            if let Value::List(mut v) = json {
                if v.len() == 1 {
                    return Some(MethodCallResult::Ok(v.swap_remove(0)));
                } else if v.len() == 3 {
                    return Some(MethodCallResult::Err {
                        code: match &v[0] {
                            Value::String(s) => s.clone(),
                            _ => "".into(),
                        },
                        message: match &v[1] {
                            Value::String(s) => s.clone(),
                            _ => "".into(),
                        },
                        details: v.swap_remove(2),
                    });
                }
            }
            error!("Invalid envelope: {}", s);
            None
        }
    }