code: public int read_tuple_head() throws OtpErlangDecodeException {
          int arity = 0;
          final int tag = read1skip_version();
  
          // decode the tuple header and get arity
          switch (tag) {
          case OtpExternal.smallTupleTag:
              arity = read1();
              break;
  
          case OtpExternal.largeTupleTag:
              arity = read4BE();
              break;
  
          default:
              throw new OtpErlangDecodeException("Not valid tuple tag: " + tag);
          }
  
          return arity;
      }
docs: Read a tuple header from the stream.
  
  @return the arity of the tuple.
  
  @exception OtpErlangDecodeException
  if the next term in the stream is not a tuple.