Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 
 package org.easycluster.easycluster.serialization.bytebean.codec.primitive;
 
TODO

Author(s):
wangqi
Version:
$Id: FloatCodec.java 14 2012-01-10 11:54:14Z archie $
public class FloatCodec extends AbstractPrimitiveCodec implements
	private static final Logger logger = LoggerFactory
	public Class<?>[] getFieldType() {
		return new Class<?>[] { float.classFloat.class };
	}
	public DecResult decode(DecContext ctx) {
		byte[] bytes = ctx.getDecBytes();
		int byteLength = ctx.getByteSize();
		NumberCodec numberCodec = ctx.getNumberCodec();
		if (byteLength > bytes.length) {
			String errmsg = "FloatCodec: not enough bytes for decode, need ["
byteLength + "], actually [" + bytes.length + "].";
			if (null != ctx.getField()) {
				errmsg += "/ cause field is [" + ctx.getField() + "]";
			}
			.error(errmsg);
			throw new RuntimeException(errmsg);
		}
		return new DecResult(numberCodec.bytes2Float(bytesbyteLength),
				ArrayUtils.subarray(bytesbyteLengthbytes.length));
	}
	public byte[] encode(EncContext ctx) {
		float enc = ((Floatctx.getEncObject()).floatValue();
		int byteLength = ctx.getByteSize();
		NumberCodec numberCodec = ctx.getNumberCodec();
		return numberCodec.float2Bytes(encbyteLength);
	}
New to GrepCode? Check out our FAQ X