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>
BaseTranscoder
which should be extended for compatibility.- Since:
- 2.0
- Author:
- Michael Nitschinger, Simon Baslé
-
-
Constructor Summary
Constructors Constructor Description AbstractTranscoder()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description D
decode(String id, com.couchbase.client.deps.io.netty.buffer.ByteBuf content, long cas, int expiry, int flags, ResponseStatus status)
protected abstract D
doDecode(String id, com.couchbase.client.deps.io.netty.buffer.ByteBuf content, long cas, int expiry, int flags, ResponseStatus status)
Perform the decoding of the received response.protected abstract Tuple2<com.couchbase.client.deps.io.netty.buffer.ByteBuf,Integer>
doEncode(D document)
Perform the encoding of the request document.Tuple2<com.couchbase.client.deps.io.netty.buffer.ByteBuf,Integer>
encode(D document)
D
newDocument(String id, int expiry, T content, long cas, MutationToken mutationToken)
Default implementation for backwards compatibility.protected boolean
shouldAutoReleaseOnDecode()
Flag method to auto release decoded buffers.protected boolean
shouldAutoReleaseOnError()
Flag method to auto release buffers on decoding error.-
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.Transcoder
documentType, newDocument
-
-
-
-
Method Detail
-
decode
public D decode(String id, com.couchbase.client.deps.io.netty.buffer.ByteBuf content, long cas, int expiry, int flags, ResponseStatus status)
-
encode
public Tuple2<com.couchbase.client.deps.io.netty.buffer.ByteBuf,Integer> encode(D document)
-
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 todecode
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 todecode
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 interfaceTranscoder<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.
-
-