Samuel-Tyler / fast_ber

A C++11 ASN.1 BER Encoding and Decoding Library
Boost Software License 1.0
84 stars 11 forks source link

Guidance on how to create a choice #18

Closed HackerBaloo closed 3 years ago

HackerBaloo commented 4 years ago

testapp.zip In test.asn1 I have created a CHOICE named Msg, but I can't figure out how to instantiate a Msg of type SPARQLReq for example. I have tried to figure it out from the tests with no luck.

The class I get like this: fast_ber::TheTest::SPARQLReq<> req; is very nice and friendly.

Samuel-Tyler commented 4 years ago

Hey,

Thanks for trying the library!

Here's a few ways to do that:

#include "test.hpp"

int main()
{
    fast_ber::TheTest::Msg<> msg = fast_ber::TheTest::SPARQLReq<
                                    fast_ber::DoubleId<
                                        fast_ber::Id<fast_ber::Class::context_specific, 1>,
                                        fast_ber::ExplicitId<fast_ber::UniversalTag::sequence>>>{"Header", {}};

    fast_ber::TheTest::SPARQLReq<
        fast_ber::DoubleId<
            fast_ber::Id<fast_ber::Class::context_specific, 1>,
            fast_ber::ExplicitId<fast_ber::UniversalTag::sequence>>> request = {"Header 2", {}};

    fast_ber::TheTest::Msg<> msg2{absl::in_place_index_t<1>{}, request};

    fast_ber::TheTest::Msg<> msg3;
    msg3.emplace<1>(request);
    absl::get<1>(msg3).header = "Header 3";

    std::cout << msg << std::endl
              << msg2 << std::endl
              << msg3 << std::endl;
}

Compile:

g++ main.cpp -I. -I../3rd_party/abseil-cpp/ -I../include src/libfast_ber_lib.a 3rd_party/abseil-cpp/absl/types/libabsl_absl_bad_variant_access.a 3rd_party/abseil-cpp/absl/types/libabsl_absl_bad_optional_access.a 3rd_party/abseil-cpp/absl/time/libabsl_absl_time.a 3rd_party/abseil-cpp/absl/strings/libabsl_absl_strings.a 3rd_party/abseil-cpp/absl/base/libabsl_absl_base.a 3rd_party/abseil-cpp/absl/base/libabsl_absl_dynamic_annotations.a 3rd_party/abseil-cpp/absl/base/libabsl_absl_spinlock_wait.a -lpthread -lrt 3rd_party/abseil-cpp/absl/strings/libabsl_absl_strings_internal.a 3rd_party/abseil-cpp/absl/base/libabsl_absl_throw_delegate.a 3rd_party/abseil-cpp/absl/base/libabsl_absl_raw_logging_internal.a 3rd_party/abseil-cpp/absl/base/libabsl_absl_log_severity.a 3rd_party/abseil-cpp/absl/numeric/libabsl_absl_int128.a 3rd_party/abseil-cpp/absl/time/libabsl_absl_civil_time.a 3rd_party/abseil-cpp/absl/time/libabsl_absl_time_zone.a

Output:

./a.out 
{"header" : "Header", "query" : []}
{"header" : "Header 2", "query" : []}
{"header" : "Header 3", "query" : []}

I appreciate there is some ugliness in the templates needed here, I will work on reducing that in this case.

HackerBaloo commented 4 years ago

Thank you for your quick response, this will let me continue to try to switch our old compiler to yours. But as a reflection I find it a bit strange that I should have to supply the Id, the number 1, in this case, since that is already in the ASN1 definition. It would have been nice the Id was selectable by name instead. It would make it less error prone since we have a choice with around 130 different message types.

On Thu, 6 Feb 2020 at 16:04, Samuel-Tyler notifications@github.com wrote:

Hey,

Thanks for trying the library!

Here's a few ways to do that:

include "test.hpp"

