Callback { public static ValueExpression crc32(final ValueExpression target) { return new UnaryValueExpression(target) { @Override public Optional<Value> eval(final Value value, final ParseState parseState, final Encoding encoding) { final CRC32 crc = new CRC32(); crc.update(value.value()); final long crcValue = crc.getValue(); return Optional.of(new CoreValue(createFromBytes(encoding.byteOrder.apply(new byte[] { (byte)((crcValue & 0xff000000) >> 24), (byte)((crcValue & 0xff0000) >> 16), (byte)((crcValue & 0xff00) >> 8), (byte) (crcValue & 0xff) })), encoding)); } }; } private  Callback(); static ValueExpression crc32(final ValueExpression target);  }
@Test public void crc32Good() { final ImmutableList<Value> result = crc32(con(0x01020304)).eval(stream(), enc()); assertEquals(1, result.size); assertArrayEquals(new byte[] { -74, 60, -5, -51 }, result.head.value()); }