def getData(self,path):
     requestBytes = [0, 0, 0, -1, 0, 0, 0, 1, 0, 0, 0, 4];
     pathLen = len(path);
     pathLenList = list(struct.unpack("4b",struct.pack("!i",pathLen)));
     for pathLenByte in pathLenList:
         requestBytes.append(pathLenByte);#add path lenth
     pathByteList =  list(struct.unpack(str(pathLen)+"b",struct.pack("!" + str(pathLen) + "s",path)));
     for pathByte in pathByteList:
         requestBytes.append(pathByte);#add path
     requestBytes.append(0);#add ifwatch
     bodySize = len(requestBytes) - 4;
     bodySizeList = list(struct.unpack("4b",struct.pack("!i",bodySize)));
     for i in range(4):
         requestBytes[i] = bodySizeList[i];
     #print requestBytes;
     trueBytes = bytearray(requestBytes);
     self.zkSocket.sendall(trueBytes);
     responseBytes = self.zkSocket.recv(1024);
     byteBuffer = ByteBuffer(responseBytes);
     byteBuffer.getInt();#msglen
     byteBuffer.getInt();#xid
     byteBuffer.getLong();#zxid
     byteBuffer.getInt();#err
     resultValue = byteBuffer.getString();
     return resultValue;
Exemplo n.º 2
0
 def getData(self, path):
     requestBytes = [0, 0, 0, -1, 0, 0, 0, 1, 0, 0, 0, 4]
     pathLen = len(path)
     pathLenList = list(struct.unpack("4b", struct.pack("!i", pathLen)))
     for pathLenByte in pathLenList:
         requestBytes.append(pathLenByte)
         #add path lenth
     pathByteList = list(
         struct.unpack(
             str(pathLen) + "b", struct.pack("!" + str(pathLen) + "s",
                                             path)))
     for pathByte in pathByteList:
         requestBytes.append(pathByte)
         #add path
     requestBytes.append(0)
     #add ifwatch
     bodySize = len(requestBytes) - 4
     bodySizeList = list(struct.unpack("4b", struct.pack("!i", bodySize)))
     for i in range(4):
         requestBytes[i] = bodySizeList[i]
     #print requestBytes;
     trueBytes = bytearray(requestBytes)
     self.zkSocket.sendall(trueBytes)
     responseBytes = self.zkSocket.recv(1024)
     byteBuffer = ByteBuffer(responseBytes)
     byteBuffer.getInt()
     #msglen
     byteBuffer.getInt()
     #xid
     byteBuffer.getLong()
     #zxid
     byteBuffer.getInt()
     #err
     resultValue = byteBuffer.getString()
     return resultValue