int main() { fast_ber::TheTest::Msg<> msg = fast_ber::TheTest::SPARQLReq< fast_ber::DoubleId< fast_ber::Id<fast_ber::Class::context_specific, 1>, fast_ber::ExplicitId>>{"Header", {}};

fast_ber::TheTest::SPARQLReq<
    fast_ber::DoubleId<
        fast_ber::Id<fast_ber::Class::context_specific, 1>,
        fast_ber::ExplicitId<fast_ber::UniversalTag::sequence>>> request = {"Header 2", {}};

fast_ber::TheTest::Msg<> msg2{absl::in_place_index_t<1>{}, request};

fast_ber::TheTest::Msg<> msg3;
msg3.emplace<1>(request);
absl::get<1>(msg3).header = "Header 3";

std::cout << msg << std::endl
          << msg2 << std::endl
          << msg3 << std::endl;

}

Compile:

g++ main.cpp -I. -I../3rd_party/abseil-cpp/ -I../include src/libfast_ber_lib.a 3rd_party/abseil-cpp/absl/types/libabsl_absl_bad_variant_access.a 3rd_party/abseil-cpp/absl/types/libabsl_absl_bad_optional_access.a 3rd_party/abseil-cpp/absl/time/libabsl_absl_time.a 3rd_party/abseil-cpp/absl/strings/libabsl_absl_strings.a 3rd_party/abseil-cpp/absl/base/libabsl_absl_base.a 3rd_party/abseil-cpp/absl/base/libabsl_absl_dynamic_annotations.a 3rd_party/abseil-cpp/absl/base/libabsl_absl_spinlock_wait.a -lpthread -lrt 3rd_party/abseil-cpp/absl/strings/libabsl_absl_strings_internal.a 3rd_party/abseil-cpp/absl/base/libabsl_absl_throw_delegate.a 3rd_party/abseil-cpp/absl/base/libabsl_absl_raw_logging_internal.a 3rd_party/abseil-cpp/absl/base/libabsl_absl_log_severity.a 3rd_party/abseil-cpp/absl/numeric/libabsl_absl_int128.a 3rd_party/abseil-cpp/absl/time/libabsl_absl_civil_time.a 3rd_party/abseil-cpp/absl/time/libabsl_absl_time_zone.a

Output:

./a.out {"header" : "Header", "query" : []} {"header" : "Header 2", "query" : []} {"header" : "Header 3", "query" : []}

I appreciate there is some ugliness in the templates needed here, I will work on reducing that in this case.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Samuel-Tyler/fast_ber/issues/18?email_source=notifications&email_token=AAA5YCQTOC6NUTLEQLXOQCTRBQRGDA5CNFSM4KQ5LN2KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEK7RB7Q#issuecomment-582947070, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA5YCU2J62IW2TXCYHWHOTRBQRGDANCNFSM4KQ5LN2A .

--


Björn Carlsson Telefon 0704-10 69 77 Epost mailto://b.r.carlsson@gmail.com Blog http://hackerbaloo.blogspot.com/


Samuel-Tyler commented 4 years ago

If I add a conversion operator the type will be able to be assigned directly to the Choice. Let me see what I can do.

Please let me know what else I can do to help you with your translation.

Thanks

Samuel-Tyler commented 4 years ago

I have added the conversions to the devel branch.

The following is now possible:

#include "generated/test.hpp"

int main()
{
    fast_ber::TheTest::Msg<> msg;
    msg = fast_ber::TheTest::SPARQLReq<>{"Header", {}};
}

Let me know if that's what you were expecting

HackerBaloo commented 4 years ago

Thank you, much nicer. I will try it out today.

Samuel-Tyler commented 4 years ago

Great.

Please note that there are some changes in devel, so you may have to tweak your code.

Also note that to access the variant alternative you will still have to provide the full typnename of the alternative (including identifier), access by index or use fast_ber::visit

Very sorry, I edited your post by accident.

HackerBaloo commented 4 years ago

Well I don't really understand your second sentence. By variant alternative, what do you mean? And How would I use fast_ber::visit?

I have problems with the new version, it works with the example. But with our bigger production ASN1 file I get this compilation error: candidate function not viable: no known conversion from 'fast_ber::CSP::TcspSemanticSPARQLReq<>' to 'const and CSP::TcspSemanticSPARQLReq is identical to TheTest::SPARQLReq and I have generated new files for both CSP and TheTest. But if you don't get an immediate aha moment, I will try to reproduce my problem with an ASN1 file that I can share.

On Fri, 7 Feb 2020 at 09:20, Samuel-Tyler notifications@github.com wrote:

Great.

Please note that there are some changes in devel, so you may have to tweak your code.

Also note that to access the variant alternative you will still have to provide the full typnename of the alternative (including identifier), access by index or use fast_ber::visit

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Samuel-Tyler/fast_ber/issues/18?email_source=notifications&email_token=AAA5YCUSFOWKL4UCAZJY2QDRBUKT3A5CNFSM4KQ5LN2KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOELCDFSI#issuecomment-583283401, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA5YCVFNG37RGHNKHK4YHTRBUKT3ANCNFSM4KQ5LN2A .

--


Björn Carlsson Telefon 0704-10 69 77 Epost mailto://b.r.carlsson@gmail.com Blog http://hackerbaloo.blogspot.com/


Samuel-Tyler commented 4 years ago

fast_ber::Choice is modelling std::variant. Take a look at the operations this provides, they are mimic'ed by fast_ber.

For example: fast_ber::visit([](const auto& arg){std::cout << arg;}, v); Would print the active member of the Choice.

I would have to see more of the log to understand. But things to check: Does the type appear exactly once in the Choice? Are you assigning to const?

Samuel-Tyler commented 4 years ago

Also, when you try to encode the structure I realized there is a bug when encoding your test code (on devel branch, not on master). This can be temporarily fixed by using IMPLICIT TAGS. I will fix this tonight.

HackerBaloo commented 4 years ago

test2.zip I added more of our definitions to reproduce the problem. I get the compilation error when i try this: The compilation error above was from clang, now I tried gcc and got a similar error, but it doesn't mention const:

g++ -std=c++14  -g -c main.cpp -I/home/bjornca/src/testapp/includes
main.cpp: In function ‘int main(int, const char**)’:
main.cpp:21:62: error: no match for ‘operator=’ (operand types are ‘fast_ber::TheTest2::Msg<>’ and ‘fast_ber::TheTest2::SemanticSPARQLReq<>’)
   msg1 = fast_ber::TheTest2::SemanticSPARQLReq<>{"Header", {}};
                                                              ^
In file included from /home/bjornca/src/testapp/includes/fast_ber/ber_types/All.hpp:3:0,
                 from test2.hpp:3,
                 from main.cpp:11:

When I try to compile this: fast_ber::TheTest2::Msg<> msg1; msg1 = fast_ber::TheTest2::SemanticSPARQLReq<>{"Header", {}};

Samuel-Tyler commented 4 years ago

The following works:

int main()
{
     fast_ber::TheTest2::Msg<> msg1;
     msg1 = TheTest2::SemanticSPARQLReq<DoubleId<Id<Class::context_specific, 119>, ExplicitId<UniversalTag::sequence>>>{"Header", {}};
}

I'm not sure why the one you tried doesn't. Seems to be some kind of bug.

Samuel-Tyler commented 4 years ago

Looks like there are two issues I need to resolve:

Fix encoding of choices for explicit tagged types Add support for REAL type

This test program works with the attached (modified) schema.

#include "test2.hpp"

#include <vector>
#include <fstream>

using namespace fast_ber;

int main()
{
    fast_ber::TheTest2::Msg<> msg1;
    //msg1 = TheTest2::SemanticSPARQLReq<DoubleId<Id<Class::context_specific, 119>, ExplicitId<UniversalTag::sequence>>>{"Header", {}};
    msg1 = TheTest2::SemanticSPARQLReq<Id<Class::context_specific, 119>>{"Header", {}};

    std::cout << msg1 << std::endl;

    std::vector<uint8_t> buffer(1000, 0);
    fast_ber::encode(absl::Span<uint8_t>(buffer), msg1);

    std::ofstream out("testout.ber");
    auto res = fast_ber::encode(absl::Span<uint8_t>(buffer), msg1);
    out.write((const char*)buffer.data(), res.length);
}

I'll work on those issues on the weekend. test2.zip

HackerBaloo commented 4 years ago

Thank you

On Fri, 7 Feb 2020 at 15:30, Samuel-Tyler notifications@github.com wrote:

Looks like there are two issues I need to resolve:

Fix encoding of choices for explicit tagged types Add support for REAL type

This test program works with the attached (modified) schema.

include "test2.hpp"

include

include

using namespace fast_ber;

int main() { fast_ber::TheTest2::Msg<> msg1; //msg1 = TheTest2::SemanticSPARQLReq<DoubleId<Id<Class::context_specific, 119>, ExplicitId>>{"Header", {}}; msg1 = TheTest2::SemanticSPARQLReq<Id<Class::context_specific, 119>>{"Header", {}};

std::cout << msg1 << std::endl;

std::vector<uint8_t> buffer(1000, 0);
fast_ber::encode(absl::Span<uint8_t>(buffer), msg1);

std::ofstream out("testout.ber");
auto res = fast_ber::encode(absl::Span<uint8_t>(buffer), msg1);
out.write((const char*)buffer.data(), res.length);

}

I'll work on those issues on the weekend. test2.zip https://github.com/Samuel-Tyler/fast_ber/files/4171245/test2.zip

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Samuel-Tyler/fast_ber/issues/18?email_source=notifications&email_token=AAA5YCXGMYI5LQ7UYR3CC33RBVWBVA5CNFSM4KQ5LN2KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOELDC3BY#issuecomment-583413127, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA5YCWUM6FZGHZKHKN7DT3RBVWBVANCNFSM4KQ5LN2A .

--


Björn Carlsson Telefon 0704-10 69 77 Epost mailto://b.r.carlsson@gmail.com Blog http://hackerbaloo.blogspot.com/


Samuel-Tyler commented 4 years ago

You're welcome.

If you happen to have any test .ber files it would allow me to verify the behaviour.

HackerBaloo commented 4 years ago

You mean the corresponding output from our old compiler?

On Fri, 7 Feb 2020 at 15:45, Samuel-Tyler notifications@github.com wrote:

You're welcome.

If you happen to have any test .ber files it would allow me to verify the behaviour.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Samuel-Tyler/fast_ber/issues/18?email_source=notifications&email_token=AAA5YCQRZ5GZH3EIW53P3C3RBVXX5A5CNFSM4KQ5LN2KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOELDEPJI#issuecomment-583419813, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA5YCXHRSS57OM2QH7LBTTRBVXX5ANCNFSM4KQ5LN2A .

--


Björn Carlsson Telefon 0704-10 69 77 Epost mailto://b.r.carlsson@gmail.com Blog http://hackerbaloo.blogspot.com/


Samuel-Tyler commented 4 years ago

Yes, if you have it handy the BER packets which you are encoding/decoding

HackerBaloo commented 4 years ago

I don't yet, but I realize it would be a fantastic way of doing regression test if we decide to switch compiler, so I will try to create some BER packets.

On Fri, 7 Feb 2020 at 15:58, Samuel-Tyler notifications@github.com wrote:

Yes, if you have it handy the BER packets which you are encoding/decoding

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Samuel-Tyler/fast_ber/issues/18?email_source=notifications&email_token=AAA5YCQH7HPM2T4E5P6H36DRBVZK5A5CNFSM4KQ5LN2KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOELDHBOA#issuecomment-583430328, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA5YCRDAE2ZAV5FYOFZIBDRBVZK5ANCNFSM4KQ5LN2A .

--


Björn Carlsson Telefon 0704-10 69 77 Epost mailto://b.r.carlsson@gmail.com Blog http://hackerbaloo.blogspot.com/


HackerBaloo commented 4 years ago

130.zip In our original asn1 SemanticSPARQLReq has the Id 130, and that's the buffer I saved to file. The request has a header="Version=1" and a list of queries, with one item="SELECT * WHERE { ?s ?p ?o }"

Samuel-Tyler commented 4 years ago

Great! This will help in testing.

./src/fast_ber_view 130.ber  | jq .
{
  "length": 49,
  "identifier": {
    "class": "Context Specific",
    "tag": 129
  },
  "content": [
    {
      "length": 45,
      "identifier": {
        "class": "Universal",
        "tag": "Sequence / Sequence Of"
      },
      "content": [
        {
          "length": 11,
          "identifier": {
            "class": "Universal",
            "tag": "UTF8 String"
          },
          "content": "Version=1"
        },
        {
          "length": 32,
          "identifier": {
            "class": "Universal",
            "tag": "Sequence / Sequence Of"
          },
          "content": [
            {
              "length": 30,
              "identifier": {
                "class": "Universal",
                "tag": "UTF8 String"
              },
              "content": "SELECT * WHERE {  ?s ?p ?o }"
            }
          ]
        }
      ]
    }
  ]
}
Samuel-Tyler commented 4 years ago

By the way, the tag seems to be 129

HackerBaloo commented 4 years ago

Well, you are right the ASN1 file says 129, but I used a member in the class when the file was named, and that was 130, strange.

On Fri, 7 Feb 2020 at 17:39, Samuel-Tyler notifications@github.com wrote:

Great! This will help in testing.

./src/fast_ber_view 130.ber | jq . { "length": 49, "identifier": { "class": "Context Specific", "tag": 129 }, "content": [ { "length": 45, "identifier": { "class": "Universal", "tag": "Sequence / Sequence Of" }, "content": [ { "length": 11, "identifier": { "class": "Universal", "tag": "UTF8 String" }, "content": "Version=1" }, { "length": 32, "identifier": { "class": "Universal", "tag": "Sequence / Sequence Of" }, "content": [ { "length": 30, "identifier": { "class": "Universal", "tag": "UTF8 String" }, "content": "SELECT * WHERE { ?s ?p ?o }" } ] } ] } ] }

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Samuel-Tyler/fast_ber/issues/18?email_source=notifications&email_token=AAA5YCSU5LYRLFSWOURRQSDRBWFCHA5CNFSM4KQ5LN2KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOELDVTLQ#issuecomment-583489966, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA5YCRAVUTYTEIH75LLQS3RBWFCHANCNFSM4KQ5LN2A .

--


Björn Carlsson Telefon 0704-10 69 77 Epost mailto://b.r.carlsson@gmail.com Blog http://hackerbaloo.blogspot.com/


Samuel-Tyler commented 4 years ago

I've fixed the choice conversion and encoding. The following is now working:

#include "generated/test2.hpp"

#include <fstream>
#include <iostream>

int main()
{
    fast_ber::TheTest2::Msg<> msg = fast_ber::TheTest2::SemanticSPARQLReq<>{"Version=1", {"SELECT * WHERE {  ?s ?p ?o }"}};

    std::vector<uint8_t> buffer;
    buffer.resize(fast_ber::encoded_length(msg));

    const auto encode_result = fast_ber::encode(absl::Span<uint8_t>(buffer), msg);
    if (!encode_result.success)
    {
        std::cout << "Failed to encode data\n";
        return -1;
    }

    std::ofstream output("msg.ber");
    if (!output.good())
    {
        std::cout << "Failed to open output file: msg.ber\n";
        return -1;
    }
    output.write(reinterpret_cast<const char*>(buffer.data()), static_cast<std::streamsize>(encode_result.length));
    return 0;
}
c++ -O3 -I../include -I../3rd_party/abseil-cpp main-test2.cpp
./a.out
../build/src/fast_ber_view msg.ber  | jq .
{
  "length": 48,
  "identifier": {
    "class": "Context Specific",
    "tag": 119
  },
  "content": [
    {
      "length": 45,
      "identifier": {
        "class": "Universal",
        "tag": "Sequence / Sequence Of"
      },
      "content": [
        {
          "length": 11,
          "identifier": {
            "class": "Universal",
            "tag": "UTF8 String"
          },
          "content": "Version=1"
        },
        {
          "length": 32,
          "identifier": {
            "class": "Universal",
            "tag": "Sequence / Sequence Of"
          },
          "content": [
            {
              "length": 30,
              "identifier": {
                "class": "Universal",
                "tag": "UTF8 String"
              },
              "content": "SELECT * WHERE {  ?s ?p ?o }"
            }
          ]
        }
      ]
    }
  ]
}

I still need to add support for REAL such that your schema will compile. For this case, I switched REAL to OCTET STRING.

HackerBaloo commented 4 years ago

Great work. But I react to the fact that I don't get a warning or anything for the REAL that the compiler doesn't understand. Can I tell the compiler to fail, or does it perhaps already give an exit code indicating that something went wrong?

On Sat, 8 Feb 2020 at 13:57, Samuel-Tyler notifications@github.com wrote:

I've fixed the choice conversion and encoding. The following is now working:

include "generated/test2.hpp"

include

include

int main() { fast_ber::TheTest2::Msg<> msg = fast_ber::TheTest2::SemanticSPARQLReq<>{"Version=1", {"SELECT * WHERE { ?s ?p ?o }"}};

std::vector<uint8_t> buffer;
buffer.resize(fast_ber::encoded_length(msg));

const auto encode_result = fast_ber::encode(absl::Span<uint8_t>(buffer), msg);
if (!encode_result.success)
{
    std::cout << "Failed to encode data\n";
    return -1;
}

std::ofstream output("msg.ber");
if (!output.good())
{
    std::cout << "Failed to open output file: msg.ber\n";
    return -1;
}
output.write(reinterpret_cast<const char*>(buffer.data()), static_cast<std::streamsize>(encode_result.length));
return 0;

}

c++ -O3 -I../include -I../3rd_party/abseil-cpp main-test2.cpp ./a.out ../build/src/fast_ber_view msg.ber | jq .

{ "length": 48, "identifier": { "class": "Context Specific", "tag": 119 }, "content": [ { "length": 45, "identifier": { "class": "Universal", "tag": "Sequence / Sequence Of" }, "content": [ { "length": 11, "identifier": { "class": "Universal", "tag": "UTF8 String" }, "content": "Version=1" }, { "length": 32, "identifier": { "class": "Universal", "tag": "Sequence / Sequence Of" }, "content": [ { "length": 30, "identifier": { "class": "Universal", "tag": "UTF8 String" }, "content": "SELECT * WHERE { ?s ?p ?o }" } ] } ] } ] }

I still need to add support for REAL such that your schema will compile. For this case, I switched REAL to OCTET STRING.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Samuel-Tyler/fast_ber/issues/18?email_source=notifications&email_token=AAA5YCRYIJWVKX37JBT5FX3RB2T27A5CNFSM4KQ5LN2KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOELFRIPI#issuecomment-583734333, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA5YCQJHREJ2526WYXVDSLRB2T27ANCNFSM4KQ5LN2A .

--


Björn Carlsson Telefon 0704-10 69 77 Epost mailto://b.r.carlsson@gmail.com Blog http://hackerbaloo.blogspot.com/


HackerBaloo commented 4 years ago

And I will test it more on Monday.

On Sat, 8 Feb 2020 at 22:23, Björn Carlsson b.r.carlsson@gmail.com wrote:

Great work. But I react to the fact that I don't get a warning or anything for the REAL that the compiler doesn't understand. Can I tell the compiler to fail, or does it perhaps already give an exit code indicating that something went wrong?

On Sat, 8 Feb 2020 at 13:57, Samuel-Tyler notifications@github.com wrote:

I've fixed the choice conversion and encoding. The following is now working:

include "generated/test2.hpp"

include

include

int main() { fast_ber::TheTest2::Msg<> msg = fast_ber::TheTest2::SemanticSPARQLReq<>{"Version=1", {"SELECT * WHERE { ?s ?p ?o }"}};

std::vector<uint8_t> buffer;
buffer.resize(fast_ber::encoded_length(msg));

const auto encode_result = fast_ber::encode(absl::Span<uint8_t>(buffer), msg);
if (!encode_result.success)
{
    std::cout << "Failed to encode data\n";
    return -1;
}

std::ofstream output("msg.ber");
if (!output.good())
{
    std::cout << "Failed to open output file: msg.ber\n";
    return -1;
}
output.write(reinterpret_cast<const char*>(buffer.data()), static_cast<std::streamsize>(encode_result.length));
return 0;

}

c++ -O3 -I../include -I../3rd_party/abseil-cpp main-test2.cpp ./a.out ../build/src/fast_ber_view msg.ber | jq .

{ "length": 48, "identifier": { "class": "Context Specific", "tag": 119 }, "content": [ { "length": 45, "identifier": { "class": "Universal", "tag": "Sequence / Sequence Of" }, "content": [ { "length": 11, "identifier": { "class": "Universal", "tag": "UTF8 String" }, "content": "Version=1" }, { "length": 32, "identifier": { "class": "Universal", "tag": "Sequence / Sequence Of" }, "content": [ { "length": 30, "identifier": { "class": "Universal", "tag": "UTF8 String" }, "content": "SELECT * WHERE { ?s ?p ?o }" } ] } ] } ] }

I still need to add support for REAL such that your schema will compile. For this case, I switched REAL to OCTET STRING.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Samuel-Tyler/fast_ber/issues/18?email_source=notifications&email_token=AAA5YCRYIJWVKX37JBT5FX3RB2T27A5CNFSM4KQ5LN2KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOELFRIPI#issuecomment-583734333, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA5YCQJHREJ2526WYXVDSLRB2T27ANCNFSM4KQ5LN2A .

--


Björn Carlsson Telefon 0704-10 69 77 Epost mailto://b.r.carlsson@gmail.com Blog http://hackerbaloo.blogspot.com/


--


Björn Carlsson Telefon 0704-10 69 77 Epost mailto://b.r.carlsson@gmail.com Blog http://hackerbaloo.blogspot.com/


Samuel-Tyler commented 4 years ago

Great work. But I react to the fact that I don't get a warning or anything for the REAL that the compiler doesn't understand. Can I tell the compiler to fail, or does it perhaps already give an exit code indicating that something went wrong?

You are right, sorry about this. I will add some more diagnostics indicating features which are still in development.

HackerBaloo commented 4 years ago

I have made a few encode performance tests, and it looks good for fast_ber. With a very big response it was better with x2. But what worries me a bit is the compilation time. Just the code in your example takes 17 s for me to compile, I don't now how that would scale with 130 messages.

HackerBaloo commented 4 years ago

Well, just tried to have two messages instead of one and that didn't affect the compilation time. And since the sample is just one file, the compiler can't use more than one thread. So perhaps I was worried for no good reason.

Samuel-Tyler commented 4 years ago

It is good to hear of the performance benefit. I have some plans to further improve this.

You are correct, the compile times may be long. This is due to work being moved to compile time for runtime efficiency, and heavy template instantiation.

I can suggest building the encoder / decoder in a separate compilation unit within your project, such that when developing changes to the rest of the project will not force a recompile of this.

Samuel-Tyler commented 4 years ago

Also, if you are just using a small subset of your ASN.1 spec, remove the stuff that you're not using to reduce the amount of code which is generated.

Samuel-Tyler commented 4 years ago

One last point, specify -DNDEBUG to remove assertions in your release build for maximum performance.

Samuel-Tyler commented 4 years ago

Hey @HackerBaloo, would be interested to hear if you've run any more tests?

HackerBaloo commented 4 years ago

Yes I did some tests in the beginning of week, and I got some good performance results. Mainly trying to encode one small and one huge message. Not that the exact performance is that important to us, just to know that it's not much worse than what we have. The huge message was about twice as fast to encode with fast_ber. But after that I have been busy with other stuff, and I think I will have limited time for this the next month or two. But I will try to squeeze in some fast_ber time.

On Sat, 15 Feb 2020 at 14:39, Samuel-Tyler notifications@github.com wrote:

Hey @HackerBaloo https://github.com/HackerBaloo, would be interested to hear if you've run any more tests?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Samuel-Tyler/fast_ber/issues/18?email_source=notifications&email_token=AAA5YCSJE4O5EUUWM2JO4D3RC7WCHA5CNFSM4KQ5LN2KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEL3KYIA#issuecomment-586591264, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA5YCTH7TXD4XGFXZYT2GLRC7WCHANCNFSM4KQ5LN2A .

--


Björn Carlsson Telefon 0704-10 69 77 Epost mailto://b.r.carlsson@gmail.com Blog http://hackerbaloo.blogspot.com/


Samuel-Tyler commented 4 years ago

@HackerBaloo Ok, no worries. Thanks for trying it out!

HackerBaloo commented 4 years ago

I have made some tests with the latest devel today, and I notice your compiler warning improvements, good work.

Samuel-Tyler commented 4 years ago

Thanks!

Please let me know if you have any further suggestions to improve usability of the project.

Samuel-Tyler commented 4 years ago

@HackerBaloo Hey. What build system are you using on your projects?

I've created fast_ber_ldap3, which demonstrates a project consuming fast_ber with CMake, documents to follow shortly. I would like fast_ber to be easy to consume, so would be interesting to know how I can make this easier.

HackerBaloo commented 4 years ago

Good initiative. You could add code on how to generate the testfiles too, or at least one example, to show that side of the process. And the use of a message could also be more elaborate than: std::cout << message << std::endl; So perhaps another utility that does something depending on the content of the message?

On Tue, 25 Feb 2020 at 00:48, Samuel-Tyler notifications@github.com wrote:

@HackerBaloo https://github.com/HackerBaloo Hey. What build system are you using on your projects?

I've created fast_ber_ldap3 https://github.com/Samuel-Tyler/fast_ber_ldap3, which demonstrates a project consuming fast_ber with CMake, documents to follow shortly. I would like fast_ber to be easy to consume, so would be interesting to know how I can make this easier.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Samuel-Tyler/fast_ber/issues/18?email_source=notifications&email_token=AAA5YCSJE3ZT4GCJDWKTOL3RERMGLA5CNFSM4KQ5LN2KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEMZ7GWY#issuecomment-590607195, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA5YCTAKKFAK5WKGU2RSO3RERMGLANCNFSM4KQ5LN2A .

--


Björn Carlsson Telefon 0704-10 69 77 Epost mailto://b.r.carlsson@gmail.com Blog http://hackerbaloo.blogspot.com/


HackerBaloo commented 4 years ago

And well, build system, we use cmake, plus a home grown system, that can generate make or cmake.

On Tue, 25 Feb 2020 at 07:36, Björn Carlsson b.r.carlsson@gmail.com wrote:

Good initiative. You could add code on how to generate the testfiles too, or at least one example, to show that side of the process. And the use of a message could also be more elaborate than: std::cout << message << std::endl; So perhaps another utility that does something depending on the content of the message?

On Tue, 25 Feb 2020 at 00:48, Samuel-Tyler notifications@github.com wrote:

@HackerBaloo https://github.com/HackerBaloo Hey. What build system are you using on your projects?

I've created fast_ber_ldap3 https://github.com/Samuel-Tyler/fast_ber_ldap3, which demonstrates a project consuming fast_ber with CMake, documents to follow shortly. I would like fast_ber to be easy to consume, so would be interesting to know how I can make this easier.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Samuel-Tyler/fast_ber/issues/18?email_source=notifications&email_token=AAA5YCSJE3ZT4GCJDWKTOL3RERMGLA5CNFSM4KQ5LN2KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEMZ7GWY#issuecomment-590607195, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA5YCTAKKFAK5WKGU2RSO3RERMGLANCNFSM4KQ5LN2A .

--


Björn Carlsson Telefon 0704-10 69 77 Epost mailto://b.r.carlsson@gmail.com Blog http://hackerbaloo.blogspot.com/


--


Björn Carlsson Telefon 0704-10 69 77 Epost mailto://b.r.carlsson@gmail.com Blog http://hackerbaloo.blogspot.com/


Samuel-Tyler commented 4 years ago

Thanks for the good advice, I've added an encoder to the repo.