RLPark 1.0.0
Reinforcement Learning Framework in Java
|
00001 package rlpark.plugin.robot.internal.disco.drops; 00002 00003 import rlpark.plugin.robot.internal.sync.LiteByteBuffer; 00004 00005 public class DropByteArray extends DropData { 00006 private final byte[] value; 00007 00008 public DropByteArray(String label, int length) { 00009 this(label, false, length, -1); 00010 } 00011 00012 public DropByteArray(String label, boolean readonly, int length, int index) { 00013 super(label, readonly, index); 00014 value = new byte[length]; 00015 } 00016 00017 @Override 00018 public DropData clone(String label, int index) { 00019 return new DropByteArray(label, readOnly, value.length, index); 00020 } 00021 00022 @Override 00023 public void putData(LiteByteBuffer buffer) { 00024 for (byte c : value) 00025 buffer.put(c); 00026 } 00027 00028 @Override 00029 public int size() { 00030 return value.length * DropData.CharSize; 00031 } 00032 00033 public byte[] value() { 00034 return value; 00035 } 00036 00037 public void setValue(char[] chars) { 00038 setValue(toBytes(chars)); 00039 } 00040 00041 static public byte[] toBytes(char[] chars) { 00042 byte[] result = new byte[chars.length]; 00043 for (int i = 0; i < result.length; i++) 00044 result[i] = (byte) chars[i]; 00045 return result; 00046 } 00047 00048 static public byte[] toBytes(int[] ints) { 00049 byte[] result = new byte[ints.length]; 00050 for (int i = 0; i < result.length; i++) 00051 result[i] = (byte) ints[i]; 00052 return result; 00053 } 00054 00055 public void setValue(byte[] message) { 00056 System.arraycopy(message, 0, value, 0, value.length); 00057 } 00058 00059 public byte[] getPascalStringValue() { 00060 byte[] result = new byte[value[0]]; 00061 System.arraycopy(value, 1, result, 0, result.length); 00062 return result; 00063 } 00064 00065 public void setPascalStringValue(char[] message) { 00066 setPascalStringValue(toBytes(message)); 00067 } 00068 00069 public void setPascalStringValue(byte[] message) { 00070 value[0] = (byte) message.length; 00071 System.arraycopy(message, 0, value, 1, message.length); 00072 } 00073 00074 }