### Question:
BcdPrefixer implements Prefixer { @Override public void encodeLength(int length, byte[] b) { for (int i = getPackedLength() - 1; i >= 0; i--) { int twoDigits = length % 100; length /= 100; b[i] = (byte)((twoDigits / 10 << 4) + twoDigits % 10); } } BcdPrefixer(int nDigits); @Override void encodeLength(int length, byte[] b); @Override int decodeLength(byte[] b, int offset); @Override int getPackedLength(); static final BcdPrefixer L; static final BcdPrefixer LL; static final BcdPrefixer LLL; static final BcdPrefixer LLLL; static final BcdPrefixer LLLLL; }### Answer:
@Test public void testEncode() throws Exception { byte[] b = new byte[1]; BcdPrefixer.LL.encodeLength(21, b); TestUtils.assertEquals(new byte[]{0x21}, b); }
@Test public void testEncodeShortLength() throws Exception { byte[] b = new byte[1]; BcdPrefixer.LL.encodeLength(3, b); TestUtils.assertEquals(new byte[]{0x03}, b); }
@Test public void testEncodeLLL() throws Exception { byte[] b = new byte[2]; BcdPrefixer.LLL.encodeLength(321, b); TestUtils.assertEquals(new byte[]{0x03, 0x21}, b); }
@Test public void testEncodeLLLShortLength() throws Exception { byte[] b = new byte[2]; BcdPrefixer.LLL.encodeLength(3, b); TestUtils.assertEquals(new byte[]{0x00, 0x03}, b); }
@Test public void testEncode99() throws Exception { byte[] b = new byte[1]; BcdPrefixer.LL.encodeLength(99, b); TestUtils.assertEquals(new byte[]{(byte)0x99}, b); }