-
-
Notifications
You must be signed in to change notification settings - Fork 60
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
Representing Objects/Classes #91
Comments
@XAMPPRocky I would be happy to help with this design: it's a subject that I have spent a fair amount of time thinking about recently. |
@benmaddison I don't have any thoughts currently, as I've never quite wrapped my head around them. Though I guess the best reference right now is the |
The SMI I have created an example module demonstrating the use of an object class as a table constraint on an ASN.1 type, and an accompanying rust type/trait hierarchy to go with it. Take a look at the files in https://github.com/benmaddison/rasn/tree/object-classes-ideas/examples. |
@XAMPPRocky, I have made some progress on this today. Please take a look at the above branch, and let me know what you think? |
You'll find that in most codecs, the tag of choices should be the smallest tag of all possible variants for the purposes of canonical sorting. It might not matter in this case, but it's important in the general case for things like choices and sets, or even just optional fields in codecs like PER.
I think we can achieve this with separate traits, we have an object safe trait that operates on const _DYN_TEST: &[&dyn ObjectSafeAccess] = &[];
trait ObjectSafeAccess {
fn get_boxed(&self) -> Box<dyn Any>;
fn set_boxed(&mut self, value: Box<dyn Any>);
}
trait TypeSafeRead {
fn get_as<T: Any + Clone>(&self) -> Option<T>;
}
trait TypeSafeWrite {
fn set_as<T: Any>(&mut self, value: T);
}
impl TypeSafeRead for &dyn ObjectSafeAccess {
fn get_as<T: Any + Clone>(&self) -> Option<T> {
self.get_boxed().downcast().ok().map(|v| *v)
}
}
impl TypeSafeWrite for &mut dyn ObjectSafeAccess {
fn set_as<T: Any>(&mut self, value: T) {
self.set_boxed(Box::new(value))
}
}
I don't know if there's a way around that when writing a manual implementation, however I would love to see what you think this would look like if it was entirely declarative. Like pretend that there's a magical derive macro that implements everything we need for this, what would you want the syntax for declaring a class and objects to look like? |
That's a good question. I think I would use a function-style macro with a custom DSL rather than a derive for the info object definitions, and then extend the Something like: info_object! {
class FooType {
const(unique) ID: OctetString;
const DESCR: &'static str;
type Foo;
}
instance FtBar of FooType {
const(unique) ID: OctetString = OctetString::from_static(&[0x01]);
const DESCR: &'static str = "Bar";
type Foo = Integer;
}
instance FtBaz of FooType {
const(unique) ID: OctetString = OctetString::from_static(&[0x02]);
const DESCR: &'static str = "Baz";
type Foo = BitString;
}
set FooTypeSet of FooType {
FtBar,
FtBaz,
}
}
#[derive(Debug, Clone, PartialEq, Eq, AsnType, Encode, Decode)]
#[rasn(table(FooTypeSet))]
struct Foo<#[rasn(instance)] T> {
name: Utf8String,
#[rasn(field(id, key))]
foo_type,
data: T::Foo,
} Not sure about the attribute on the generic parameter declaration... is that even legal?! |
The only thing not legal here is the |
One of the things that needs a good representation the the rasn framework is defining and using Objects/Classes from ASN.1 in rasn.
The text was updated successfully, but these errors were encountered: