24 #include <relpipe/writer/AttributeMetadata.h> |
24 #include <relpipe/writer/AttributeMetadata.h> |
25 #include <relpipe/common/type/typedefs.h> |
25 #include <relpipe/common/type/typedefs.h> |
26 |
26 |
27 #include <relpipe/cli/CLI.h> |
27 #include <relpipe/cli/CLI.h> |
28 |
28 |
|
29 #include "lib/ASN1ContentHandler.h" |
|
30 #include "lib/BasicASN1Reader.h" |
|
31 #include "lib/TransactionalBuffer.h" |
|
32 |
29 #include "ASN1Command.h" |
33 #include "ASN1Command.h" |
|
34 #include "RelpipeASN1ContentHandler.h" |
|
35 #include "FreeformASN1ContentHandler.h" |
30 |
36 |
31 using namespace std; |
37 using namespace std; |
32 using namespace relpipe::writer; |
38 using namespace relpipe::writer; |
33 //using namespace relpipe::in::asn1::lib; |
39 using namespace relpipe::in::asn1::lib; |
34 |
40 |
35 namespace relpipe { |
41 namespace relpipe { |
36 namespace in { |
42 namespace in { |
37 namespace asn1 { |
43 namespace asn1 { |
38 |
44 |
39 void ASN1Command::process(std::istream& input, std::shared_ptr<writer::RelationalWriter> writer, Configuration& configuration) { |
45 void ASN1Command::process(std::istream& input, std::shared_ptr<writer::RelationalWriter> writer, Configuration& configuration) { |
40 // TODO: parse ASN.1 and write relational data |
46 // TODO: parse ASN.1 and write relational data |
|
47 BasicASN1Reader reader; |
|
48 std::shared_ptr<ASN1ContentHandler> asn1handler; |
|
49 |
|
50 if (configuration.mode == Mode::Relpipe) asn1handler = std::make_shared<RelpipeASN1ContentHandler>(writer, configuration); |
|
51 else if (configuration.mode == Mode::Freeform) asn1handler = std::make_shared<FreeformASN1ContentHandler>(writer, configuration); |
|
52 else throw RelpipeWriterException(L"Unsupported mode in ASN1Command: " + std::to_wstring((int) configuration.mode)); |
|
53 |
|
54 for (ParserOptionRecipe o : configuration.parserOptions) { |
|
55 int n = 0; |
|
56 n += reader.setOption(convertor.to_bytes(o.uri), convertor.to_bytes(o.value)); |
|
57 n += asn1handler->setOption(convertor.to_bytes(o.uri), convertor.to_bytes(o.value)); |
|
58 if (n == 0) throw RelpipeWriterException(L"Invalid parser option: „" + o.uri + L"“ with value: „" + o.value + L"“"); |
|
59 } |
|
60 |
|
61 reader.addHandler(asn1handler); |
|
62 |
|
63 try { |
|
64 // TODO: buffering? (reader itself also buffers) |
|
65 for (uint8_t b = input.get(); input.good(); b = input.get()) reader.write(&b, 1); |
|
66 } catch (const relpipe::in::asn1::lib::TransactionalBuffer::WriteBufferOverflowException& e) { |
|
67 // TODO: avoid leaky abstraction and use different exception |
|
68 throw relpipe::writer::RelpipeWriterException(L"Transactional buffer for ASN.1 input is too small"); |
|
69 } |
|
70 |
|
71 reader.close(); |
|
72 |
41 |
73 |
42 } |
74 } |
43 |
75 |
44 } |
76 } |
45 } |
77 } |