Inheritance: Erlang.Object
Ejemplo n.º 1
0
        /*
         * Create an Erlang {@link Port port}. Erlang ports are
         * based upon some node specific information; this method creates a
         * port using the information in this node. Each call to this method
         * produces a unique port. It may not be meaningful to create a port
         * in a non-Erlang environment, but this method is provided for
         * completeness.
         *
         * @return an Erlang port.
         **/
        public virtual Erlang.Port createPort()
        {
            lock (this)
            {
                Erlang.Port p = new Erlang.Port(_node, portCount, _creation);

                portCount++;
                if (portCount > 0x3ffff)
                {
                    portCount = 0;
                }

                return(p);
            }
        }
Ejemplo n.º 2
0
 public int encode_size(Erlang.Object o)
 {
     if (o is Erlang.Atom)
     {
         return(1 + 2 + o.atomValue().Length);
     }
     else if (o is Erlang.Boolean)
     {
         return(1 + 2 + (o.boolValue()
                                               ? Erlang.Boolean.s_true.atomValue().Length
                                               : Erlang.Boolean.s_false.atomValue().Length));
     }
     else if (o is Erlang.Binary)
     {
         return(5 + o.binaryValue().Length);
     }
     else if (o is Erlang.Long)
     {
         long l = o.longValue();
         if ((l & 0xff) == l)
         {
             return(2);
         }
         else if ((l <= OtpExternal.erlMax) && (l >= OtpExternal.erlMin))
         {
             return(5);
         }
         return(long_arity(l));
     }
     else if (o is Erlang.Byte)
     {
         return(1 + 1);
     }
     else if (o is Erlang.Double)
     {
         return(9);
     }
     else if (o is Erlang.String)
     {
         string l = o.stringValue();
         if (l.Length == 0)
         {
             return(1);
         }
         if (l.Length < 0xffff)
         {
             return(2 + l.Length);
         }
         return(1 + 4 + 2 * l.Length);
     }
     else if (o is Erlang.List)
     {
         Erlang.List l = o.listValue();
         if (l.arity() == 0)
         {
             return(1);
         }
         int sz = 5;
         for (int i = 0; i < l.arity(); i++)
         {
             sz += encode_size(l[i]);
         }
         return(sz);
     }
     else if (o is Erlang.Tuple)
     {
         Erlang.Tuple l  = o.tupleValue();
         int          sz = 1 + (l.arity() < 0xff ? 1 : 4);
         for (int i = 0; i < l.arity(); i++)
         {
             sz += encode_size(l[i]);
         }
         return(sz);
     }
     else if (o is Erlang.Pid)
     {
         Erlang.Pid p = o.pidValue();
         return(1 + (1 + 2 + p.node().Length) + 4 + 4 + 1);
     }
     else if (o is Erlang.Ref)
     {
         Erlang.Ref p   = o.refValue();
         int[]      ids = p.ids();
         return(1 + (1 + 2 + p.node().Length) + 1 + 4 * ids.Length);
     }
     else if (o is Erlang.Port)
     {
         Erlang.Port p = o.portValue();
         return(1 + (1 + 2 + p.node().Length) + 4 + 1);
     }
     else
     {
         throw new Erlang.Exception("Unknown encode size for object: " + o.ToString());
     }
 }
Ejemplo n.º 3
0
        /*
        * Create an Erlang {@link Port port}. Erlang ports are
        * based upon some node specific information; this method creates a
        * port using the information in this node. Each call to this method
        * produces a unique port. It may not be meaningful to create a port
        * in a non-Erlang environment, but this method is provided for
        * completeness.
        *
        * @return an Erlang port.
        **/
        public virtual Erlang.Port createPort()
        {
            lock(this)
            {
                Erlang.Port p = new Erlang.Port(_node, portCount, _creation);

                portCount++;
                if (portCount > 0x3ffff)
                    portCount = 0;

                return p;
            }
        }
