Class AbstractTranscoder<D extends Document<T>,​T>

java.lang.Object
com.couchbase.client.java.transcoder.AbstractTranscoder<D,​T>
All Implemented Interfaces:
Transcoder<D,​T>
Direct Known Subclasses:
BinaryTranscoder, ByteArrayTranscoder, JsonArrayTranscoder, JsonBooleanTranscoder, JsonCryptoTranscoder, JsonDoubleTranscoder, JsonLongTranscoder, JsonStringTranscoder, JsonTranscoder, LegacyTranscoder, RawJsonTranscoder, SerializableTranscoder, StringTranscoder

public abstract class AbstractTranscoder<D extends Document<T>,​T>
extends Object
implements Transcoder<D,​T>
Base Transcoder which should be extended for compatibility.
Since:
2.0
Author:
Michael Nitschinger, Simon Baslé
  • Constructor Details

    • AbstractTranscoder

      public AbstractTranscoder()
  • Method Details

    • decode

      public D decode​(String id, com.couchbase.client.deps.io.netty.buffer.ByteBuf content, long cas, int expiry, int flags, ResponseStatus status)
      Specified by:
      decode in interface Transcoder<D extends Document<T>,​T>
    • encode

      public Tuple2<com.couchbase.client.deps.io.netty.buffer.ByteBuf,​Integer> encode​(D document)
      Specified by:
      encode in interface Transcoder<D extends Document<T>,​T>
    • doDecode

      protected abstract D doDecode​(String id, com.couchbase.client.deps.io.netty.buffer.ByteBuf content, long cas, int expiry, int flags, ResponseStatus status) throws Exception
      Perform the decoding of the received response.
      Parameters:
      id - the id of the document.
      content - the encoded content of the document.
      cas - the cas value of the document.
      expiry - the expiration time of the document.
      flags - the flags set on the document.
      status - the response status.
      Returns:
      the decoded document.
      Throws:
      Exception - if something goes wrong during the decode process.
    • doEncode

      protected abstract Tuple2<com.couchbase.client.deps.io.netty.buffer.ByteBuf,​Integer> doEncode​(D document) throws Exception
      Perform the encoding of the request document.
      Parameters:
      document - the document to encode.
      Returns:
      A tuple consisting of the encoded content and the flags to set.
      Throws:
      Exception - if something goes wrong during the encode process.
    • shouldAutoReleaseOnDecode

      protected boolean shouldAutoReleaseOnDecode()
      Flag method to auto release decoded buffers. Override to change default behaviour (true).
      Returns:
      true if the ByteBuf passed to decode method is to be released automatically on success (default behaviour)
    • shouldAutoReleaseOnError

      protected boolean shouldAutoReleaseOnError()
      Flag method to auto release buffers on decoding error. Override to change default behaviour (true).
      Returns:
      true if the ByteBuf passed to decode method is to be released automatically in case of error (default behaviour)
    • newDocument

      public D newDocument​(String id, int expiry, T content, long cas, MutationToken mutationToken)
      Default implementation for backwards compatibility.
      Specified by:
      newDocument in interface Transcoder<D extends Document<T>,​T>
      Parameters:
      id - the id of the document.
      expiry - the document expiration.
      content - the document content.
      cas - the documents cas value.
      mutationToken - the documents mutation token.
      Returns:
      the created document.