Ejemplo n.º 1
0
 internal static int ReadDeleteResponse(Socket socket)
 {
     using (KVMemoryStream stream = ReadResponse(socket))
     {
         int len     = stream.ReadInt();
         int type    = stream.ReadInt();
         int retCode = stream.ReadInt();
         return(retCode);
     }
 }
Ejemplo n.º 2
0
 internal static int ReadGetResponse(Socket socket, out byte[] value)
 {
     using (KVMemoryStream stream = ReadResponse(socket))
     {
         int    len     = stream.ReadInt();
         int    type    = stream.ReadInt();
         int    retCode = stream.ReadInt();
         int    retry   = stream.ReadByte();
         int    ttl     = stream.ReadInt();
         byte[] key     = stream.ReadBytes();
         value = stream.ReadBytes();
         return(retCode);
     }
 }
Ejemplo n.º 3
0
 internal static DataServerStruct decodeDataServer(KVMemoryStream stream)
 {
     Address addr = decodeAddress(stream);
     int weight = stream.ReadInt();
     SystemInfo info = decodeSystemInfo(stream);
     int size = stream.ReadInt();
     DataServerStruct dataServer = new DataServerStruct(addr, weight, info);
     for (int i = 0; i < size; i++)
     {
         Region region = decodeRegion(stream);
         dataServer.addRegion(region);
     }
     return dataServer;
 }
Ejemplo n.º 4
0
        internal static DataServerStruct decodeDataServer(KVMemoryStream stream)
        {
            Address          addr       = decodeAddress(stream);
            int              weight     = stream.ReadInt();
            SystemInfo       info       = decodeSystemInfo(stream);
            int              size       = stream.ReadInt();
            DataServerStruct dataServer = new DataServerStruct(addr, weight, info);

            for (int i = 0; i < size; i++)
            {
                Region region = decodeRegion(stream);
                dataServer.addRegion(region);
            }
            return(dataServer);
        }
Ejemplo n.º 5
0
        public static Address decodeAddress(KVMemoryStream stream)
        {
            String ip   = stream.ReadString();
            int    port = stream.ReadInt();

            return(new Address(ip, port));
        }
Ejemplo n.º 6
0
        private static KVMemoryStream ReadResponse(Socket socket)
        {
            KVMemoryStream stream        = new KVMemoryStream(64);
            int            readLength    = 0;
            int            messageLength = 0;

            while ((readLength = socket.Receive(readBuffer)) > 0)
            {
                stream.Write(readBuffer, 0, readLength);
                if (messageLength == 0 || readLength >= 4)
                {
                    //calculate message length
                    long oldPos = stream.Position;
                    stream.Position = 0;
                    messageLength   = stream.ReadInt();
                    stream.Position = oldPos;
                }
                if (messageLength <= readLength - 4)
                {
                    stream.Position = 0;
                    return(stream);
                }
            }
            throw new InvalidDataException();
        }
Ejemplo n.º 7
0
 public static Region decodeRegion(KVMemoryStream stream)
 {
     int regionId = stream.ReadInt();
     byte[] start = stream.ReadBytes();
     byte[] end = stream.ReadBytes();
     RegionStat stat = decodeRegionStat(stream);
     return new Region(regionId, start, end, stat);
 }
Ejemplo n.º 8
0
 internal static int ReadRegionTableResponse(Socket socket, out RegionTable table)
 {
     using (KVMemoryStream stream = ReadResponse(socket))
     {
         int len     = stream.ReadInt();
         int type    = stream.ReadInt();
         int retCode = stream.ReadInt();
         if (retCode == ProtocolCode.Success)
         {
             table = DecoderUtil.decodeRegionTable(stream);
         }
         else
         {
             table = null;
         }
         return(retCode);
     }
 }
Ejemplo n.º 9
0
 public static RegionStat decodeRegionStat(KVMemoryStream stream)
 {
     RegionStat stat = new RegionStat();
     stat.keyNum = stream.ReadInt();
     stat.size = stream.ReadLong();
     stat.readCount = stream.ReadLong();
     stat.writeCount = stream.ReadLong();
     return stat;
 }
Ejemplo n.º 10
0
        public static RegionStat decodeRegionStat(KVMemoryStream stream)
        {
            RegionStat stat = new RegionStat();

            stat.keyNum     = stream.ReadInt();
            stat.size       = stream.ReadLong();
            stat.readCount  = stream.ReadLong();
            stat.writeCount = stream.ReadLong();
            return(stat);
        }
Ejemplo n.º 11
0
        public static Region decodeRegion(KVMemoryStream stream)
        {
            int regionId = stream.ReadInt();

            byte[]     start = stream.ReadBytes();
            byte[]     end   = stream.ReadBytes();
            RegionStat stat  = decodeRegionStat(stream);

            return(new Region(regionId, start, end, stat));
        }
Ejemplo n.º 12
0
 internal static int ReadStatResponse(Socket socket, out DataServerStruct[] dataServers)
 {
     using (KVMemoryStream stream = ReadResponse(socket))
     {
         int len     = stream.ReadInt();
         int type    = stream.ReadInt();
         int retCode = stream.ReadInt();
         dataServers = null;
         int size = stream.ReadInt();
         if (size > 0)
         {
             dataServers = new DataServerStruct[size];
             for (int i = 0; i < size; i++)
             {
                 dataServers[i] = DecoderUtil.decodeDataServer(stream);
             }
         }
         return(retCode);
     }
 }
Ejemplo n.º 13
0
 public static RegionTable decodeRegionTable(KVMemoryStream stream)
 {
     RegionTable table =new RegionTable();
     int size = stream.ReadInt();
     for (int i = 0; i < size; i++)
     {
         Region region = decodeRegion(stream);
         Address addr = decodeAddress(stream);
         table.addRegion(region, addr);
     }
     return table;
 }
Ejemplo n.º 14
0
        public static RegionTable decodeRegionTable(KVMemoryStream stream)
        {
            RegionTable table = new RegionTable();
            int         size  = stream.ReadInt();

            for (int i = 0; i < size; i++)
            {
                Region  region = decodeRegion(stream);
                Address addr   = decodeAddress(stream);
                table.addRegion(region, addr);
            }
            return(table);
        }
Ejemplo n.º 15
0
 private static KVMemoryStream ReadResponse(Socket socket)
 {
     KVMemoryStream stream = new KVMemoryStream(64);
     int readLength = 0;
     int messageLength = 0;
     while ((readLength = socket.Receive(readBuffer)) > 0)
     {
         stream.Write(readBuffer, 0, readLength);
         if (messageLength == 0 || readLength >= 4)
         {
             //calculate message length
             long oldPos = stream.Position;
             stream.Position = 0;
             messageLength = stream.ReadInt();
             stream.Position = oldPos;
         }
         if (messageLength <= readLength - 4)
         {
             stream.Position = 0;
             return stream;
         }
     }
     throw new InvalidDataException();
 }
Ejemplo n.º 16
0
 public static Address decodeAddress(KVMemoryStream stream)
 {
     String ip = stream.ReadString();
     int port = stream.ReadInt();
     return new Address(ip, port);
 }