@Override public ByteBuffer readBinaryKey(long encoding) { CachedEncode<K, V> cache = lastMapping; if (cache != null) { Long cachedEncoding = cache.getEncoding(); if (cachedEncoding != null && cachedEncoding == encoding) { return cache.getEncodedKey(); } } ByteBuffer attached = readKeyBuffer(encoding); ByteBuffer detached = ByteBuffer.allocate(attached.remaining()); detached.put(attached).flip(); return detached; }
@Override public ByteBuffer readBinaryValue(long encoding) { CachedEncode<K, V> cache = lastMapping; if (cache != null) { Long cachedEncoding = cache.getEncoding(); if (cachedEncoding != null && cachedEncoding == encoding) { return cache.getEncodedValue(); } } ByteBuffer attached = readValueBuffer(encoding); ByteBuffer detached = ByteBuffer.allocate(attached.remaining()); detached.put(attached).flip(); return detached; }
@Override public final Long writeMapping(K key, V value, int hash, int metadata) { Long result; if (lastMapping != null && lastMapping.getKey() == key && lastMapping.getValue() == value) { result = writeMappingBuffers(lastMapping.getEncodedKey(), lastMapping.getEncodedValue(), hash); } else { ByteBuffer keyBuffer = keyPortability.encode(key); ByteBuffer valueBuffer = valuePortability.encode(value); result = writeMappingBuffers(keyBuffer.duplicate(), valueBuffer.duplicate(), hash); lastMapping = new CachedEncode<>(key, value, keyBuffer, valueBuffer, result); } if (result != null) { fireWritten(key, value, lastMapping.getEncodedKey(), lastMapping.getEncodedValue(), hash, metadata, result); } return result; }
@Override public final Long writeMapping(K key, V value, int hash, int metadata) { Long result; if (lastMapping != null && lastMapping.getKey() == key && lastMapping.getValue() == value) { result = writeMappingBuffers(lastMapping.getEncodedKey(), lastMapping.getEncodedValue(), hash); } else { ByteBuffer keyBuffer = keyPortability.encode(key); ByteBuffer valueBuffer = valuePortability.encode(value); result = writeMappingBuffers(keyBuffer.duplicate(), valueBuffer.duplicate(), hash); lastMapping = new CachedEncode<>(key, value, keyBuffer, valueBuffer, result); } if (result != null) { fireWritten(key, value, lastMapping.getEncodedKey(), lastMapping.getEncodedValue(), hash, metadata, result); } return result; }
@Override public ByteBuffer readBinaryKey(long encoding) { CachedEncode<K, V> cache = lastMapping; if (cache != null) { Long cachedEncoding = cache.getEncoding(); if (cachedEncoding != null && cachedEncoding == encoding) { return cache.getEncodedKey(); } } ByteBuffer attached = readKeyBuffer(encoding); ByteBuffer detached = ByteBuffer.allocate(attached.remaining()); detached.put(attached).flip(); return detached; }
@Override public ByteBuffer readBinaryValue(long encoding) { CachedEncode<K, V> cache = lastMapping; if (cache != null) { Long cachedEncoding = cache.getEncoding(); if (cachedEncoding != null && cachedEncoding == encoding) { return cache.getEncodedValue(); } } ByteBuffer attached = readValueBuffer(encoding); ByteBuffer detached = ByteBuffer.allocate(attached.remaining()); detached.put(attached).flip(); return detached; }