@Test
public void decode () throws Exception {

  byte[] bytes1 = Bytes.resizableArray()
      .write1B(PID.getCode())
      .writeNB(new ErlangAtom("popa@localhost").toBytes())
      .write4B(Integer.MAX_VALUE)
      .write4B(Integer.MAX_VALUE)
      .write1B(Integer.MAX_VALUE)
      .arrayCopy();
  try (val input = new OtpInputStream(bytes1)) {
    ErlangPid pid = ErlangTerm.newInstance(wrappedBuffer(bytes1));
    OtpErlangPid otpPid = input.read_pid();
    assertThat(pid.getDescriptor().getFullName())
        .isEqualTo(otpPid.node());
    assertThat(pid.getId())
        .isEqualTo(otpPid.id());
    assertThat(pid.getCreation())
        .isEqualTo(otpPid.creation());
    assertThat(pid.getSerial())
        .isEqualTo(otpPid.serial());
  }
  byte[] bytes2 = Bytes.resizableArray()
      .write1B(NEW_PID.getCode())
      .writeNB(new ErlangAtom("popa@localhost").toBytes())
      .write4B(Integer.MAX_VALUE)
      .write4B(Integer.MAX_VALUE)
      .write4B(Integer.MAX_VALUE)
      .arrayCopy();
  try (val input = new OtpInputStream(bytes2)) {
    ErlangPid pid = ErlangTerm.newInstance(wrappedBuffer(bytes2));
    OtpErlangPid otpPid = input.read_pid();
    assertThat(pid.getDescriptor().getFullName())
        .isEqualTo(otpPid.node());
    assertThat(pid.getId())
        .isEqualTo(otpPid.id());
    assertThat(pid.getCreation())
        .isEqualTo(otpPid.creation());
    assertThat(pid.getSerial())
        .isEqualTo(otpPid.serial());
  }
}