Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serde Feature #14

Open
osiler opened this issue Jun 4, 2023 · 0 comments
Open

Serde Feature #14

osiler opened this issue Jun 4, 2023 · 0 comments

Comments

@osiler
Copy link

osiler commented Jun 4, 2023

Hi,

I was wondering if it would be a good idea to serdify some of the constants and settings that the aravis bindings are generating.

While the genicam standard does provide the information from most gige cameras (my use case), application settings for developers are likely to be co-located in one place (yaml, json, toml).

An example of some of the pixel formats below.

use aravis::PixelFormat;
use serde::{Deserialize, de::Visitor};

#[derive(Copy, Clone)]
pub struct CameraPixelFormat(pub PixelFormat);

impl<'de> Deserialize<'de> for CameraPixelFormat {
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        deserializer.deserialize_str(PixelFormatVisitor {})
    }
}

pub struct PixelFormatVisitor {}

impl<'de> Visitor<'de> for PixelFormatVisitor {
    type Value = CameraPixelFormat;

    fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
        formatter.write_str("Could not deserialise CameraPixelFormat")
    }

    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
        where
            E: serde::de::Error, {

       match v {
            "RGB_8_PACKER" => Ok(CameraPixelFormat(PixelFormat::RGB_8_PACKED)),
            "BAYER_RG_8" => Ok(CameraPixelFormat(PixelFormat::BAYER_RG_8)),
            "RGB_8_PLANAR" => Ok(CameraPixelFormat(PixelFormat::RGB_8_PLANAR)),
            _ => Err(serde::de::Error::custom("Unknown pixel format {v:?}")),
        } 
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant