Decodes a transit value to a corresponding object

 @param node a transit value to be decoded
 @param cache
 @param as_map_key
 @return decoded object
326818
def decode(node, cache=RollingCache.new, as_map_key=false)
      case node
      when String
        if cache.has_key?(node)
          cache.read(node)
        else
          parsed = if !node.start_with?(ESC)
                     node
                   elsif node.start_with?(TAG)
                     Tag.new(node[2..-1])
                   elsif handler = @handlers[node[1]]
                     handler.from_rep(node[2..-1])
                   elsif node.start_with?(ESC_ESC, ESC_SUB, ESC_RES)
                     node[1..-1]
                   else
                     @default_handler.from_rep(node[1], node[2..-1])
                   end
          if cache.cacheable?(node, as_map_key)
            cache.write(parsed)
          end
          parsed
        end
      when Array
        return node if node.empty?
        e0 = decode(node.shift, cache, false)
        if e0 == MAP_AS_ARRAY
          decode(Hash[*node], cache)
        elsif Tag === e0
          v = decode(node.shift, cache)
          if handler = @handlers[e0.value]
            handler.from_rep(v)
          else
            @default_handler.from_rep(e0.value,v)
          end
        else
          [e0] + node.map {|e| decode(e, cache, as_map_key)}
        end
      when Hash
        if node.size == 1
          k = decode(node.keys.first,   cache, true)
          v = decode(node.values.first, cache, false)
          if Tag === k
            if handler = @handlers[k.value]
              handler.from_rep(v)
            else
              @default_handler.from_rep(k.value,v)
            end
          else
            {k => v}
          end
        else
          node.keys.each do |k|
            node.store(decode(k, cache, true), decode(node.delete(k), cache))
          end
          node
        end
      else
        node
      end
    end
1307436
static Key getKey(boolean isLeft, int col, H2ONode node) {
    return Key.make("__radix_order__MSBNodeCounts_col" + col + "_node" + node.index() + (isLeft ? "_LEFT" : "_RIGHT"));
    // Each node's contents is different so the node number needs to be in the key
    // TODO: need the biggestBit in here too, that the MSB is offset from
  }
100194
private static SFPair<OcspResponseCacheKey, SFPair<Long, String>>
  decodeCacheFromJSON(Map.Entry<String, JsonNode> elem) throws IOException
  {
    long currentTimeSecond = new Date().getTime() / 1000;
    byte[] certIdDer = Base64.decodeBase64(elem.getKey());
    DLSequence rawCertId = (DLSequence) ASN1ObjectIdentifier.fromByteArray(certIdDer);
    ASN1Encodable[] rawCertIdArray = rawCertId.toArray();
    byte[] issuerNameHashDer = ((DEROctetString) rawCertIdArray[1]).getEncoded();
    byte[] issuerKeyHashDer = ((DEROctetString) rawCertIdArray[2]).getEncoded();
    BigInteger serialNumber = ((ASN1Integer) rawCertIdArray[3]).getValue();

    OcspResponseCacheKey k = new OcspResponseCacheKey(
        issuerNameHashDer, issuerKeyHashDer, serialNumber);

    JsonNode ocspRespBase64 = elem.getValue();
    if (!ocspRespBase64.isArray() || ocspRespBase64.size() != 2)
    {
      LOGGER.debug("Invalid cache file format.");
      return null;
    }
    long producedAt = ocspRespBase64.get(0).asLong();
    String ocspResp = ocspRespBase64.get(1).asText();

    if (currentTimeSecond - CACHE_EXPIRATION_IN_SECONDS <= producedAt)
    {
      // add cache
      return SFPair.of(k, SFPair.of(producedAt, ocspResp));
    }
    else
    {
      // delete cache
      return SFPair.of(k, SFPair.of(producedAt, (String) null));
    }
  }
