@Test
public void decode () throws Exception {

  byte[] bytes1 = Bytes.resizableArray()
      .write1B(PORT.getCode())
      .writeNB(new ErlangAtom("popa@localhost").toBytes())
      .write4B(Integer.MAX_VALUE)
      .write1B(Integer.MAX_VALUE)
      .arrayCopy();
  try (val input = new OtpInputStream(bytes1)) {
    ErlangPort port = ErlangTerm.newInstance(wrappedBuffer(bytes1));
    OtpErlangPort otpPid = input.read_port();
    assertThat(port.getDescriptor().getFullName())
        .isEqualTo(otpPid.node());
    assertThat(port.getId())
        .isEqualTo(otpPid.id());
    assertThat(port.getCreation())
        .isEqualTo(otpPid.creation());
  }
  byte[] bytes2 = Bytes.resizableArray()
      .write1B(NEW_PORT.getCode())
      .writeNB(new ErlangAtom("popa@localhost").toBytes())
      .write4B(Integer.MAX_VALUE)
      .write4B(Integer.MAX_VALUE)
      .arrayCopy();
  try (val input = new OtpInputStream(bytes2)) {
    ErlangPort port = ErlangTerm.newInstance(wrappedBuffer(bytes2));
    OtpErlangPort otpPid = input.read_port();
    assertThat(port.getDescriptor().getFullName())
        .isEqualTo(otpPid.node());
    assertThat(port.getId())
        .isEqualTo(otpPid.id());
    assertThat(port.getCreation())
        .isEqualTo(otpPid.creation());
  }
}