Giter Site home page Giter Site logo

Comments (4)

XAMPPRocky avatar XAMPPRocky commented on July 28, 2024

Hello, no I believe it's a bug. I'm currently working on fixing it.

from rasn.

XAMPPRocky avatar XAMPPRocky commented on July 28, 2024

This should be fixed on the latest main. Feel free to re-open if you have a case that fails.

from rasn.

anthok avatar anthok commented on July 28, 2024

Reopening (don't think I can actually reopen the issue though) because I ran into a case that will encode properly, but can't decode.

use rasn::{types::*, *};

#[derive(AsnType, Decode, Encode, Debug, PartialEq, Clone)]
#[rasn(choice)]
pub enum ProtocolMessages {
    #[rasn(tag(0))]
    Message(MessagePDU),
}

#[derive(AsnType, Decode, Encode, Debug, PartialEq, Clone)]
pub struct MessagePDU {
    #[rasn(tag(0))]
    pub message_id: rasn::types::Integer,

    #[rasn(tag(1))]
    pub message_num: Option<rasn::types::Integer>,

    #[rasn(tag(2))]
    pub message_status: MessageStatus,
}

#[derive(AsnType, Decode, Encode, Debug, PartialEq, Clone)]
pub struct MessageStatus {
    #[rasn(tag(0))]
    #[rasn(choice)]
    pub message_class: MessageClass,

    #[rasn(tag(1))]
    pub status_id: Option<rasn::types::Integer>,

    #[rasn(tag(2))]
    #[rasn(choice)]
    pub status_enum: Option<MessageEnum>,
}

#[derive(AsnType, Decode, Encode, Debug, PartialEq, Clone)]
#[rasn(choice)]
pub enum MessageClass {
    #[rasn(tag(0))]
    Test1(rasn::types::Integer),

    #[rasn(tag(1))]
    Test2(rasn::types::Integer),
}

#[derive(AsnType, Decode, Encode, Debug, PartialEq, Clone)]
#[rasn(choice)]
pub enum MessageEnum {
    #[rasn(tag(0))]
    Hello(rasn::types::Integer),

    #[rasn(tag(1))]
    World(rasn::types::Integer),

    #[rasn(tag(2))]
    Test(rasn::types::Integer),
}

#[test]
fn it_works() {
    let data = ProtocolMessages::Message(MessagePDU {
        message_id: 0.into(),
        message_num: None, 
        message_status: MessageStatus{
            message_class: MessageClass::Test1(0.into()),
            status_id: None,
            status_enum: None,
        }
    });

    let bin = rasn::ber::encode(&data).unwrap();
    assert_eq!(data, rasn::ber::decode(&bin).unwrap());
}

from rasn.

XAMPPRocky avatar XAMPPRocky commented on July 28, 2024

Thank you for the test case! I'll work on fixing it. By the way, if you are interested I would be open to adding IEC standards (ie rasn-iec61850) crates under standards like SNMP. This would be shared on crates.io under Apache / MIT for everyone, and can be part of test suite to make sure it always passes.

from rasn.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.