1009154
function mapCacheSet$1(key, value) {
  var data = getMapData$4(this, key),
      size = data.size;

  data.set(key, value);
  this.size += data.size == size ? 0 : 1;
  return this;
}
652511
function _mapInAttributes(&$root, $path, $asn1)
    {
        $attributes = &$this->_subArray($root, $path);

        if (is_array($attributes)) {
            for ($i = 0; $i < count($attributes); $i++) {
                $id = $attributes[$i]['type'];
                /* $value contains the DER encoding of an ASN.1 value
                   corresponding to the attribute type identified by type */
                $map = $this->_getMapping($id);
                if (is_array($attributes[$i]['value'])) {
                    $values = &$attributes[$i]['value'];
                    for ($j = 0; $j < count($values); $j++) {
                        $value = $asn1->encodeDER($values[$j], $this->AttributeValue);
                        $decoded = $asn1->decodeBER($value);
                        if (!is_bool($map)) {
                            $mapped = $asn1->asn1map($decoded[0], $map);
                            if ($mapped !== false) {
                                $values[$j] = $mapped;
                            }
                            if ($id == 'pkcs-9-at-extensionRequest' && $this->_isSubArrayValid($values, $j)) {
                                $this->_mapInExtensions($values, $j, $asn1);
                            }
                        } elseif ($map) {
                            $values[$j] = base64_encode($value);
                        }
                    }
                }
            }
        }
    }
263199
private static Map<String, Node> getFields(Node node) {
        Map<String, Node> result = new HashMap<>();
        Iterator<KeyValue> fields = node.fields();
        while (fields.hasNext()) {
            KeyValue field = fields.next();
            result.put(field.getKey(), field.getValue());
        }
        return Collections.unmodifiableMap(result);
    }
1074612
private Map<String, String> asMap(NodeList kvList) {
    	Map<String, String> rt = new HashMap<String, String>();
    	
    	for (int i = 0; i < kvList.getLength(); ++i) {
    		Node item = kvList.item(i);
    		NodeList itemChildren = item.getChildNodes();
    		
    		if (item.getNodeType() != Node.ELEMENT_NODE) {
    			continue;
    		}
    		
    		String key = null;
    		String value = null;
    		
    		for (int j = 0; j < itemChildren.getLength(); ++j) {
    			Node child = itemChildren.item(j);
    			
    			if (child.getNodeType() != Node.ELEMENT_NODE) {
        			continue;
        		}
    			
    			if ("key".equalsIgnoreCase(child.getNodeName())) {
    				key = child.getTextContent();
    			} else if ("value".equalsIgnoreCase(child.getNodeName())) {
    				value = child.getTextContent();
    			}
    		}
    		
    		if (key != null && value != null) {
    			rt.put(key, value);
    		} else {
    			LOGGER.error("Invalid K/V pair: key: " + key + ", value: " + value);
    		}
    	}
    	
    	return rt;
    }
189995
private static String encodeCacheKey(OcspResponseCacheKey ocsp_cache_key)
  {
    try
    {
      DigestCalculator digest = new SHA1DigestCalculator();
      AlgorithmIdentifier algo = digest.getAlgorithmIdentifier();
      ASN1OctetString nameHash = ASN1OctetString.getInstance(ocsp_cache_key.nameHash);
      ASN1OctetString keyHash = ASN1OctetString.getInstance(ocsp_cache_key.keyHash);
      ASN1Integer snumber = new ASN1Integer(ocsp_cache_key.serialNumber);
      CertID cid = new CertID(algo, nameHash, keyHash, snumber);
      return Base64.encodeBase64String(cid.toASN1Primitive().getEncoded());
    }
    catch (Exception ex)
    {
      LOGGER.debug("Failed to encode cache key to base64 encoded cert id");
    }
    return null;
  }
