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: capnp_splitter.rs
    path of file: ./repos/flowgger/src/flowgger/splitter
    
    the code of the file until where you have to start completion: use super::Splitter;
use crate::flowgger::decoder::Decoder;
use crate::flowgger::encoder::Encoder;
use crate::flowgger::record::{Record, SDValue, StructuredData, FACILITY_MAX, SEVERITY_MAX};
use crate::record_capnp;
use capnp;
use capnp::message::ReaderOptions;
use std::io::{stderr, BufReader, Read, Write};
use std::sync::mpsc::SyncSender;
use std::thread;
use std::time::Duration;

pub struct CapnpSplitter;

impl<T: Read> Splitter<T> for CapnpSplitter {
    fn run(
        &self,
        buf_reader: BufReader<T>,
        tx: SyncSender<Vec<u8>>,
        _decoder: Box<dyn Decoder>,
        encoder: Box<dyn Encoder>,
    ) {
        let mut buf_reader = buf_reader;
        loop {
            let message_reader =
                match capnp::serialize::read_message(&mut buf_reader, ReaderOptions::new()) {
                    Err(e) => match e.kind {
                        capnp::ErrorKind::Failed | capnp::ErrorKind::Unimplemented => {
                            let _ = writ
    
fn handle_message(message: record_capnp::record::Reader) -> Result<Record, &'static str> {
    let ts = message.get_ts();
    if ts.is_nan() || ts <= 0.0 {
        return Err("Missing timestamp");
    }
    let hostname = message
        .get_hostname()
        .and_then(|x| Ok(x.to_owned()))
        .or(Err("Missing host name"))?;
    let facility = match message.get_facility() {
        facility if facility <= FACILITY_MAX => Some(facility),
        _ => None,
    };
    let severity = match message.get_severity() {
        severity if severity <= SEVERITY_MAX => Some(severity),
        _ => None,
    };
    let appname = message.get_appname().and_then(|x| Ok(x.to_owned())).ok();
    let procid = message.get_procid().and_then(|x| Ok(x.to_owned())).ok();
    let msgid = message.get_msgid().and_then(|x| Ok(x.to_owned())).ok();
    let msg = message.get_msg().and_then(|x| Ok(x.to_owned())).ok();
    let full_msg = message.get_full_msg().and_then(|x| Ok(x.to_owned())).ok();
    let sd = get_sd(message)?;
    Ok(Record {
        ts,
        hostname,
        facility,
        severity,
        appname,
        procid,
        msgid,
        msg,
        full_msg,
        sd,
    })
}