K2Informatics.Erlnet.OtpInputStream.read_ref C# (CSharp) Метод

read_ref() публичный Метод

public read_ref ( ) : OtpErlangRef
Результат OtpErlangRef
        public OtpErlangRef read_ref()
        {
            String node;
            int id;
            int creation;
            int tag;

            tag = read1skip_version();

            switch (tag)
            {
                case OtpExternal.refTag:
                    node = read_atom();
                    id = read4BE() & 0x3ffff; // 18 bits
                    creation = read1() & 0x03; // 2 bits
                    return new OtpErlangRef(node, id, creation);

                case OtpExternal.newRefTag:
                    int arity = read2BE();
                    node = read_atom();
                    creation = read1() & 0x03; // 2 bits

                    int[] ids = new int[arity];
                    for (int i = 0; i < arity; i++)
                    {
                        ids[i] = read4BE();
                    }
                    ids[0] &= 0x3ffff; // first id gets truncated to 18 bits
                    return new OtpErlangRef(node, ids, creation);

                default:
                    throw new OtpErlangDecodeException("Wrong tag encountered, expected ref, got " + tag);
            }
        }

Usage Example

Пример #1
0
        /**
         * Create an Erlang ref from a stream containing a ref encoded in Erlang
         * external format.
         *
         * @param buf
         *                the stream containing the encoded ref.
         *
         * @exception OtpErlangDecodeException
         *                    if the buffer does not contain a valid external
         *                    representation of an Erlang ref.
         */
        public OtpErlangRef(OtpInputStream buf)
        {
            OtpErlangRef r = buf.read_ref();

            node = r.Node;
            creation = r.Creation;
            ids = r.Ids;
        }