ystero-dev / hampi

Rust ASN.1 Toolkit
Other
43 stars 18 forks source link

Possible to access value of key for variants? #96

Closed gth828r closed 1 year ago

gth828r commented 1 year ago

Thank you for your excellent work on this project!

I was wondering if it is possible to access the value of the key meta value for the asn attribute which gets defined in the generated code?

For example, in ngap code that I generated, I see this:

pub enum InitiatingMessageValue {
    #[asn(key = 64)]
    Id_AMFCPRelocationIndication(AMFCPRelocationIndication),
    #[asn(key = 0)]
    Id_AMFConfigurationUpdate(AMFConfigurationUpdate),
    #[asn(key = 1)]
    Id_AMFStatusIndication(AMFStatusIndication),
    #[asn(key = 2)]
...

When defining an NGAP_PDU, I need to explicitly set the procedure_code for an InitiatingMessage. Right now, I am just manually filling in the literal value like 64, but I am wondering if there is some way to just reference a key value for Id_AMFCPRelocationIndication from the generated code?

gabhijit commented 1 year ago

Hi @gth828r

Perhaps you are looking at accessing the constants with symbolic names rather than the values (when generating the message) -

here is an example of that. Is this what you are looking at? Like the constant ID_NG_SETUP. These constants are generated by the code already and can be included through the code generated using build.rs mechanism.

You can check whether the constant you need is indeed generated or not. It's possible some keys were missed in code generation and that support will be required to be added then.

gth828r commented 1 year ago

@gabhijit yes, that was exactly what I was looking for. Thanks for setting me straight!