private static byte[] packMap(Map<String, String> map) { Buffer<?> buf = new Buffer.PlainBuffer(); List<String> keys = new ArrayList<String>(map.keySet()); Collections.sort(keys); for (String key : keys) { buf.putString(key); String value = map.get(key); buf.putString(packString(value)); } return buf.getCompactData(); } }
private static byte[] packList(Iterable<String> strings) { Buffer<?> buf = new Buffer.PlainBuffer(); for (String string : strings) { buf.putString(string); } return buf.getCompactData(); }
@Test public void shouldCorrectlyEncodeAndDecodeUInt64Types() throws BufferException { // This number fits into a unsigned 64 bit integer but not a signed one. BigInteger bigUint64 = BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.ONE).add(BigInteger.ONE); assertEquals(0x8000000000000001l, bigUint64.longValue()); Buffer<PlainBuffer> buff = new PlainBuffer(); buff.putUInt64(bigUint64); byte[] data = buff.getCompactData(); assertEquals(8, data.length); assertEquals((byte) 0x80, data[0]); assertEquals((byte) 0x00, data[1]); assertEquals((byte) 0x00, data[2]); assertEquals((byte) 0x00, data[3]); assertEquals((byte) 0x00, data[4]); assertEquals((byte) 0x00, data[5]); assertEquals((byte) 0x00, data[6]); assertEquals((byte) 0x01, data[7]); byte[] asBinary = new byte[] { (byte) 0x80, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01 }; buff = new PlainBuffer(asBinary); assertEquals(bigUint64, buff.readUInt64AsBigInteger()); }
private static byte[] packList(Iterable<String> strings) { Buffer<?> buf = new Buffer.PlainBuffer(); for (String string : strings) { buf.putString(string); } return buf.getCompactData(); }
@Override public byte[] encode(byte[] sig) { int rIndex = 3; int rLen = sig[rIndex++] & 0xff; byte[] r = new byte[rLen]; System.arraycopy(sig, rIndex, r, 0, r.length); int sIndex = rIndex + rLen + 1; int sLen = sig[sIndex++] & 0xff; byte[] s = new byte[sLen]; System.arraycopy(sig, sIndex, s, 0, s.length); System.arraycopy(sig, 4, r, 0, rLen); System.arraycopy(sig, 6 + rLen, s, 0, sLen); Buffer buf = new Buffer.PlainBuffer(); buf.putMPInt(new BigInteger(r)); buf.putMPInt(new BigInteger(s)); return buf.getCompactData(); }
private static byte[] packMap(Map<String, String> map) { Buffer<?> buf = new Buffer.PlainBuffer(); List<String> keys = new ArrayList<String>(map.keySet()); Collections.sort(keys); for (String key : keys) { buf.putString(key); String value = map.get(key); buf.putString(packString(value)); } return buf.getCompactData(); } }