Ejemplo n.º 4
0
 public void TestEncodeDecode()
 {
     {
         OtpOutputStream os  = new OtpOutputStream(new Erlang.Atom("abc"));
         OtpInputStream  ins = new OtpInputStream(os.getBuffer(), 0, os.size());
         Assert.IsTrue("abc" == ins.read_atom());
     }
     {
         OtpOutputStream os  = new OtpOutputStream(new Erlang.String("string"));
         OtpInputStream  ins = new OtpInputStream(os.getBuffer(), 0, os.size());
         Assert.IsTrue("string" == ins.read_string());
     }
     {
         Erlang.Pid      pid = new Erlang.Pid("abc", 1, 2, 3);
         OtpOutputStream os  = new OtpOutputStream(pid);
         OtpInputStream  ins = new OtpInputStream(os.getBuffer(), 0, os.size());
         Assert.IsTrue(pid.Equals(ins.read_pid()));
     }
     {
         Erlang.Port     p   = new Erlang.Port("abc", 1, 2);
         OtpOutputStream os  = new OtpOutputStream(p);
         OtpInputStream  ins = new OtpInputStream(os.getBuffer(), 0, os.size());
         Assert.IsTrue(p.Equals(ins.read_port()));
     }
     {
         Erlang.Ref p = new Erlang.Ref("abc", new int[3] {
             1, 2, 3
         }, 2);
         OtpOutputStream os  = new OtpOutputStream(p);
         OtpInputStream  ins = new OtpInputStream(os.getBuffer(), 0, os.size());
         Assert.IsTrue(p.Equals(ins.read_ref()));
     }
     {
         OtpOutputStream os = new OtpOutputStream();
         os.write_long(1);
         OtpInputStream ins = new OtpInputStream(os.getBuffer(), 0, os.size());
         long           n   = ins.read_long();
         Assert.IsTrue(1 == n);
     }
     {
         OtpOutputStream os = new OtpOutputStream();
         os.write_long(0xFFFFFF);
         OtpInputStream ins = new OtpInputStream(os.getBuffer(), 0, os.size());
         long           n   = ins.read_long();
         Assert.IsTrue(0xFFFFFF == n);
     }
     {
         OtpOutputStream os = new OtpOutputStream();
         os.write_long(0xFFFFFFFF);
         OtpInputStream ins = new OtpInputStream(os.getBuffer(), 0, os.size());
         long           n   = ins.read_long();
         Assert.IsTrue(0xFFFFFFFF == n);
     }
     {
         OtpOutputStream os = new OtpOutputStream();
         os.write_ulong((ulong)0xFFFFFFFFFF);
         OtpInputStream ins = new OtpInputStream(os.getBuffer(), 0, os.size());
         ulong          n   = ins.read_ulong();
         Assert.IsTrue((ulong)0xFFFFFFFFFF == n);
     }
     {
         OtpOutputStream os = new OtpOutputStream();
         os.write_ulong((ulong)0xFFFFFFFFFFFF);
         OtpInputStream ins = new OtpInputStream(os.getBuffer(), 0, os.size());
         ulong          n   = ins.read_ulong();
         Assert.IsTrue((ulong)0xFFFFFFFFFFFF == n);
     }
     {
         OtpOutputStream os = new OtpOutputStream();
         os.write_ulong((ulong)0xFFFFFFFFFFFFFF);
         OtpInputStream ins = new OtpInputStream(os.getBuffer(), 0, os.size());
         ulong          n   = ins.read_ulong();
         Assert.IsTrue((ulong)0xFFFFFFFFFFFFFF == n);
     }
     {
         OtpOutputStream os = new OtpOutputStream();
         os.write_ulong((ulong)0xFFFFFFFFFFFFFFFF);
         OtpInputStream ins = new OtpInputStream(os.getBuffer(), 0, os.size());
         ulong          n   = ins.read_ulong();
         Assert.IsTrue((ulong)0xFFFFFFFFFFFFFFFF == n);
     }
 }