📄 request.java
字号:
protected final void finalizePreviousChainedDss(boolean dssHasSameCorrelator) { finalizeDssLength(); bytes_[dssLengthLocation_ + 3] |= 0x40; if (dssHasSameCorrelator) // for blobs { bytes_[dssLengthLocation_ + 3] |= 0x10; } } // method to determine if any data is in the request. // this indicates there is a dss object already in the buffer. protected final boolean doesRequestContainData() { return offset_ != 0; } // signal the completion of a Dss Layer A object. The length of // dss object will be calculated based on the difference between the // start of the dss, saved on the beginDss call, and the current // offset into the buffer which marks the end of the data. In the event // the length requires the use of continuation Dss headers, one for each 32k // chunk of data, the data will be shifted and the continuation headers // will be inserted with the correct values as needed. // Note: In the future, we may try to optimize this approach // in an attempt to avoid these shifts. protected final void finalizeDssLength() { // calculate the total size of the dss and the number of bytes which would // require continuation dss headers. The total length already includes the // the 6 byte dss header located at the beginning of the dss. It does not // include the length of any continuation headers. int totalSize = offset_ - dssLengthLocation_; int bytesRequiringContDssHeader = totalSize - 32767; // determine if continuation headers are needed if (bytesRequiringContDssHeader > 0) { // the continuation headers are needed, so calculate how many. // after the first 32767 worth of data, a continuation header is // needed for every 32765 bytes (32765 bytes of data + 2 bytes of // continuation header = 32767 Dss Max Size). int contDssHeaderCount = bytesRequiringContDssHeader / 32765; if (bytesRequiringContDssHeader % 32765 != 0) { contDssHeaderCount++; } // right now the code will shift to the right. In the future we may want // to try something fancier to help reduce the copying (maybe keep // space in the beginning of the buffer??). // the offset points to the next available offset in the buffer to place // a piece of data, so the last dataByte is at offset -1. // various bytes will need to be shifted by different amounts // depending on how many dss headers to insert so the amount to shift // will be calculated and adjusted as needed. ensure there is enough room // for all the conutinuation headers and adjust the offset to point to the // new end of the data. int dataByte = offset_ - 1; int shiftOffset = contDssHeaderCount * 2; ensureLength(offset_ + shiftOffset); offset_ += shiftOffset; // mark passOne to help with calculating the length of the final (first or // rightmost) continuation header. boolean passOne = true; do { // calculate chunk of data to shift int dataToShift = bytesRequiringContDssHeader % 32765; if (dataToShift == 0) { dataToShift = 32765; } // perform the shift for (int i = 0; i < dataToShift; i++) { bytes_[dataByte + shiftOffset] = bytes_[dataByte]; dataByte--; } // calculate the value the value of the 2 byte continuation dss header which // includes the length of itself. On the first pass, if the length is 32767 // we do not want to set the continuation dss header flag. int twoByteContDssHeader = dataToShift + 2; if (passOne) { passOne = false; } else { if (twoByteContDssHeader == 32767) { twoByteContDssHeader = 0xFFFF; } } // insert the header's length bytes bytes_[dataByte + shiftOffset - 1] = (byte) ((twoByteContDssHeader >>> 8) & 0xff); bytes_[dataByte + shiftOffset] = (byte) (twoByteContDssHeader & 0xff); // adjust the bytesRequiringContDssHeader and the amount to shift for // data in upstream headers. bytesRequiringContDssHeader -= dataToShift; shiftOffset -= 2; // shift and insert another header for more data. } while (bytesRequiringContDssHeader > 0); // set the continuation dss header flag on for the first header totalSize = 0xFFFF; } // insert the length bytes in the 6 byte dss header. bytes_[dssLengthLocation_] = (byte) ((totalSize >>> 8) & 0xff); bytes_[dssLengthLocation_ + 1] = (byte) (totalSize & 0xff); } // mark the location of a two byte ddm length field in the buffer, // skip the length bytes for later update, and insert a ddm codepoint // into the buffer. The value of the codepoint is not checked. // this length will be automatically updated when construction of // the ddm object is complete (see updateLengthBytes method). // Note: this mechanism handles extended length ddms. protected final void markLengthBytes(int codePoint) { ensureLength(offset_ + 4); // save the location of length bytes in the mark stack. mark(); // skip the length bytes and insert the codepoint offset_ += 2; bytes_[offset_++] = (byte) ((codePoint >>> 8) & 0xff); bytes_[offset_++] = (byte) (codePoint & 0xff); } // mark an offest into the buffer by placing the current offset value on // a stack. private final void mark() { markStack_[top_++] = offset_; } // remove and return the top offset value from mark stack. private final int popMark() { return markStack_[--top_]; } protected final void markForCachingPKGNAMCSN() { mark(); } protected final int popMarkForCachingPKGNAMCSN() { return popMark(); } // Called to update the last ddm length bytes marked (lengths are updated // in the reverse order that they are marked). It is up to the caller // to make sure length bytes were marked before calling this method. // If the length requires ddm extended length bytes, the data will be // shifted as needed and the extended length bytes will be automatically // inserted. protected final void updateLengthBytes() throws SqlException { // remove the top length location offset from the mark stack\ // calculate the length based on the marked location and end of data. int lengthLocation = popMark(); int length = offset_ - lengthLocation; // determine if any extended length bytes are needed. the value returned // from calculateExtendedLengthByteCount is the number of extended length // bytes required. 0 indicates no exteneded length. int extendedLengthByteCount = calculateExtendedLengthByteCount(length); if (extendedLengthByteCount != 0) { // ensure there is enough room in the buffer for the extended length bytes. ensureLength(offset_ + extendedLengthByteCount); // calculate the length to be placed in the extended length bytes. // this length does not include the 4 byte llcp. int extendedLength = length - 4; // shift the data to the right by the number of extended length bytes needed. int extendedLengthLocation = lengthLocation + 4; System.arraycopy(bytes_, extendedLengthLocation, bytes_, extendedLengthLocation + extendedLengthByteCount, extendedLength); // write the extended length int shiftSize = (extendedLengthByteCount - 1) * 8; for (int i = 0; i < extendedLengthByteCount; i++) { bytes_[extendedLengthLocation++] = (byte) ((extendedLength >>> shiftSize) & 0xff); shiftSize -= 8; } // adjust the offset to account for the shift and insert offset_ += extendedLengthByteCount; // the two byte length field before the codepoint contains the length // of itself, the length of the codepoint, and the number of bytes used // to hold the extended length. the 2 byte length field also has the first // bit on to indicate extended length bytes were used. length = extendedLengthByteCount + 4; length |= 0x8000; } // write the 2 byte length field (2 bytes before codepoint). bytes_[lengthLocation] = (byte) ((length >>> 8) & 0xff); bytes_[lengthLocation + 1] = (byte) (length & 0xff); } // helper method to calculate the minimum number of extended length bytes needed // for a ddm. a return value of 0 indicates no extended length needed. private final int calculateExtendedLengthByteCount(long ddmSize) //throws SqlException { // according to Jim and some tests perfomred on Lob data, // the extended length bytes are signed. Assume that // if this is the case for Lobs, it is the case for // all extended length scenarios. if (ddmSize <= 0x7FFF) { return 0; } else if (ddmSize <= 0x7FFFFFFFL) { return 4; } else if (ddmSize <= 0x7FFFFFFFFFFFL) { return 6; } else { return 8; } } // insert the padByte into the buffer by length number of times. final void padBytes(byte padByte, int length) { ensureLength(offset_ + length); for (int i = 0; i < length; i++) { bytes_[offset_++] = padByte; } } // insert an unsigned single byte value into the buffer. final void write1Byte(int value) { ensureLength(offset_ + 1); bytes_[offset_++] = (byte) (value & 0xff); } // insert 3 unsigned bytes into the buffer. this was // moved up from NetStatementRequest for performance final void buildTripletHeader(int tripletLength, int tripletType, int tripletId) { ensureLength(offset_ + 3); bytes_[offset_++] = (byte) (tripletLength & 0xff); bytes_[offset_++] = (byte) (tripletType & 0xff); bytes_[offset_++] = (byte) (tripletId & 0xff); } final void writeLidAndLengths(int[][] lidAndLengthOverrides, int count, int offset) { ensureLength(offset_ + (count * 3)); for (int i = 0; i < count; i++, offset++) { bytes_[offset_++] = (byte) (lidAndLengthOverrides[offset][0] & 0xff); bytes_[offset_++] = (byte) ((lidAndLengthOverrides[offset][1] >>> 8) & 0xff); bytes_[offset_++] = (byte) (lidAndLengthOverrides[offset][1] & 0xff); } } // if mdd overrides are not required, lids and lengths are copied straight into the // buffer. // otherwise, lookup the protocolType in the map. if an entry exists, substitute the // protocolType with the corresponding override lid. final void writeLidAndLengths(int[][] lidAndLengthOverrides, int count, int offset, boolean mddRequired, java.util.Hashtable map) { if (!mddRequired) { writeLidAndLengths(lidAndLengthOverrides, count, offset); } // if mdd overrides are required, lookup the protocolType in the map, and substitute // the protocolType with the override lid. else { ensureLength(offset_ + (count * 3)); int protocolType, overrideLid; Object entry; for (int i = 0; i < count; i++, offset++) { protocolType = lidAndLengthOverrides[offset][0]; // lookup the protocolType in the protocolType->overrideLid map // if an entry exists, replace the protocolType with the overrideLid entry = map.get(new Integer(protocolType)); overrideLid = (entry == null) ? protocolType : ((Integer) entry).intValue();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -