/**
* copied from KVPairs.class and modified
*/
public static KVBundle fromBin(byte bin[], KVBundleFormat format) {
KVBundle bundle = new KVBundle(format);
int pos = 0;
while (pos < bin.length) {
String key = null;
String val = null;
for (int i = pos; i < bin.length; i++) {
if (bin[i] == 0) {
key = new String(bin, pos, i - pos);
pos = i + 1;
break;
}
if (i == bin.length - 1) {
key = new String(bin, pos, i - pos + 1);
pos = i + 1;
break;
}
}
for (int i = pos; i < bin.length; i++) {
if (bin[i] == 0) {
val = new String(bin, pos, i - pos);
pos = i + 1;
break;
}
if (i == bin.length - 1) {
val = new String(bin, pos, i - pos + 1);
pos = i + 1;
break;
}
}
bundle.setValue(format.getField(key), ValueFactory.create(val));
}
return bundle;
}