Skip to content

Commit

Permalink
Merge pull request #217 from v0-e/asn1-print
Browse files Browse the repository at this point in the history
asn1: Add print() method to asn1c wrapper
  • Loading branch information
riebl authored Jan 28, 2024
2 parents 275247e + 570558b commit 332387b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
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

0 comments on commit 332387b

Please sign in to comment.