Class ByteBufJsonHelper


  • public class ByteBufJsonHelper
    extends Object
    An helper class providing utility methods to deal with parsing of structured data (like JSON) inside a ByteBuf buffer.
    Since:
    1.1
    Author:
    Simon Baslé
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static int findNextChar​(ByteBuf buf, char c)
      Shorthand for ByteBuf.bytesBefore(byte) with a simple char c, finds the number of bytes until next occurrence of the character c from the current readerIndex() in buf.
      static int findNextCharNotPrefixedBy​(ByteBuf buf, char c, char prefix)
      Find the number of bytes until next occurrence of the character c from the current readerIndex in buf, with the twist that if this occurrence is prefixed by the prefix character, we try to find another occurrence.
      static int findSectionClosingPosition​(ByteBuf buf, char openingChar, char closingChar)
      Finds the position of the correct closing character, taking into account the fact that before the correct one, other sub section with same opening and closing characters can be encountered.
      static int findSectionClosingPosition​(ByteBuf buf, int startOffset, char openingChar, char closingChar)
      Finds the position of the correct closing character, taking into account the fact that before the correct one, other sub section with same opening and closing characters can be encountered.
      static int findSplitPosition​(ByteBuf buf, char splitChar)
      Finds the position of the split character, taking into account the fact that the character could be found escaped in strings (such occurrences are ignored).
    • Constructor Detail

      • ByteBufJsonHelper

        public ByteBufJsonHelper()
    • Method Detail

      • findNextChar

        public static final int findNextChar​(ByteBuf buf,
                                             char c)
        Shorthand for ByteBuf.bytesBefore(byte) with a simple char c, finds the number of bytes until next occurrence of the character c from the current readerIndex() in buf.
        Parameters:
        buf - the buffer to look into.
        c - the character to search for.
        Returns:
        the number of bytes before the character or -1 if not found.
        See Also:
        ByteBuf.bytesBefore(byte)
      • findNextCharNotPrefixedBy

        public static final int findNextCharNotPrefixedBy​(ByteBuf buf,
                                                          char c,
                                                          char prefix)
        Find the number of bytes until next occurrence of the character c from the current readerIndex in buf, with the twist that if this occurrence is prefixed by the prefix character, we try to find another occurrence.
        Parameters:
        buf - the buffer to look into.
        c - the character to search for.
        prefix - the character to trigger a retry.
        Returns:
        the position of the first occurrence of c that is not prefixed by prefix or -1 if none found.
      • findSectionClosingPosition

        public static int findSectionClosingPosition​(ByteBuf buf,
                                                     char openingChar,
                                                     char closingChar)
        Finds the position of the correct closing character, taking into account the fact that before the correct one, other sub section with same opening and closing characters can be encountered. This implementation starts for the current readerIndex.
        Parameters:
        buf - the ByteBuf where to search for the end of a section enclosed in openingChar and closingChar.
        openingChar - the section opening char, used to detect a sub-section.
        closingChar - the section closing char, used to detect the end of a sub-section / this section.
        Returns:
        the section closing position or -1 if not found.
      • findSplitPosition

        public static final int findSplitPosition​(ByteBuf buf,
                                                  char splitChar)
        Finds the position of the split character, taking into account the fact that the character could be found escaped in strings (such occurrences are ignored). This implementation starts for the current readerIndex.
        Parameters:
        buf - the ByteBuf where to search for the split character.
        splitChar - the split character to detect.
        Returns:
        the split character position or -1 if not found.
      • findSectionClosingPosition

        public static int findSectionClosingPosition​(ByteBuf buf,
                                                     int startOffset,
                                                     char openingChar,
                                                     char closingChar)
        Finds the position of the correct closing character, taking into account the fact that before the correct one, other sub section with same opening and closing characters can be encountered. This implementation starts for the current readerIndex + startOffset.
        Parameters:
        buf - the ByteBuf where to search for the end of a section enclosed in openingChar and closingChar.
        startOffset - the offset at which to start reading (from buffer's readerIndex).
        openingChar - the section opening char, used to detect a sub-section.
        closingChar - the section closing char, used to detect the end of a sub-section / this section.
        Returns:
        the section closing position or -1 if not found.