Change header byte length, add data view by field type

This commit is contained in:
Michael Mikovsky
2025-03-31 11:58:45 -06:00
parent 967dc3c967
commit 5447b64857
33 changed files with 699 additions and 176 deletions
@@ -1,5 +1,7 @@
package com.ridgebotics.ridgescout.utility;
import static com.ridgebotics.ridgescout.utility.fileEditor.lengthHeaderBytes;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
@@ -71,7 +73,7 @@ public class ByteBuilder {
public ByteBuilder addInt(int num, int precision) throws buildingException {
if(precision <= 0){throw new buildingException("Invalid precision: " + precision);}
if(precision > 65536){throw new buildingException("Precision too large (greter than 65536)");}
if(precision > Math.pow(lengthHeaderBytes,8)){throw new buildingException("Precision too large (greter than 16777216)");}
if(precision < getLeastBytePrecision(num)){throw new buildingException("Precision too small");}
if(num > Integer.MAX_VALUE){throw new buildingException("Integer overflow");}
@@ -96,7 +98,7 @@ public class ByteBuilder {
}
public ByteBuilder addString(String str) throws buildingException {
str = blankStrNull(str);
if(str.length() > 65536){throw new buildingException("String too long (greater than 65536)");}
if(str.length() > Math.pow(lengthHeaderBytes,8)){throw new buildingException("String too long (greater than 16777216)");}
stringType stringType = new stringType();
// To get the length correctly, the string bytes need to be precalculated
@@ -175,7 +177,7 @@ public class ByteBuilder {
public ByteBuilder addLong(long num, int precision) throws buildingException {
if(precision <= 0){throw new buildingException("Invalid precision: " + precision);}
if(precision > 65536){throw new buildingException("Precision too large (greter than 65536)");}
if(precision > Math.pow(lengthHeaderBytes,8)){throw new buildingException("Precision too large (greter than 16777216)");}
if(precision < getLeastBytePrecision(num)){throw new buildingException("Precision too small");}
if(num > Long.MAX_VALUE){throw new buildingException("Long overflow");}
@@ -200,7 +202,7 @@ public class ByteBuilder {
}
public ByteBuilder addRaw(int type, byte[] bytes) throws buildingException {
if(bytes.length > 65536){throw new buildingException("Byte array length to long (greater than 65536)");}
if(bytes.length > 16777216){throw new buildingException("Byte array length to long (greater than 16777216)");}
rawType rawType = new rawType();
rawType.type = type;
@@ -213,7 +215,7 @@ public class ByteBuilder {
public byte[] build() throws buildingException {
if(bytesToBuild.size() == 0){throw new buildingException("Cannot build null data");}
int length = bytesToBuild.size() * 3;
int length = bytesToBuild.size() * (lengthHeaderBytes + 1);
for(byteType bt : bytesToBuild){
length += bt.length();
}
@@ -223,12 +225,13 @@ public class ByteBuilder {
for(byteType bt : bytesToBuild){
byte[] blockLength = fileEditor.toBytes(bt.length(), 2);
byte[] blockLength = fileEditor.toBytes(bt.length(), lengthHeaderBytes + 1);
for(int i = 0; i < lengthHeaderBytes; i++) {
bytes[bytesFilled] = blockLength[i];
bytesFilled += 1;
}
bytes[bytesFilled] = blockLength[0];
bytesFilled += 1;
bytes[bytesFilled] = blockLength[1];
bytesFilled += 1;
bytes[bytesFilled] = bt.getType();
bytesFilled += 1;