All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.mentalog.encoder.Encoder Maven / Gradle / Ivy

There is a newer version: 2.1.2
Show newest version
package org.mentalog.encoder;

import java.nio.ByteBuffer;

/**
 * An interface that you can use to encode any object inside a ByteBuffer. This is important to avoid calling toString() in the objects passed to the log() method. For example,
 * MentaLog already comes with encoders for null, CharSequences, and byte/char arrays that do not create any strings (garbage).
 * 
 * Refer to: http://mentalog.soliveirajr.com for documentations, recipes and more.
 * 
 * @author Sergio Oliveira Jr. - [email protected]
 */
public interface Encoder {
	
	public static final Encoder NULL = new NullEncoder();
	public static final Encoder CHAR_SEQUENCE = new CharSequenceEncoder();
	public static final Encoder BYTE_OR_CHAR_ARRAY = new ByteOrCharArrayEncoder();
	public static final Encoder THROWABLE = new ThrowableEncoder();
	public static final Encoder ASCII = new AsciiEncoder();
	
	/**
	 * Encode the given object into the provided byte buffer.
	 * 
	 * Note: You should use instanceof to check and cast the object to a type that this encoder can encode.
	 * Each encoder receives all objects passed to the log() method. If a encoder receives an object it does not
	 * support, it does nothing and returns false, so the next encoder in the chain will be applied.
	 * 
	 * @param obj That object to be encoded.
	 * @param dest The byte buffer that will receive the encoded object.
	 * @return true if the object was encoded, false otherwise
	 */
	public boolean encode(Object obj, ByteBuffer dest, int varargsPos, int varargsLen);
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy