/*
Provide an estimate of encoded length of the payload
11645
int guessPayloadLength() {
    int length = 0;
    // Total guess at average size of map entry
    try {
      Map<String,Object> payload = getBodyMap();
      length = payload.size()*60;
    }
    catch (UnsupportedEncodingException e) {
      // No FFDC code needed
      // hmm... how do we figure out a reasonable length
    }
    return length;
  }
734372
private int staticEncodingLength(GenericPropertyInfo info) {
        TypeDesc type = info.getStorageType();
        TypeDesc primType = type.toPrimitiveType();

        if (primType == null) {
            if (info.isLob()) {
                // Lob locator is stored as a long.
                return 8;
            }
        } else {
            if (info.isNullable()) {
                // Type is a primitive wrapper.
                switch (primType.getTypeCode()) {
                case TypeDesc.BYTE_CODE:
                    return ~1;
                case TypeDesc.BOOLEAN_CODE:
                    return 1;
                case TypeDesc.SHORT_CODE:
                case TypeDesc.CHAR_CODE:
                    return ~1;
                case TypeDesc.INT_CODE:
                    return ~1;
                case TypeDesc.FLOAT_CODE:
                    return 4;
                case TypeDesc.LONG_CODE:
                    return ~1;
                case TypeDesc.DOUBLE_CODE:
                    return 8;
                }
            } else {
                // Type is primitive or a required primitive wrapper.
                switch (type.getTypeCode()) {
                case TypeDesc.BYTE_CODE:
                case TypeDesc.BOOLEAN_CODE:
                    return 1;
                case TypeDesc.SHORT_CODE:
                case TypeDesc.CHAR_CODE:
                    return 2;
                case TypeDesc.INT_CODE:
                case TypeDesc.FLOAT_CODE:
                    return 4;
                case TypeDesc.LONG_CODE:
                case TypeDesc.DOUBLE_CODE:
                    return 8;
                }
            }
        }

        return ~0;
    }
803323
function getStringBufferLength(hexStr) {
  const _tmpBuf = Buffer.from(hexStr, 'hex').length;
  return Buffer.from([_tmpBuf]).toString('hex');
}
753594
public int encodedTypeLength() {
    int ans = 3; // 3 includes kind code for VARIANT plus the length
    for (int i = 0; i < cases.length; i++)
      ans += cases[i].encodedTypeLength();
    return ans;
  }
344689
def Size(self):
        
        return s.uint32 + 12 + s.uint32 + s.uint32 + len(self.Payload)
630317
private long deserializeDataLength(DataInputStream dis) throws IOException {
        int dataLength = dis.readInt();
        if(dataLength == -1) {
            return dis.readLong();
        }
        return dataLength;
    }
1303808
int guessPayloadLength() {
    int length = 0;
    // It is likely that the String length will be the same as the length in bytes
    // when it has been encoded (to UTF8) plus a small overhead.
    try {
      if (jmo.getPayloadPart().getChoiceField(JsPayloadAccess.PAYLOAD) != JsPayloadAccess.IS_PAYLOAD_EMPTY) {
        String payload = (String)getPayload().getField(JmsTextBodyAccess.BODY_DATA_VALUE);
        if (payload != null) length = payload.length() + 24;
      }
    }
    catch (MFPUnsupportedEncodingRuntimeException e) {
      FFDCFilter.processException(e, "com.ibm.ws.sib.mfp.impl.JsJmsTextMessageImpl.getText", "129");
      // hmm... how do we figure out a reasonable length
    }
    return length;
  }
756259
private int getLengthFromByteArray(byte[] bin){
        ByteBuffer bb = ByteBuffer.wrap(bin);
        bb.order(ByteOrder.BIG_ENDIAN);
        return bb.getShort();
    }
440564
int guessPayloadLength() {
    int length = 0;
    byte[] payload = (byte[])getPayload().getField(JmsBytesBodyAccess.BODY_DATA_VALUE);
    if (payload != null) {
      length = payload.length + 24;
    }
    return length;
  }
194654
function getUTF8Length(s) {
  let len = 0;
  let i;
  let code;
  for (i = 0; i < s.length; i++) {
    code = s.charCodeAt(i);
    if (code <= 0x7f) {
      len += 1;
    } else if (code <= 0x7ff) {
      len += 2;
    } else if (code >= 0xd800 && code <= 0xdfff) {
      // Surrogate pair: These take 4 bytes in UTF-8 and 2 chars in UCS-2
      // (Assume next char is the other [valid] half and just skip it)
      len += 4; i++;
    } else if (code < 0xffff) {
      len += 3;
    } else {
      len += 4;
    }
  }
  return len;
}
439429
private static int readTokenLength(ByteArrayInputStream bais) {
        int tokenLength = 0;
        byte lengthMarker = (byte) bais.read();

        if (lengthMarker == (byte) 0x081) {
            int firstByte = bais.read();
            tokenLength = firstByte;
        } else if (lengthMarker == (byte) 0x082) {
            int secondByte = bais.read();
            int firstByte = bais.read();
            tokenLength = (secondByte << 8) + firstByte;
        } else if (lengthMarker == (byte) 0x083) {
            int thirdByte = bais.read();
            int secondByte = bais.read();
            int firstByte = bais.read();
            tokenLength = (thirdByte << 16) + (secondByte << 8) + firstByte;
        } else if (lengthMarker == (byte) 0x084) {
            int fourthByte = bais.read();
            int thirdByte = bais.read();
            int secondByte = bais.read();
            int firstByte = bais.read();
            tokenLength = (fourthByte << 24) + (thirdByte << 16) + (secondByte << 8) + firstByte;
        } else {
            // If not one of the markers above, this is the actual length.
            tokenLength = lengthMarker;
        }

        return tokenLength;
    }
883608
function lengthInUtf8Bytes(str) {
		const m = encodeURIComponent(str).match(/%[89ABab]/g);
		return str.length + (m ? m.length : 0);
	}
1145932
def _get_content_length(self,msg):
        ''''''
        m = re.search(r'[Cc]ontent-length:\s?(?P<len>\d+)',msg,re.S)
        return (m and int(m.group('len'))) or 0
784250
function multipartDecode(response) {
    const message = new Uint8Array(response);

    /* Set a maximum length to search for the header boundaries, otherwise
       findToken can run for a long time
    */
    const maxSearchLength = 1000;


    // First look for the multipart mime header
    let separator = stringToUint8Array('\r\n\r\n');
    let headerIndex = findToken(message, separator, 0, maxSearchLength);
    if (headerIndex === -1) {
      throw new Error('Response message has no multipart mime header');
    }

    const header = uint8ArrayToString(message, 0, headerIndex);
    const boundaryString = identifyBoundary(header);
    if (!boundaryString) {
      throw new Error('Header of response message does not specify boundary');
    }

    const boundary = stringToUint8Array(boundaryString);
    const boundaryLength = boundary.length;
    const components = [];

    let offset = headerIndex + separator.length;

    // Loop until we cannot find any more boundaries
    let boundaryIndex;

    while (boundaryIndex !== -1) {
      // Search for the next boundary in the message, starting
      // from the current offset position
      boundaryIndex = findToken(message, boundary, offset);

      // If no further boundaries are found, stop here.
      if (boundaryIndex === -1) {
        break;
      }

      // Extract data from response message, excluding "\r\n"
      const spacingLength = 2;
      const length = boundaryIndex - offset - spacingLength;
      const data = response.slice(offset, offset + length);

      // Add the data to the array of results
      components.push(data);

      // Move the offset to the end of the current section,
      // plus the identified boundary
      offset += length + spacingLength + boundaryLength;
    }

    return components;
}
396046
def get_payload(self, data):
        """"""
        start = 2
        length = ord(data[1:2])
        if length == 126:
            # Payload information are an extra 2 bytes.
            start = 4
            length, = unpack(">H", data[2:4])
        elif length == 127:
            # Payload information are an extra 6 bytes.
            start = 8
            length, = unpack(">I", data[2:6])
        end = start + length
        payload = json.loads(data[start:end].decode())
        extra_data = data[end:]
        return payload, extra_data
1262474
@Override
    int guessPayloadLength() {
        int length = 0;
        byte[] payload = getDataFromPayload();
        if (payload != null) {
            length = payload.length + 24;
        }
        return length;
    }
347283
def determineLength(length):
        
        integer = ord(length)

        if integer < 128:
            return 0
        elif integer < 192:
            return 1
        elif integer < 224:
            return 2
        elif integer < 240:
            return 3
        else:
            raise ConnectionError('Unknown controll byte {}'.format(length))