com.flybotix.hfr.codex.encode.UncompressedEncoder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of highfrequencyrobots Show documentation
Show all versions of highfrequencyrobots Show documentation
A way for wifi robots and IoT devices to quickly send compressed data arrays across a network.
package com.flybotix.hfr.codex.encode;
import java.nio.ByteBuffer;
import com.flybotix.hfr.codex.Codex;
import com.flybotix.hfr.codex.CodexOf;
public class UncompressedEncoder & CodexOf> extends DefaultEncoder {
public UncompressedEncoder(Class pEnum, IEncoderProperties pProps) {
super(pEnum, pProps);
}
public AEncoder createClone() {
return new UncompressedEncoder(getEnum(), mProps);
}
@Override
protected boolean isCompressed() {
return false;
}
@Override
protected Codex decodeImpl(ByteBuffer pData) {
// Codex result = new Codex<>(this);
Codex result = new Codex<>(getDefaultValue(), getEnum());
for(int dataidx = 0; dataidx < mLength; dataidx++) {
result.set(dataidx, mProps.decodeSingle(pData));
}
return result;
}
@Override
protected byte[] encodeImpl(Codex pData) {
ByteBuffer bb = ByteBuffer.allocate(mProps.sizeOfSingle() * mLength);
for(int dataidx = 0; dataidx < mLength; dataidx++) {
mProps.encodeSingle(bb, pData.get(dataidx));
}
return bb.array();
}
}