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

asn1: Add print() method to asn1c wrapper #217

Merged
merged 1 commit into from
Jan 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions vanetza/asn1/asn1c_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ bool validate(asn_TYPE_descriptor_t& td, const void* t, std::string& error)
return ok;
}

int print(FILE* stream, asn_TYPE_descriptor_t& td, const void* t)
{
return asn_fprint(stream, &td, t);
}

std::size_t size_per(asn_TYPE_descriptor_t& td, const void* t)
{
asn_enc_rval_t ec;
Expand Down
21 changes: 21 additions & 0 deletions vanetza/asn1/asn1c_wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ void free(asn_TYPE_descriptor_t&, void*);
void* copy(asn_TYPE_descriptor_t&, const void*);
bool validate(asn_TYPE_descriptor_t&, const void*);
bool validate(asn_TYPE_descriptor_t&, const void*, std::string&);
int print(FILE* stream, asn_TYPE_descriptor_t&, const void*);
std::size_t size_per(asn_TYPE_descriptor_t&, const void*);
std::size_t size_oer(asn_TYPE_descriptor_t&, const void*);
ByteBuffer encode_per(asn_TYPE_descriptor_t&, const void*);
Expand Down Expand Up @@ -93,6 +94,26 @@ class asn1c_wrapper_common
return vanetza::asn1::validate(m_type, m_struct, error);
}

/**
* Print ASN.1 type to standard output
* \param stream Output stream
* \return 0 on success, -1 on error
*/
int print() const
{
return vanetza::asn1::print(stdout, m_type, m_struct);
}

/**
* Print ASN.1 type to some file stream
* \param stream Output stream
* \return 0 on success, -1 on error
*/
int print(FILE* stream) const
{
return vanetza::asn1::print(stream, m_type, m_struct);
}

/**
* Swap ASN.1 wrapper content
* \param other wrapper
Expand Down
6 changes: 6 additions & 0 deletions vanetza/asn1/tests/asn1c_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ TEST(asn1c_wrapper, validate) {
EXPECT_FALSE(msg.empty());
}

TEST(asn1c_wrapper, print) {
test_wrapper wrapper(asn_DEF_VanetzaTest);
OCTET_STRING_fromString(&wrapper->string, "1234");
EXPECT_EQ(wrapper.print(), 0);
}

TEST(asn1c_wrapper, encode) {
test_wrapper wrapper(asn_DEF_VanetzaTest);
OCTET_STRING_fromString(&wrapper->string, "1234");
Expand Down
Loading