-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add data compression to PositionForwarderWialon #5455
Conversation
|
ByteArrayOutputStream container = new ByteArrayOutputStream(); | ||
|
||
container.write(0xFF); | ||
|
||
int dataLength = data.length; | ||
ByteBuffer lengthBuffer = ByteBuffer.allocate(2).order(ByteOrder.LITTLE_ENDIAN); | ||
lengthBuffer.putShort((short) dataLength); | ||
container.write(lengthBuffer.array(), 0, 2); | ||
|
||
container.write(data, 0, dataLength); | ||
|
||
return container.toByteArray(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using Netty buffers can probably make this much cleaner.
Should i just wrap this feature with And maybe we need to change protocol version from hardcode at MainModule to config option? |
I think it would be better to just have a constructor parameter to enable/disable ZIP. |
Disabled by default? |
Yes, I prefer disabled by default because then the format will be compatible with Traccar. |
@@ -111,6 +129,33 @@ public void forward(PositionData positionData, ResultHandler resultHandler) { | |||
} | |||
} | |||
|
|||
public static byte[] compressData(byte[] data) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would probably just combine the two methods to avoid two buffers.
If data is bigger then MTU, UDP won't allow to send this. I try to change UDP to TCP, chunk data, but compression do it's best.
Compression is described at the end of this docs: https://extapi.wialon.com/hw/cfg/Wialon%20IPS_en_v_2_0.pdf
Tested on Wialon and build looks fine.