Exemple #1
0
        public static LcrsNode DeserializeNode(Stream stream)
        {
            var blockArr = new byte[SizeOfNode()];

            stream.Read(blockArr, 0, blockArr.Length);

            if (!BitConverter.IsLittleEndian)
            {
                Array.Reverse(blockArr, 0, sizeof(char));
                Array.Reverse(blockArr, sizeof(char), sizeof(short));
                Array.Reverse(blockArr, sizeof(char) + sizeof(short), sizeof(int));
            }

            var val         = BitConverter.ToChar(blockArr, 0);
            var haveSibling = BitConverter.ToBoolean(blockArr, sizeof(char));
            var haveChild   = BitConverter.ToBoolean(blockArr, sizeof(char) + sizeof(byte));
            var eow         = BitConverter.ToBoolean(blockArr, sizeof(char) + 2 * sizeof(byte));
            var depth       = BitConverter.ToInt16(blockArr, sizeof(char) + 3 * sizeof(byte));
            var weight      = BitConverter.ToInt32(blockArr, sizeof(char) + 3 * sizeof(byte) + sizeof(short));
            var block       = BlockSerializer.DeserializeBlock(stream);

            return(new LcrsNode(
                       val,
                       haveSibling,
                       haveChild,
                       eow,
                       depth,
                       weight,
                       block));
        }
Exemple #2
0
        public void Start()
        {
            byte[] request;

            try
            {
                while (true)
                {
                    Log.Info("document server idle");

                    Socket handler = _listener.Accept();

                    request = new byte[sizeof(long) + sizeof(int)];

                    int received = handler.Receive(request);

                    Log.InfoFormat("received a {0} byte request", received);

                    var address = BlockSerializer.DeserializeBlock(request, 0);

                    byte[] response = FindInCache(address);

                    handler.Send(response);
                    handler.Shutdown(SocketShutdown.Both);
                    handler.Dispose();

                    Log.InfoFormat("responded with a {0} byte document", response.Length);
                }
            }
            catch (Exception e)
            {
                Log.Info(e.ToString());
            }
        }
Exemple #3
0
        protected override BlockInfo Deserialize(long offset, int size, Stream stream)
        {
            stream.Seek(offset, SeekOrigin.Begin);

            return(BlockSerializer.DeserializeBlock(stream));
        }