# HG changeset patch # User František Kučera # Date 1627488069 -7200 # Node ID 7d309accc6394a452c06e38e3b342b11a779fc84 # Parent 3192dc8772de0ea4563bb825cc4dfa3b69627a50 configuration: --parser-option bit-string-symbol-0 bit-string-symbol-1 – custom symbols e.g. .:, -+, \/ diff -r 3192dc8772de -r 7d309accc639 bash-completion.sh --- a/bash-completion.sh Tue Jul 27 18:33:27 2021 +0200 +++ b/bash-completion.sh Wed Jul 28 18:01:09 2021 +0200 @@ -32,9 +32,8 @@ PARSER_OPTIONS=( "encoding" "parse-encapsulated" - "tree-style" - "tree-with-namespaces" - "root-name" + "bit-string-symbol-0" + "bit-string-symbol-1" ); ENCODINGS=( @@ -56,6 +55,8 @@ elif [[ "$w1" == "--parser-option" ]]; then COMPREPLY=($(compgen -W "${PARSER_OPTIONS[*]}" -- "$w0")) elif [[ "$w2" == "--parser-option" && "$w1" == "encoding" ]]; then COMPREPLY=($(compgen -W "${ENCODINGS[*]}" -- "$w0")) elif [[ "$w2" == "--parser-option" && "$w1" == "parse-encapsulated" ]]; then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0")) + elif [[ "$w2" == "--parser-option" && "$w1" == "bit-string-symbol-0" && "x$w0" == "x" ]]; then COMPREPLY=("'0'") + elif [[ "$w2" == "--parser-option" && "$w1" == "bit-string-symbol-1" && "x$w0" == "x" ]]; then COMPREPLY=("'1'") else OPTIONS=( "--relation" diff -r 3192dc8772de -r 7d309accc639 src/FreeformASN1ContentHandler.h --- a/src/FreeformASN1ContentHandler.h Tue Jul 27 18:33:27 2021 +0200 +++ b/src/FreeformASN1ContentHandler.h Wed Jul 28 18:01:09 2021 +0200 @@ -26,6 +26,11 @@ namespace in { namespace asn1 { +namespace freeformOption { +static const char* BitStringSymbol0 = "bit-string-symbol-0"; +static const char* BitStringSymbol1 = "bit-string-symbol-1"; +} + /** * Converts arbitrary ASN.1 stream of events to a relation * i.e. does not require any specific structures/schema. @@ -40,6 +45,9 @@ Configuration configuration; std::vector position; + std::string bitStringSymbol0 = "0"; + std::string bitStringSymbol1 = "1"; + class Record { public: const Header* header; @@ -105,7 +113,11 @@ } bool setOption(const std::string& uri, const std::string& value) override { - return false; + if (uri == freeformOption::BitStringSymbol0) bitStringSymbol0 = value; + else if (uri == freeformOption::BitStringSymbol1) bitStringSymbol1 = value; + else return false; + + return true; } void writeStreamStart() override { @@ -131,7 +143,7 @@ void writeStreamEnd() override { Record r(nullptr, position, L"stream-end"); write(r); - + auto id = position.back() + 1; position.pop_back(); position.back() = id; @@ -147,7 +159,7 @@ void writeCollectionEnd() override { Record r(nullptr, position, L"collection-end"); write(r); - + auto id = position.back() + 1; position.pop_back(); position.back() = id; @@ -155,8 +167,7 @@ void writeBitString(const Header& header, std::vector value) override { std::stringstream bits; - for (bool b : value) bits << (int) b; - // for (bool b : value) bits << (b ? ':' : '.'); // TODO: configurable true/false symbols? + for (bool b : value) bits << (b ? bitStringSymbol1 : bitStringSymbol0); position.back()++; Record r(&header, position, L"bit-string");