Add debugString() method
This commit is contained in:
@@ -318,6 +318,26 @@ public class IsoMessage {
|
|||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Creates a BitSet for the bitmap. */
|
||||||
|
protected BitSet createBitmapBitSet() {
|
||||||
|
BitSet bs = new BitSet(forceb2 ? 128 : 64);
|
||||||
|
for (int i = 2 ; i < 129; i++) {
|
||||||
|
if (fields[i] != null) {
|
||||||
|
bs.set(i - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (forceb2) {
|
||||||
|
bs.set(0);
|
||||||
|
} else if (bs.length() > 64) {
|
||||||
|
//Extend to 128 if needed
|
||||||
|
BitSet b2 = new BitSet(128);
|
||||||
|
b2.or(bs);
|
||||||
|
bs = b2;
|
||||||
|
bs.set(0);
|
||||||
|
}
|
||||||
|
return bs;
|
||||||
|
}
|
||||||
|
|
||||||
/** This calls writeInternal(), allowing applications to get the byte buffer containing the
|
/** This calls writeInternal(), allowing applications to get the byte buffer containing the
|
||||||
* message data, without the length header. */
|
* message data, without the length header. */
|
||||||
public byte[] writeData() {
|
public byte[] writeData() {
|
||||||
@@ -342,21 +362,7 @@ public class IsoMessage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Bitmap
|
//Bitmap
|
||||||
BitSet bs = new BitSet(forceb2 ? 128 : 64);
|
BitSet bs = createBitmapBitSet();
|
||||||
for (int i = 2 ; i < 129; i++) {
|
|
||||||
if (fields[i] != null) {
|
|
||||||
bs.set(i - 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (forceb2) {
|
|
||||||
bs.set(0);
|
|
||||||
} else if (bs.length() > 64) {
|
|
||||||
//Extend to 128 if needed
|
|
||||||
BitSet b2 = new BitSet(128);
|
|
||||||
b2.or(bs);
|
|
||||||
bs = b2;
|
|
||||||
bs.set(0);
|
|
||||||
}
|
|
||||||
//Write bitmap to stream
|
//Write bitmap to stream
|
||||||
if (binary || binBitmap) {
|
if (binary || binBitmap) {
|
||||||
int pos = 128;
|
int pos = 128;
|
||||||
@@ -417,6 +423,42 @@ public class IsoMessage {
|
|||||||
return bout.toByteArray();
|
return bout.toByteArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Returns a string representation of the message, as if it were encoded
|
||||||
|
* in ASCII with no binary bitmap. */
|
||||||
|
public String debugString() {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
if (isoHeader != null) {
|
||||||
|
sb.append(isoHeader);
|
||||||
|
}
|
||||||
|
sb.append(String.format("%04x", type));
|
||||||
|
|
||||||
|
//Bitmap
|
||||||
|
BitSet bs = createBitmapBitSet();
|
||||||
|
int pos = 0;
|
||||||
|
int lim = bs.size() / 4;
|
||||||
|
for (int i = 0; i < lim; i++) {
|
||||||
|
int nibble = 0;
|
||||||
|
if (bs.get(pos++))
|
||||||
|
nibble |= 8;
|
||||||
|
if (bs.get(pos++))
|
||||||
|
nibble |= 4;
|
||||||
|
if (bs.get(pos++))
|
||||||
|
nibble |= 2;
|
||||||
|
if (bs.get(pos++))
|
||||||
|
nibble |= 1;
|
||||||
|
sb.append(HEX[nibble]);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Fields
|
||||||
|
for (int i = 2; i < 129; i++) {
|
||||||
|
IsoValue<?> v = fields[i];
|
||||||
|
if (v != null) {
|
||||||
|
sb.append(v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
//These are for Groovy compat
|
//These are for Groovy compat
|
||||||
/** Sets the specified value in the specified field, just like {@link #setField(int, IsoValue)}. */
|
/** Sets the specified value in the specified field, just like {@link #setField(int, IsoValue)}. */
|
||||||
public <T> void putAt(int i, IsoValue<T> v) {
|
public <T> void putAt(int i, IsoValue<T> v) {
|
||||||
|
|||||||
Reference in New Issue
Block a user