Class ByteBufJsonHelper

java.lang.Object
com.couchbase.client.core.endpoint.util.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é
  • Constructor Summary

    Constructors
    Constructor Description
    ByteBufJsonHelper()  
  • Method Summary

    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).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ByteBufJsonHelper

      public ByteBufJsonHelper()
  • Method Details

    • 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.