Class AbstractFragmentTranscoder

java.lang.Object
com.couchbase.client.java.transcoder.subdoc.AbstractFragmentTranscoder
All Implemented Interfaces:
FragmentTranscoder
Direct Known Subclasses:
AbstractByteArrayFragmentTranscoder

@Committed
@Public
public abstract class AbstractFragmentTranscoder
extends Object
implements FragmentTranscoder
A common implementation base of the FragmentTranscoder interface for transcoding sub-document fragments. It recognizes MultiValue as a special encoding case to be treated separately.
Since:
2.2
Author:
Simon Baslé
  • Constructor Summary

    Constructors
    Constructor Description
    AbstractFragmentTranscoder()  
  • Method Summary

    Modifier and Type Method Description
    <T> T decode​(com.couchbase.client.deps.io.netty.buffer.ByteBuf encoded, Class<? extends T> clazz)
    Decode content in a ByteBuf **without releasing it**.
    protected abstract com.couchbase.client.deps.io.netty.buffer.ByteBuf doEncodeMulti​(MultiValue<?> multiValue, String transcodingErrorMessage)
    Encode a special mutation value that denotes multiple values being processed in bulk, to a ByteBuf suitable for use in the sub-document protocol.
    protected abstract <T> com.couchbase.client.deps.io.netty.buffer.ByteBuf doEncodeSingle​(T value, String transcodingErrorMessage)
    Encode a single mutation value to a ByteBuf suitable for use in the sub-document protocol.
    <T> com.couchbase.client.deps.io.netty.buffer.ByteBuf encode​(T value)
    Encode a value to a ByteBuf suitable for use in the sub-document protocol.
    <T> com.couchbase.client.deps.io.netty.buffer.ByteBuf encodeWithMessage​(T value, String transcodingErrorMessage)
    Encode a value to a ByteBuf suitable for use in the sub-document protocol.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.couchbase.client.java.transcoder.subdoc.FragmentTranscoder

    decodeWithMessage
  • Constructor Details

    • AbstractFragmentTranscoder

      public AbstractFragmentTranscoder()
  • Method Details

    • decode

      public <T> T decode​(com.couchbase.client.deps.io.netty.buffer.ByteBuf encoded, Class<? extends T> clazz) throws TranscodingException
      Description copied from interface: FragmentTranscoder
      Decode content in a ByteBuf **without releasing it**. Suitable for populating a DocumentFragment's content.
      Specified by:
      decode in interface FragmentTranscoder
      Type Parameters:
      T - the type of the decoded fragment.
      Parameters:
      encoded - the encoded fragment value (will not be released).
      clazz - the target class for decoded value. Using Object.class implies a generic decode, where dictionaries are represented by JsonObject and arrays by JsonArray.
      Returns:
      a decoded fragment.
      Throws:
      TranscodingException - if the decoding couldn't happen.
    • encode

      public <T> com.couchbase.client.deps.io.netty.buffer.ByteBuf encode​(T value) throws TranscodingException
      Description copied from interface: FragmentTranscoder
      Encode a value to a ByteBuf suitable for use in the sub-document protocol.
      Specified by:
      encode in interface FragmentTranscoder
      Type Parameters:
      T - the type of the fragment being encoded.
      Parameters:
      value - the value to encode.
      Returns:
      a ByteBuf representation of the fragment value.
      Throws:
      TranscodingException - if the encoding couldn't happen.
    • encodeWithMessage

      public <T> com.couchbase.client.deps.io.netty.buffer.ByteBuf encodeWithMessage​(T value, String transcodingErrorMessage) throws TranscodingException
      Description copied from interface: FragmentTranscoder
      Encode a value to a ByteBuf suitable for use in the sub-document protocol.
      Specified by:
      encodeWithMessage in interface FragmentTranscoder
      Type Parameters:
      T - the type of the fragment being encoded.
      Parameters:
      value - the value to encode.
      transcodingErrorMessage - the error message to be used in the thrown TranscodingException if the encoding couldn't happen.
      Returns:
      a ByteBuf representation of the fragment value.
      Throws:
      TranscodingException - if the encoding couldn't happen.
    • doEncodeSingle

      protected abstract <T> com.couchbase.client.deps.io.netty.buffer.ByteBuf doEncodeSingle​(T value, String transcodingErrorMessage) throws TranscodingException
      Encode a single mutation value to a ByteBuf suitable for use in the sub-document protocol.
      Type Parameters:
      T - the type of the fragment being encoded.
      Parameters:
      value - the value to encode.
      transcodingErrorMessage - the error message to be used in the thrown TranscodingException if the encoding couldn't happen.
      Returns:
      a ByteBuf representation of the fragment value.
      Throws:
      TranscodingException - if the encoding couldn't happen.
    • doEncodeMulti

      protected abstract com.couchbase.client.deps.io.netty.buffer.ByteBuf doEncodeMulti​(MultiValue<?> multiValue, String transcodingErrorMessage) throws TranscodingException
      Encode a special mutation value that denotes multiple values being processed in bulk, to a ByteBuf suitable for use in the sub-document protocol.
      Parameters:
      multiValue - the multivalue to encode.
      transcodingErrorMessage - the error message to be used in the thrown TranscodingException if the encoding couldn't happen.
      Returns:
      a ByteBuf representation of the fragment multivalue.
      Throws:
      TranscodingException - if the encoding couldn't happen.