public BinaryPacket getBinaryCommandHeader() throws Exception {
		if(baos.size()<24) return null;

		byte input[] = baos.toByteArray();

		byte headerData[] = new byte[24];
		System.arraycopy(input, 0, headerData, 0, 24);
		RequestHeader header = RequestHeader.parse(headerData);
		
		//saftey check
		if(header.getKeyLength()>getMaxSizeAllowedForKey()) {
			throw new IllegalArgumentException(
					"key passed to big to store "+key);
		}
		
		long bodySize = header.getTotalBodyLength() - 
			(header.getExtrasLength() + header.getKeyLength());
		if(bodySize>0) {
			if(Data.getMaxSizeAllowedForValue()>0) {
				if(bodySize > Data.getMaxSizeAllowedForValue()) {
					throw new IllegalArgumentException(
						"value passed is too big to store "+bodySize);
				}
			}
		}
		//saftey check
		
		int lenToRead = header.getTotalBodyLength();
		if(baos.size()<(24+lenToRead)) {
			//todo may be it not good idea to descard parsed header
			return null;
		}

		byte bodyData[] = new byte[lenToRead];
		System.arraycopy(input, 24, bodyData, 0, lenToRead);

		BinaryPacket packet = BinaryPacket.parseRequest(header, bodyData);
			
		baos.reset();
		int index = lenToRead+24;
		baos.write(input, index, input.length-index);
		
		return packet;
	}