471684
@Override
	public String getCacheKey(String name, Tree params, String... keys) {
		if (params == null) {
			return name;
		}
		StringBuilder buffer = new StringBuilder(128);
		serializeKey(buffer, params, keys);
		String serializedParams = buffer.toString();
		int paramsLength = serializedParams.length();
		if (maxParamsLength < 44 || paramsLength <= maxParamsLength) {

			// Key = action name : serialized key
			return name + ':' + serializedParams;
		}

		// Length of unhashed part (begining of the serialized params)
		int prefixLength = maxParamsLength - 44;

		// Create SHA-256 hash from the entire key
		byte[] bytes = serializedParams.getBytes(StandardCharsets.UTF_8);
		MessageDigest hasher = hashers.poll();
		if (hasher == null) {
			try {
				hasher = MessageDigest.getInstance("SHA-256");
			} catch (Exception cause) {
				logger.warn("Unable to get SHA-256 hasher!", cause);
				return name + ':' + serializedParams;
			}
		}
		bytes = hasher.digest(bytes);
		hashers.add(hasher);

		// Concatenate key and the 44 character long hash
		String base64 = BASE64.encode(bytes);
		if (prefixLength < 1) {

			// Fully hashed key = action name : hash code
			return name + ':' + base64;
		}

		// Partly hashed key = action name : beginig of the prefix + hash code
		return name + ':' + serializedParams.substring(0, prefixLength) + base64;
	}
599153
public Object decode(CachedData d) {
    byte[] data = d.getData();
    Object rv = null;
    if ((d.getFlags() & COMPRESSED) != 0) {
      data = decompress(d.getData());
    }
    int flags = d.getFlags() & SPECIAL_MASK;
    if ((d.getFlags() & SERIALIZED) != 0 && data != null) {
      rv = deserialize(data);
    } else if (flags != 0 && data != null) {
      switch (flags) {
      case SPECIAL_BOOLEAN:
        rv = Boolean.valueOf(tu.decodeBoolean(data));
        break;
      case SPECIAL_INT:
        rv = Integer.valueOf(tu.decodeInt(data));
        break;
      case SPECIAL_LONG:
        rv = Long.valueOf(tu.decodeLong(data));
        break;
      case SPECIAL_DATE:
        rv = new Date(tu.decodeLong(data));
        break;
      case SPECIAL_BYTE:
        rv = Byte.valueOf(tu.decodeByte(data));
        break;
      case SPECIAL_FLOAT:
        rv = new Float(Float.intBitsToFloat(tu.decodeInt(data)));
        break;
      case SPECIAL_DOUBLE:
        rv = new Double(Double.longBitsToDouble(tu.decodeLong(data)));
        break;
      case SPECIAL_BYTEARRAY:
        rv = data;
        break;
      default:
        getLogger().warn("Undecodeable with flags %x", flags);
      }
    } else {
      rv = decodeString(data);
    }
    return rv;
  }
680667
function (node, result, cache) {
    switch (node.type) {
      case 'start':
      case 'end':
        return ''
      case 'any-character':
        return Random.character()
      case 'backspace':
        return ''
      case 'word-boundary': // TODO
        return ''
      case 'non-word-boundary': // TODO
        break
      case 'digit':
        return Random.pick(
          NUMBER.split('')
        )
      case 'non-digit':
        return Random.pick(
          (LOWER + UPPER + OTHER).split('')
        )
      case 'form-feed':
        break
      case 'line-feed':
        return node.body || node.text
      case 'carriage-return':
        break
      case 'white-space':
        return Random.pick(
          SPACE.split('')
        )
      case 'non-white-space':
        return Random.pick(
          (LOWER + UPPER + NUMBER).split('')
        )
      case 'word': // \w [a-zA-Z0-9]
        return Random.pick(
          (LOWER + UPPER + NUMBER).split('')
        )
      case 'tab':
        break
      case 'vertical-tab':
        break

      case 'non-word': // \W [^a-zA-Z0-9]
        return Random.pick(
          OTHER.replace('_', '').split('')
        )
      case 'null-character':
        break
    }
    return node.body || node.text
  }
