public static byte[] tlv(int tagNo, Consumer<Asn1OutputStream> consumer) {
        try (final ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
            try (final Asn1OutputStream out = new Asn1OutputStream(bos, tagNo)) {
                consumer.accept(out);
            }
            return bos.toByteArray();
        } catch (IOException e) {
            throw new Asn1Exception("Unexpected IO exception", e);
        }
    }
@Test
    public void tlvShouldEncode() {
        assertArrayEquals(new byte[] { 0x04, 2, 0x12, 0x34},
            Asn1Utils.tlv(4, (out) -> out.writeInt(0x1234)));
    }