Пример #1
0
        public async Task <Dictionary <string, PropDesc> > InspectObject(KiRef handle, int start, int end)
        {
            var reply = await DoRequest(KiTag.REQ, KiRequest.InspectObject, handle, start, end);

            var props = new Dictionary <string, PropDesc>();
            int i     = 1;

            while (i < reply.Length)
            {
                string    key   = reply[i++].ToString();
                PropFlags flags = (PropFlags)(int)reply[i++];
                if (flags.HasFlag(PropFlags.Accessor))
                {
                    KiAtom   getter    = reply[i++];
                    KiAtom   setter    = reply[i++];
                    PropDesc propValue = new PropDesc(getter, setter, flags);
                    if (!flags.HasFlag(PropFlags.Internal))
                    {
                        props.Add(key, propValue);
                    }
                }
                else
                {
                    KiAtom   value     = reply[i++];
                    PropDesc propValue = new PropDesc(value, flags);
                    if (!flags.HasFlag(PropFlags.Internal))
                    {
                        props.Add(key, propValue);
                    }
                }
            }
            return(props);
        }
Пример #2
0
 public KiAtom(KiRef handle)
 {
     m_tag   = KiTag.Ref;
     m_value = handle;
 }
Пример #3
0
        public static KiAtom Receive(Socket socket)
        {
            byte initialByte;

            byte[]   bytes;
            int      length = -1;
            Encoding utf8   = new UTF8Encoding(false);

            if (!socket.ReceiveAll(bytes = new byte[1]))
            {
                return(null);
            }
            initialByte = bytes[0];
            KiRef handle = new KiRef();

            switch ((KiTag)initialByte)
            {
            case KiTag.EOM:
            case KiTag.REQ:
            case KiTag.REP:
            case KiTag.ERR:
            case KiTag.NFY:
            case KiTag.Undefined:
            case KiTag.Null:
            case KiTag.True:
            case KiTag.False:
                return(new KiAtom((KiTag)initialByte));

            case KiTag.Buffer:
                if (!socket.ReceiveAll(bytes = new byte[4]))
                {
                    return(null);
                }
                length = (bytes[0] << 24) + (bytes[1] << 16) + (bytes[2] << 8) + bytes[3];
                if (!socket.ReceiveAll(bytes = new byte[length]))
                {
                    return(null);
                }
                return(new KiAtom(bytes));

            case KiTag.Ref:
                if (!socket.ReceiveAll(bytes = new byte[4]))
                {
                    return(null);
                }
                handle.Handle = (uint)((bytes[0] << 24) + (bytes[1] << 16) + (bytes[2] << 8) + bytes[3]);
                return(new KiAtom(handle));

            case KiTag.Integer:
                if (!socket.ReceiveAll(bytes = new byte[4]))
                {
                    return(null);
                }
                return(new KiAtom((bytes[0] << 24) + (bytes[1] << 16) + (bytes[2] << 8) + bytes[3]));

            case KiTag.Number:
                if (!socket.ReceiveAll(bytes = new byte[8]))
                {
                    return(null);
                }
                if (BitConverter.IsLittleEndian)
                {
                    Array.Reverse(bytes);
                }
                return(new KiAtom(BitConverter.ToDouble(bytes, 0)));

            case KiTag.String:
                if (!socket.ReceiveAll(bytes = new byte[4]))
                {
                    return(null);
                }
                length = (bytes[0] << 24) + (bytes[1] << 16) + (bytes[2] << 8) + bytes[3];
                if (!socket.ReceiveAll(bytes = new byte[length]))
                {
                    return(null);
                }
                return(new KiAtom(utf8.GetString(bytes)));

            default:
                return(null);
            }
        }