Class Utf8.ServerProcessor

java.lang.Object
com.google.protobuf.Utf8.Processor
com.google.protobuf.Utf8.ServerProcessor
Direct Known Subclasses:
Utf8.ServerProcessorWithEncodedLength
Enclosing class:
Utf8

static class Utf8.ServerProcessor extends Utf8.Processor
Utf8.Processor optimized for server platforms.
  • Constructor Details

    • ServerProcessor

      ServerProcessor()
  • Method Details

    • decodeUtf8

      String decodeUtf8(byte[] bytes, int index, int size) throws InvalidProtocolBufferException
      Description copied from class: Utf8.Processor
      Decodes the given byte array slice into a String.
      Specified by:
      decodeUtf8 in class Utf8.Processor
      Throws:
      InvalidProtocolBufferException - if the byte array slice is not valid UTF-8
    • encodeUtf8

      int encodeUtf8(String in, byte[] out, int offset, int length)
      Description copied from class: Utf8.Processor
      Encodes an input character sequence (in) to UTF-8 in the target array (out). For a string, this method is functionally identical to
      byte[] a = string.getBytes(UTF_8);
      System.arraycopy(a, 0, bytes, offset, a.length);
      return offset + a.length;
      
      but may be implemented differently for efficiency purposes.

      Matching String.getBytes(UTF_8) this replaces unpaired surrogates with a replacement character.

      To ensure sufficient space in the output buffer, either call Utf8.Processor.encodedLength(String) to compute the exact amount needed, or leave room for Utf8.MAX_BYTES_PER_CHAR * sequence.length(), which is the largest possible number of bytes that any input can be encoded to.

      Specified by:
      encodeUtf8 in class Utf8.Processor
      Parameters:
      in - the input character sequence to be encoded
      out - the target array
      offset - the starting offset in bytes to start writing at
      length - the length of the bytes, starting from offset
      Returns:
      the new offset, equivalent to offset + Utf8.encodedLength(sequence)
    • encodeUtf8Internal

      protected void encodeUtf8Internal(String in, ByteBuffer out)
      Description copied from class: Utf8.Processor
      Encodes the input character sequence to a direct ByteBuffer instance.
      Specified by:
      encodeUtf8Internal in class Utf8.Processor