620755
@SuppressWarnings("rawtypes")
    private Map.Entry getMapEntry(Node node) {
        Object value = null;
        String keyName = node.getLocalName();
        XmlMapEntry xmlMapEntry = this.mapSpecification.get(keyName);
        switch (node.getNodeType()) {
            case Node.ATTRIBUTE_NODE:
                value = node.getNodeValue();
                break;
            case Node.ELEMENT_NODE: {
                if (xmlMapEntry == null) {
                    value = new NodeArray(node.getChildNodes());
                } else {
                    XmlMapFacet valueFacet = xmlMapEntry.getValue();
                    switch (valueFacet.getType()) {
                        case ELEMENT:
                            value = keyName;
                            break;
                        case CONTENT: {
                            NodeList nodeList = node.getChildNodes();
                            if (nodeList.getLength() > 0) {
                                value = new NodeArray(nodeList);
                            }
                        }
                            break;
                        case ATTRIBUTE: {
                            NamedNodeMap attributes = node.getAttributes();
                            Node attribute = attributes.getNamedItem(valueFacet.getName());
                            if (attribute != null) {
                                value = attribute.getNodeValue();
                            }
                        }
                            break;
                        default:
                            throw new IllegalStateException();
                    }
                    XmlMapFacet keyFacet = xmlMapEntry.getKey();
                    switch (keyFacet.getType()) {
                        case ELEMENT:
                            break;
                        case CONTENT: {
                            NodeList nodeList = node.getChildNodes();
                            if (nodeList.getLength() > 0) {
                                keyName = getStringValue((Node) nodeList.item(0));
                            } else {
                                keyName = null;
                            }
                        }
                            break;
                        case ATTRIBUTE: {
                            NamedNodeMap attributes = node.getAttributes();
                            Node attribute = attributes.getNamedItem(keyFacet.getName());
                            if (attribute != null) {
                                keyName = attribute.getNodeValue();
                            } else {
                                keyName = null;
                            }
                            break;
                        }
                        default:
                            throw new IllegalStateException();
                    }
                }
            }
        }
        if (keyName == null) {
            return null;
        } else {
            final Object _key = keyName;
            final Object _value = value;
            return new Map.Entry() {

                @Override
                public Object getKey() {
                    return _key;
                }

                @Override
                public Object getValue() {
                    return _value;
                }

                @Override
                public Object setValue(Object object) {
                    return null;
                }

            };
        }
    }
475146
private Iterator<String> decodeKeys(final Iterator<Row<ByteBuffer, DeltaKey>> iter) {
        return new AbstractIterator<String>() {
            @Override
            protected String computeNext() {
                while (iter.hasNext()) {
                    Row<ByteBuffer, DeltaKey> row = iter.next();
                    if (!row.getColumns().isEmpty()) { // Ignore range ghosts
                        return AstyanaxStorage.getContentKey(row.getRawKey());
                    }
                }
                return endOfData();
            }
        };
    }
659718
def encode(self, name, as_map_key=False):
        """"""
        if name in self.key_to_value:
            return self.key_to_value[name]
        return self.encache(name) if is_cacheable(name, as_map_key) else name
756086
@SuppressWarnings("unchecked")
    public static <T> T get(Object key) {
        try {
            return (T) CACHE.get(key);
        } catch (ClassCastException e) {
            System.out.print("E/Cache: Can't use cached object: wrong type");
        }
        return null;
    }
122448
@Override
  public InetSocketAddress get(final Identifier key,
                               final Callable<InetSocketAddress> valueFetcher) throws ExecutionException {
    return cache.get(key, valueFetcher);
  }
376444
protected Object getFromCache(String cacheName, String key) {
        try {
            ICache cache = getCache(cacheName);
            return cache != null ? cache.get(key) : null;
        } catch (CacheException e) {
            LOGGER.warn(e.getMessage(), e);
            return null;
        }
    }