From c63355fc5466845c99943c60feb302dd50079921 Mon Sep 17 00:00:00 2001 From: Strongest Number 9 <16169054+StrongestNumber9@users.noreply.github.com> Date: Thu, 3 Aug 2023 11:02:39 +0300 Subject: [PATCH] Clean up docs, change it to adoc (#17) --- README.md => README.adoc | 64 +++++++++---------- .../com/teragrep/rlo_06/BrokenSyntaxTest.java | 6 -- 2 files changed, 29 insertions(+), 41 deletions(-) rename README.md => README.adoc (64%) diff --git a/README.md b/README.adoc similarity index 64% rename from README.md rename to README.adoc index d0c5508..4a210d0 100644 --- a/README.md +++ b/README.adoc @@ -1,4 +1,4 @@ -# teragrep RFC5424 parser += teragrep RFC5424 parser Features * Fast @@ -6,60 +6,55 @@ Non-features * Excellent strictness -## License +== License AGPLv3 with link:https://github.com/teragrep/rlo_06/blob/master/LICENSE#L665-L670[additional permissions] granted in the license. -## Usage +== Usage This parser uses subscriptions to pick up interesting message elements from the message stream. For generic message property extraction use: -```java + +[source,java] +---- RFC5424ParserSubscription subscription = new RFC5424ParserSubscription(); subscription.subscribeAll(); // or following where parameter is type of ParserEnum subscription.add(ParserEnum.TIMESTAMP); subscription.add(ParserEnum.MSG); -``` +---- For structured data property extraction use: -```java + +[source,java] +---- RFC5424ParserSDSubscription sdSubscription = new RFC5424ParserSDSubscription(); // subscribe with following where first is SD-ID and second is PARAM-NAME sdSubscription.subscribeElement("event_key@12345","paramKey"); -``` - -After desired subscriptions are created then allocate a resultset object: -```java -ParserResultset res = new ParserResultset(subscription, sdSubscription); -``` +---- Create a parser with the desired InputStream -```java -RFC5424Parser parser = new RFC5424Parser(inputStream); -``` - -```java -if (parser.next(res) == true) { - String msg = res.getMsgAsUTF8String(); - String sdValue = res.getSdValueAsUTF8String("event_key@12345","paramKey") -} -``` + +[source,java] +---- +RFC5424Parser parser = new RFC5424Parser(inputStream, subscription, sdSubscription); +---- Next event can be extracted as follows -```java -res.clear(); // clear resultset before calling .next() again -if(parser.next(res) == true) { - String msg = res.getMsgAsUTF8String(); - String sdValue = res.getSdValueAsUTF8String("event_key@12345","paramKey") + +[source,java] +---- +if (parser.next()) { + ResultSetAsString results = new ResultSetAsString(parser.get()); + String msg = results.getMsg(); + String sdValue = results.getSdValue("event_key@12345","paramKey"); } -``` +---- -## Todo -``` -RFC5424Parser.java -``` +== Todo + +=== RFC5424Parser.java * Take maximum allocation sizes from ParserResultset for string length checking * Throw if maximum size is exceeded * Throw if quotation exceed maximum line. THIS STALLS AT THE MOMENT. @@ -68,8 +63,7 @@ RFC5424Parser.java * Try extracting sdParsing to a dedicated class * Try extracting buffer handling to a dedicated class -``` -SytanxTest.java -``` +=== Tests + * More test cases, see palindromicity code diff --git a/src/test/java/com/teragrep/rlo_06/BrokenSyntaxTest.java b/src/test/java/com/teragrep/rlo_06/BrokenSyntaxTest.java index eb11803..dc7bf42 100644 --- a/src/test/java/com/teragrep/rlo_06/BrokenSyntaxTest.java +++ b/src/test/java/com/teragrep/rlo_06/BrokenSyntaxTest.java @@ -13,11 +13,9 @@ void testBrokenFail() throws Exception { RFC5424ParserSubscription subscription = new RFC5424ParserSubscription(); subscription.subscribeAll(); RFC5424ParserSDSubscription sdSubscription = new RFC5424ParserSDSubscription(); - ParserResultSet res = new ParserResultSet(subscription, sdSubscription); RFC5424Parser parser = new RFC5424Parser(null, subscription, sdSubscription); parser.setInputStream(new ByteArrayInputStream( (SYSLOG_MESSAGE).getBytes())); Assertions.assertThrows(ParseException.class, parser::next); - res.clear(); } @Test @@ -26,7 +24,6 @@ void testNilTimestamp() throws Exception { RFC5424ParserSubscription subscription = new RFC5424ParserSubscription(); subscription.subscribeAll(); RFC5424ParserSDSubscription sdSubscription = new RFC5424ParserSDSubscription(true); - ParserResultSet res = new ParserResultSet(subscription, sdSubscription); RFC5424Parser parser = new RFC5424Parser(null, subscription, sdSubscription); ResultSetAsString resultsetAsString = new ResultSetAsString(parser.get()); parser.setInputStream(new ByteArrayInputStream( (input).getBytes())); @@ -39,7 +36,6 @@ void testNilTimestamp() throws Exception { Assertions.assertEquals("DEA", resultsetAsString.getProcid(), "Procid"); Assertions.assertEquals("MSG-01", resultsetAsString.getMsgid(), "msgid"); Assertions.assertEquals("sigsegv", resultsetAsString.getMsg(), "msg"); - res.clear(); } @Test @@ -48,11 +44,9 @@ void testOpenSD() throws Exception { RFC5424ParserSubscription subscription = new RFC5424ParserSubscription(); subscription.subscribeAll(); RFC5424ParserSDSubscription sdSubscription = new RFC5424ParserSDSubscription(); - ParserResultSet res = new ParserResultSet(subscription, sdSubscription); RFC5424Parser parser = new RFC5424Parser(null, subscription, sdSubscription); parser.setInputStream(new ByteArrayInputStream((SYSLOG_MESSAGE).getBytes())); Assertions.assertThrows(ParseException.class, parser::next); - res.clear(); }