progress towards REO compatibility
This commit is contained in:
parent
a59f865e59
commit
6bfd2b54c2
|
@ -32,6 +32,7 @@ public class IniFileModel {
|
||||||
public Map<String, IniField> allIniFields = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
public Map<String, IniField> allIniFields = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
||||||
|
|
||||||
public Map<String, String> tooltips = new TreeMap<>();
|
public Map<String, String> tooltips = new TreeMap<>();
|
||||||
|
public Map<String, String> protocolMeta = new TreeMap<>();
|
||||||
private boolean isConstantsSection;
|
private boolean isConstantsSection;
|
||||||
private String currentSection;
|
private String currentSection;
|
||||||
|
|
||||||
|
@ -141,10 +142,16 @@ public class IniFileModel {
|
||||||
isConstantsSection = first.equals("[Constants]");
|
isConstantsSection = first.equals("[Constants]");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isInsidePageDefinition && isConstantsSection) {
|
if (isConstantsSection) {
|
||||||
if (list.size() > 1)
|
if (isInsidePageDefinition) {
|
||||||
handleFieldDefinition(list);
|
if (list.size() > 1)
|
||||||
return;
|
handleFieldDefinition(list);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
if (list.size() > 1) {
|
||||||
|
protocolMeta.put(list.get(0), list.get(1));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,44 @@
|
||||||
|
package com.opensr5.ini;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ProtocolCommand {
|
||||||
|
|
||||||
|
private final byte[] bytes;
|
||||||
|
|
||||||
|
public ProtocolCommand(byte[] bytes) {
|
||||||
|
this.bytes = bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] getBytes() {
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ProtocolCommand parse(String meta) {
|
||||||
|
// todo: support placeholders
|
||||||
|
|
||||||
|
List<Byte> result = new ArrayList<>();
|
||||||
|
|
||||||
|
for (int i = 0; i < meta.length(); i++) {
|
||||||
|
char c = meta.charAt(i);
|
||||||
|
if (c == '\\') {
|
||||||
|
char next = meta.charAt(i + 1);
|
||||||
|
if (next != 'x')
|
||||||
|
throw new IllegalArgumentException("Unexpected symbol: " + next);
|
||||||
|
String hex = meta.substring(i + 2, i + 4);
|
||||||
|
result.add(Byte.parseByte(hex, 16));
|
||||||
|
i += 3;
|
||||||
|
} else {
|
||||||
|
result.add((byte) c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] bytes = new byte[result.size()];
|
||||||
|
for (int i = 0; i < result.size(); i++)
|
||||||
|
bytes[i] = result.get(i);
|
||||||
|
|
||||||
|
return new ProtocolCommand(bytes);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,9 +1,6 @@
|
||||||
package com.opensr5.ini.test;
|
package com.opensr5.ini.test;
|
||||||
|
|
||||||
import com.opensr5.ini.IniFileMetaInfo;
|
import com.opensr5.ini.*;
|
||||||
import com.opensr5.ini.IniFileModel;
|
|
||||||
import com.opensr5.ini.IniFileReader;
|
|
||||||
import com.opensr5.ini.RawIniFile;
|
|
||||||
import com.opensr5.ini.field.ArrayIniField;
|
import com.opensr5.ini.field.ArrayIniField;
|
||||||
import com.opensr5.ini.field.EnumIniField;
|
import com.opensr5.ini.field.EnumIniField;
|
||||||
import com.opensr5.ini.field.IniField;
|
import com.opensr5.ini.field.IniField;
|
||||||
|
@ -11,9 +8,9 @@ import org.jetbrains.annotations.NotNull;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.*;
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Andrey Belomutskiy, (c) 2013-2020
|
* Andrey Belomutskiy, (c) 2013-2020
|
||||||
|
@ -112,6 +109,26 @@ public class IniFileReaderTest {
|
||||||
return IniFileReader.read(new ByteArrayInputStream(string.getBytes()));
|
return IniFileReader.read(new ByteArrayInputStream(string.getBytes()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testProtocolMeta() {
|
||||||
|
String string =
|
||||||
|
"[Constants]\n" +
|
||||||
|
" crc32CheckCommand = \"k\\x00\\x00\\x00\\x00\\x00\\x00\"\n" +
|
||||||
|
"page = 1\n" +
|
||||||
|
"primingSquirtDurationMs\t\t\t= scalar, F32,\t96,\t\"*C\", 1, 0, -40, 200, 1\n" +
|
||||||
|
"";
|
||||||
|
RawIniFile lines = IniFileReader.read(new ByteArrayInputStream(string.getBytes()));
|
||||||
|
IniFileModel model = new IniFileModel().readIniFile(lines);
|
||||||
|
assertEquals(1, model.allIniFields.size());
|
||||||
|
|
||||||
|
String crcProtocol = model.protocolMeta.get("crc32CheckCommand");
|
||||||
|
assertEquals("k\\x00\\x00\\x00\\x00\\x00\\x00", crcProtocol);
|
||||||
|
|
||||||
|
byte[] expected = {'k', 0, 0, 0, 0, 0, 0};
|
||||||
|
|
||||||
|
assertTrue(Arrays.equals(expected, ProtocolCommand.parse(crcProtocol).getBytes()));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEasyFields() {
|
public void testEasyFields() {
|
||||||
String string = "page = 1\n" +
|
String string = "page = 1\n" +
|
||||||
|
@ -174,9 +191,8 @@ public class IniFileReaderTest {
|
||||||
" \tname2\t\t\t= array, F32,\t108,\t[8],\t\"\", 1, 0, 0.0, 18000, 2\n" +
|
" \tname2\t\t\t= array, F32,\t108,\t[8],\t\"\", 1, 0, 0.0, 18000, 2\n" +
|
||||||
"[Constants]\n" +
|
"[Constants]\n" +
|
||||||
" \tname\t\t\t= array, F32,\t108,\t[8],\t\"\", 1, 0, 0.0, 18000, 2\n" +
|
" \tname\t\t\t= array, F32,\t108,\t[8],\t\"\", 1, 0, 0.0, 18000, 2\n" +
|
||||||
"[PcVariables]\n" +
|
"[PcVariables]\n" +
|
||||||
" \tname3\t\t\t= array, F32,\t108,\t[8],\t\"\", 1, 0, 0.0, 18000, 2\n"
|
" \tname3\t\t\t= array, F32,\t108,\t[8],\t\"\", 1, 0, 0.0, 18000, 2\n";
|
||||||
;
|
|
||||||
|
|
||||||
RawIniFile lines = IniFileReader.read(new ByteArrayInputStream(string.getBytes()));
|
RawIniFile lines = IniFileReader.read(new ByteArrayInputStream(string.getBytes()));
|
||||||
IniFileModel model = new IniFileModel().readIniFile(lines);
|
IniFileModel model = new IniFileModel().readIniFile(lines);
|
||||||
|
|
Loading…
Reference in New Issue