Returns the byte length of the given tag.

@param {number} tag
@return {number}
333306
function getTagLength(tag) {
  var lenTag = 4;
  
  while(lenTag > 1) {
    var tmpTag = tag >>> ((lenTag - 1) * 8);
    
    if ((tmpTag & 0xFF) != 0x00) {
      break;
    } 
    
    lenTag--;
  }
  
  return lenTag;
}
1309423
function _getUTF8Length(content) {
    var result = encodeURI(content).toString().replace(/\%[0-9a-fA-F]{2}/g, 'a');
    return result.length + (result.length != content ? 3 : 0);
  }
513509
function bytesToSize (bytes) {
  const sizes = ['bytes', 'kb', 'mb', 'gb', 'tb']
  if (bytes === 0) return '0 byte'
  const i = parseInt(Math.floor(Math.log(bytes) / Math.log(BYTES)))
  return (bytes / Math.pow(BYTES, i)).toFixed(DISPLAY_DECIMALS) + sizes[i]
}
373929
public String getTagHtml(Tag tag) {

        StringBuffer result = new StringBuffer(32);
        result.append('<');
        result.append(tag.getText());
        result.append('>');
        return result.toString();
    }
1094222
function() {
        var length = 0.0;
        for (var i=0, len=this.components.length; i<len; i++) {
            length += this.components[i].getLength();
        }
        return length;
    }
1343947
public static String getFormattedTagAndLength(final byte[] data, final int indentLength) {
		StringBuilder buf = new StringBuilder();
		String indent = getSpaces(indentLength);
		TLVInputStream stream = new TLVInputStream(new ByteArrayInputStream(data));

		boolean firstLine = true;
		try {
			while (stream.available() > 0) {
				if (firstLine) {
					firstLine = false;
				} else {
					buf.append("\n");
				}
				buf.append(indent);

				ITag tag = searchTagById(stream.readTag());
				int length = stream.readLength();

				buf.append(prettyPrintHex(tag.getTagBytes()));
				buf.append(" ");
				buf.append(String.format("%02x", length));
				buf.append(" -- ");
				buf.append(tag.getName());
			}
		} catch (IOException e) {
			LOGGER.error(e.getMessage(), e);
		} finally {
			IOUtils.closeQuietly(stream);
		}
		return buf.toString();
	}
407348
public static int sizeOf(int tagNumber, int contentLength) {
        if (tagNumber < 0 || contentLength < 0) {
            throw new IllegalArgumentException("Invalid tagNumber/contentLength: " + tagNumber + ", " + contentLength);
        }

        int len = 0;

        // ID octets
        if (tagNumber <= 30) {
            len++; // single octet
        } else {
            len = len + 1 + (int) Math.ceil((1 + Integer.numberOfTrailingZeros(Integer.highestOneBit(tagNumber))) / 7.0d);
        }

        // Length octets (TODO: indefinite form)
        if (contentLength <= 0x7f) {
            len++; // definite form, single octet
        } else {
            len = len + 1 + (int) Math.ceil((1 + Integer.numberOfTrailingZeros(Integer.highestOneBit(contentLength))) / 8.0d);
        }

        // Content octets
        len += contentLength;

        return len;
    }
1021275
function encodeTags(tags) {
  var bufLength = 0;
  var tagLengths = []
  
  for (var i = 0; i < tags.length; i++) {
    var tagLength = getTagLength(tags[i]);
    tagLengths.push(tagLength);
    bufLength += tagLength;
  }
  
  var buf = new Buffer(bufLength);
  var slicedBuf = buf;
  
  for (var i = 0; i < tags.length; i++) {
    encodeNumber(slicedBuf, tags[i], tagLengths[i]);
    slicedBuf = slicedBuf.slice(tagLengths[i]);
  }
  
  return buf;
}
973014
public final String fullstring(final String tag) {
        String fullstring = getToken(tag).getFullString();
        if (fullstring == null) {
            fullstring = tag;
        }
        return fullstring;
    }
839402
def packet(tag, blob):
    """"""
    assert len(blob) < 2**32

    if len(blob) < 2**8:
        length_type = 0
    elif len(blob) < 2**16:
        length_type = 1
    else:
        length_type = 2

    fmt = ['>B', '>H', '>L'][length_type]
    leading_byte = 0x80 | (tag << 2) | (length_type)
    return struct.pack('>B', leading_byte) + util.prefix_len(fmt, blob)
725891
def get_is_value(tag):
    
    # data is int formatted as string so convert te string first and cast to int
    if tag.VR == 'OB' or tag.VR == 'UN':
        value = int(tag.value.decode("ascii").replace(" ", ""))
        return value
    return int(tag.value)
1192886
function getLengthOfLength(lenValue, indefiniteLength) {
  var lenOfLen;
  
  if (indefiniteLength) {
    lenOfLen = 3;
  } else if (lenValue > 0x00FFFFFF) {
    lenOfLen = 5;
  } else if (lenValue > 0x0000FFFF) {
    lenOfLen = 4;
  } else if (lenValue > 0x000000FF) {
    lenOfLen = 3;
  } else if (lenValue > 0x0000007F) {
    lenOfLen = 2; 
  } else {
    lenOfLen = 1;
  }
  
  return lenOfLen
}
1198637
function stattag (stat) {
  var mtime = stat.mtime.getTime().toString(16)
  var size = stat.size.toString(16)

  return '"' + size + '-' + mtime + '"'
}
875954
function decode(string, tag) {

    tag = tag || '\\u';

    var newString = '';
    var open = false;
    var char, charCode;
    var index = -1;
    var length = string.length;
    while (++index < length) {
        char = string.charAt(index);
        charCode = char.charCodeAt(0);
        if (open) {
            if (char === tag) {
                newString += tag;
            } else {
                var hex = parseInt(string.substr(index, 4), 16);
                if (isNaN(hex)) {
                    newString += char;
                } else {
                    newString += String.fromCharCode(hex);
                    index += 3;
                }
            }
            open = false;
        } else {
            if (char === tag) {
                open = true;
            } else {
                newString += char;
            }
        }
    }

    return newString;

}
635922
def tagged(self, tag, offset=0, count=25):
        ''''''
        return json.loads(self.client('tag', 'get', tag, offset, count))
329345
protected void readTag(int tag)
        throws IOException
    {
        int length = (is.read() << 8) + is.read();
        is.skip(length);
    }
995290
function parse_BLOB(blob) {
	var size = blob.read_shift(4);
	var bytes = blob.slice(blob.l,blob.l+size);
	blob.l += size;
	if((size & 3) > 0) blob.l += (4 - (size & 3)) & 3;
	return bytes;
}