Skip to content

Commit

Permalink
Merge pull request #9 from librasn/feature/parameterization
Browse files Browse the repository at this point in the history
Feature/parameterization
  • Loading branch information
6d7a authored Apr 6, 2024
2 parents a481bb7 + bec393a commit cb06687
Show file tree
Hide file tree
Showing 30 changed files with 2,172 additions and 765 deletions.
301 changes: 132 additions & 169 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion rasn-compiler-derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ authors = ["Kevin Westphal"]
proc-macro = true

[dependencies]
rasn-compiler = "0.1.0"
rasn-compiler = { path = "../rasn-compiler" }
proc-macro2 = "1"
syn= "2"
2 changes: 1 addition & 1 deletion rasn-compiler-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ readme.workspace = true
[dependencies]
rasn-compiler-derive = { path = "../rasn-compiler-derive" }
rasn-compiler = { path = "../rasn-compiler" }
rasn = "0.12.4"
rasn = { git = "https://github.com/librasn/rasn" }

[dev-dependencies]
bitvec = { version = "1" }
Expand Down
2 changes: 1 addition & 1 deletion rasn-compiler-tests/tests/edge_cases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ e2e_pdu!(
pub struct Test {
#[rasn(default = "test_int_default")]
pub int: IntWithDefault,
#[rasn(default = "test_r_enum_default")]
#[rasn(default = "test_r_enum_default", identifier = "enum")]
pub r_enum: EnumWithDefault,
}
impl Test {
Expand Down
1 change: 1 addition & 0 deletions rasn-compiler-tests/tests/information_objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ e2e_pdu!(
#[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq)]
#[rasn(automatic_tags)]
pub struct Actual {
#[rasn(identifier = "errorCode")]
pub error_code: ErrorCode,
pub parameter: Option<Any>,
}
Expand Down
12 changes: 6 additions & 6 deletions rasn-compiler-tests/tests/nested_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ e2e_pdu!(
Wrapping-Boolean ::= Test-Boolean
value Wrapping-Boolean ::= FALSE"#,
r#" #[derive(AsnType, Debug, Clone, Copy, Decode, Encode, PartialEq)]
#[rasn(delegate)]
#[rasn(delegate, identifier = "Test-Boolean")]
pub struct TestBoolean(pub bool);
#[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq)]
#[rasn(delegate)]
#[rasn(delegate, identifier = "Wrapping-Boolean")]
pub struct WrappingBoolean(pub TestBoolean);
pub const VALUE: WrappingBoolean = WrappingBoolean(TestBoolean(false)); "#
Expand All @@ -23,11 +23,11 @@ e2e_pdu!(
Wrapping-Int ::= Test-Int (0..123)
value Wrapping-Int ::= 4"#,
r#" #[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[rasn(delegate, value("0..=123723"))]
#[rasn(delegate, value("0..=123723"), identifier = "Test-Int")]
pub struct TestInt(pub u32);
#[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq)]
#[rasn(delegate, value("0..=123"))]
#[rasn(delegate, value("0..=123"), identifier = "Wrapping-Int")]
pub struct WrappingInt(pub TestInt);
pub const VALUE: WrappingInt = WrappingInt(TestInt(4)); "#
Expand Down Expand Up @@ -90,11 +90,11 @@ e2e_pdu!(
Wrapping-Int ::= Test-Int (0..value)
value Test-Int ::= 5"#,
r#" #[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[rasn(delegate, value("0..=123723"))]
#[rasn(delegate, value("0..=123723"), identifier = "Test-Int")]
pub struct TestInt(pub u32);
#[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq)]
#[rasn(delegate, value("0..=5"))]
#[rasn(delegate, value("0..=5"), identifier = "Wrapping-Int")]
pub struct WrappingInt(pub TestInt);
pub const VALUE: TestInt = TestInt(5); "#
Expand Down
280 changes: 280 additions & 0 deletions rasn-compiler-tests/tests/parameterization.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,280 @@
use rasn_compiler_tests::e2e_pdu;

e2e_pdu! {
parameterized_type,
r#"
ParamType { INTEGER: lower, BOOLEAN: flag } ::= SEQUENCE {
int-value INTEGER (lower..12),
bool-value BOOLEAN DEFAULT flag
}
ImplType ::= ParamType { 2, TRUE }
"#,
r#"
#[derive (AsnType, Debug, Clone, Decode, Encode, PartialEq)]
#[rasn (automatic_tags)]
pub struct ImplType {
#[rasn(value("2..=12"), identifier = "int-value")]
pub int_value : u8,
#[rasn (default = "impl_type_bool_value_default", identifier = "bool-value")]
pub bool_value : bool,
}
impl ImplType {
pub fn new (int_value: u8 , bool_value: bool) -> Self {
Self { int_value , bool_value, }
}
}
fn impl_type_bool_value_default () -> bool {
true
}
"#
}

e2e_pdu! {
parameterized_information_object_classes,
r#"
NGAP-PROTOCOL-EXTENSION ::= CLASS {
&id INTEGER UNIQUE,
&criticality INTEGER,
&Extension,
&presence BOOLEAN
}
WITH SYNTAX {
ID &id
CRITICALITY &criticality
EXTENSION &Extension
PRESENCE &presence
}
ProtocolExtensionContainer {NGAP-PROTOCOL-EXTENSION : ExtensionSetParam} ::=
SEQUENCE (SIZE (1..maxProtocolExtensions)) OF
ProtocolExtensionField {{ExtensionSetParam}}
ProtocolExtensionField {NGAP-PROTOCOL-EXTENSION : ExtensionSetParam} ::= SEQUENCE {
id NGAP-PROTOCOL-EXTENSION.&id ({ExtensionSetParam}),
criticality NGAP-PROTOCOL-EXTENSION.&criticality ({ExtensionSetParam}{@id}),
extensionValue NGAP-PROTOCOL-EXTENSION.&Extension ({ExtensionSetParam}{@id})
}
A2X-PC5-FlowBitRates ::= SEQUENCE {
a2X-GuaranteedFlowBitRate BOOLEAN,
iE-Extensions ProtocolExtensionContainer { {A2X-PC5-FlowBitRates-ExtIEs} } OPTIONAL,
...
}
A2X-PC5-FlowBitRates-ExtIEs NGAP-PROTOCOL-EXTENSION ::= {
...
}
"#,
r#"
#[doc = " Anonymous SEQUENCE OF member "]
#[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq)]
#[rasn(automatic_tags, identifier = "SEQUENCE")]
pub struct AnonymousA2XPC5FlowBitRatesIEExtensions {
pub id: Integer,
pub criticality: Integer,
#[rasn(identifier = "extensionValue")]
pub extension_value: Any,
}
impl AnonymousA2XPC5FlowBitRatesIEExtensions {
pub fn new(id: Integer, criticality: Integer, extension_value: Any) -> Self {
Self {
id,
criticality,
extension_value,
}
}
}
impl AnonymousA2XPC5FlowBitRatesIEExtensions {
pub fn decode_extension_value<D: Decoder>(
&self,
decoder: &mut D,
) -> Result<A2XPC5FlowBitRatesExtIEs_Extension, D::Error> {
A2XPC5FlowBitRatesExtIEs_Extension::decode(
decoder,
Some(&self.extension_value),
&self.id,
)
}
}
#[doc = " Inner type "]
#[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq)]
#[rasn(delegate, size("1.."))]
pub struct A2XPC5FlowBitRatesIEExtensions(
pub SequenceOf<AnonymousA2XPC5FlowBitRatesIEExtensions>,
);
#[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq)]
#[rasn(automatic_tags, identifier = "A2X-PC5-FlowBitRates")]
#[non_exhaustive]
pub struct A2XPC5FlowBitRates {
#[rasn(identifier = "a2X-GuaranteedFlowBitRate")]
pub a2X__guaranteed_flow_bit_rate: bool,
#[rasn(size("1.."), identifier = "iE-Extensions")]
pub i_e__extensions: Option<SequenceOf<A2XPC5FlowBitRatesIEExtensions>>,
}
impl A2XPC5FlowBitRates {
pub fn new(
a2X__guaranteed_flow_bit_rate: bool,
i_e__extensions: Option<SequenceOf<A2XPC5FlowBitRatesIEExtensions>>,
) -> Self {
Self {
a2X__guaranteed_flow_bit_rate,
i_e__extensions,
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub enum A2XPC5FlowBitRatesExtIEs_Extension {}
impl A2XPC5FlowBitRatesExtIEs_Extension {
pub fn decode<D: Decoder>(
decoder: &mut D,
open_type_payload: Option<&Any>,
identifier: &Integer,
) -> Result<Self, D::Error> {
match identifier {
_ => Err(rasn::error::DecodeError::from_kind(
rasn::error::DecodeErrorKind::Custom {
msg: alloc::format!(
"Unknown unique identifier for information object class instance."
),
},
decoder.codec(),
)
.into()),
}
}
pub fn encode<E: Encoder>(
&self,
encoder: &mut E,
identifier: &Integer,
) -> Result<(), E::Error> {
match (self, identifier) {
_ => Err(rasn::error::EncodeError::from_kind(
rasn::error::EncodeErrorKind::Custom {
msg: alloc::format!(
"Unknown unique identifier for information object class instance."
),
},
encoder.codec(),
)
.into()),
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub enum A2XPC5FlowBitRatesExtIEs_criticality {}
impl A2XPC5FlowBitRatesExtIEs_criticality {
pub fn decode<D: Decoder>(
decoder: &mut D,
open_type_payload: Option<&Any>,
identifier: &Integer,
) -> Result<Self, D::Error> {
match identifier {
_ => Err(rasn::error::DecodeError::from_kind(
rasn::error::DecodeErrorKind::Custom {
msg: alloc::format!(
"Unknown unique identifier for information object class instance."
),
},
decoder.codec(),
)
.into()),
}
}
pub fn encode<E: Encoder>(
&self,
encoder: &mut E,
identifier: &Integer,
) -> Result<(), E::Error> {
match (self, identifier) {
_ => Err(rasn::error::EncodeError::from_kind(
rasn::error::EncodeErrorKind::Custom {
msg: alloc::format!(
"Unknown unique identifier for information object class instance."
),
},
encoder.codec(),
)
.into()),
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub enum A2XPC5FlowBitRatesExtIEs_id {}
impl A2XPC5FlowBitRatesExtIEs_id {
pub fn decode<D: Decoder>(
decoder: &mut D,
open_type_payload: Option<&Any>,
identifier: &Integer,
) -> Result<Self, D::Error> {
match identifier {
_ => Err(rasn::error::DecodeError::from_kind(
rasn::error::DecodeErrorKind::Custom {
msg: alloc::format!(
"Unknown unique identifier for information object class instance."
),
},
decoder.codec(),
)
.into()),
}
}
pub fn encode<E: Encoder>(
&self,
encoder: &mut E,
identifier: &Integer,
) -> Result<(), E::Error> {
match (self, identifier) {
_ => Err(rasn::error::EncodeError::from_kind(
rasn::error::EncodeErrorKind::Custom {
msg: alloc::format!(
"Unknown unique identifier for information object class instance."
),
},
encoder.codec(),
)
.into()),
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub enum A2XPC5FlowBitRatesExtIEs_presence {}
impl A2XPC5FlowBitRatesExtIEs_presence {
pub fn decode<D: Decoder>(
decoder: &mut D,
open_type_payload: Option<&Any>,
identifier: &Integer,
) -> Result<Self, D::Error> {
match identifier {
_ => Err(rasn::error::DecodeError::from_kind(
rasn::error::DecodeErrorKind::Custom {
msg: alloc::format!(
"Unknown unique identifier for information object class instance."
),
},
decoder.codec(),
)
.into()),
}
}
pub fn encode<E: Encoder>(
&self,
encoder: &mut E,
identifier: &Integer,
) -> Result<(), E::Error> {
match (self, identifier) {
_ => Err(rasn::error::EncodeError::from_kind(
rasn::error::EncodeErrorKind::Custom {
msg: alloc::format!(
"Unknown unique identifier for information object class instance."
),
},
encoder.codec(),
)
.into()),
}
}
}
"#
}
9 changes: 7 additions & 2 deletions rasn-compiler-tests/tests/parse_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,13 @@ fn compile_etsi() {
println!(
"{:?}",
Compiler::new()
.add_asn_by_path("../rasn-compiler/test_asn1/CAP.asn")
//.add_asn_by_path("./tests/modules/itu-t_x_x501_2001_EnhancedSecurity.asn1")
// .add_asn_by_path("../rasn-compiler/test_asn1/ngap_class.asn")
// .add_asn_by_path("../rasn-compiler/test_asn1/ngap_common.asn")
// .add_asn_by_path("../rasn-compiler/test_asn1/ngap_const.asn")
// .add_asn_by_path("../rasn-compiler/test_asn1/ngap_container.asn")
// .add_asn_by_path("../rasn-compiler/test_asn1/ngap_ies.asn")
// .add_asn_by_path("../rasn-compiler/test_asn1/ngap_pdus.asn")
.add_asn_by_path("../rasn-compiler/test_asn1/ngap_subset.asn")
.set_output_path("./tests")
.compile()
);
Expand Down
Loading

0 comments on commit cb06687

Please sign in to comment.