Converts a proto type to a wire type.

@param blockPInfo the proto type to convert
@return the converted wire type
542714
public static BlockInfo fromProto(alluxio.grpc.BlockInfo blockPInfo) {
    BlockInfo blockInfo = new BlockInfo();
    blockInfo.setBlockId(blockPInfo.getBlockId());
    blockInfo.setLength(blockPInfo.getLength());
    blockInfo.setLocations(map(GrpcUtils::fromProto, blockPInfo.getLocationsList()));
    return blockInfo;
  }
1300604
public static TypeInformation<?> PRIMITIVE_ARRAY(TypeInformation<?> elementType) {
		if (elementType == BOOLEAN) {
			return PrimitiveArrayTypeInfo.BOOLEAN_PRIMITIVE_ARRAY_TYPE_INFO;
		} else if (elementType == BYTE) {
			return PrimitiveArrayTypeInfo.BYTE_PRIMITIVE_ARRAY_TYPE_INFO;
		} else if (elementType == SHORT) {
			return PrimitiveArrayTypeInfo.SHORT_PRIMITIVE_ARRAY_TYPE_INFO;
		} else if (elementType == INT) {
			return PrimitiveArrayTypeInfo.INT_PRIMITIVE_ARRAY_TYPE_INFO;
		} else if (elementType == LONG) {
			return PrimitiveArrayTypeInfo.LONG_PRIMITIVE_ARRAY_TYPE_INFO;
		} else if (elementType == FLOAT) {
			return PrimitiveArrayTypeInfo.FLOAT_PRIMITIVE_ARRAY_TYPE_INFO;
		} else if (elementType == DOUBLE) {
			return PrimitiveArrayTypeInfo.DOUBLE_PRIMITIVE_ARRAY_TYPE_INFO;
		} else if (elementType == CHAR) {
			return PrimitiveArrayTypeInfo.CHAR_PRIMITIVE_ARRAY_TYPE_INFO;
		}
		throw new IllegalArgumentException("Invalid element type for a primitive array.");
	}
971135
public Buffer pin(BlockId blk) {
		// Try to find out if this block has been pinned by this transaction
		PinnedBuffer pinnedBuff = pinnedBuffers.get(blk);
		if (pinnedBuff != null) {
			pinnedBuff.pinnedCount++;
			return pinnedBuff.buffer;
		}
		
		// This transaction has pinned too many buffers
		if (pinnedBuffers.size() == BUFFER_POOL_SIZE)
			throw new BufferAbortException();
		
		// Pinning process
		try {
			Buffer buff;
			long timestamp = System.currentTimeMillis();
			boolean waitedBeforeGotBuffer = false;

			// Try to pin a buffer or the pinned buffer for the given BlockId
			buff = bufferPool.pin(blk);

			// If there is no such buffer or no available buffer,
			// wait for it
			if (buff == null) {
				waitedBeforeGotBuffer = true;
				synchronized (bufferPool) {
					waitingThreads.add(Thread.currentThread());

					while (buff == null && !waitingTooLong(timestamp)) {
						bufferPool.wait(MAX_TIME);
						if (waitingThreads.get(0).equals(Thread.currentThread()))
							buff = bufferPool.pin(blk);
					}

					waitingThreads.remove(Thread.currentThread());
				}
			}

			// If it still has no buffer after a long wait,
			// release and re-pin all buffers it has
			if (buff == null) {
				repin();
				buff = pin(blk);
			} else {
				pinnedBuffers.put(buff.block(), new PinnedBuffer(buff));
			}

			// TODO: Add some comment here
			if (waitedBeforeGotBuffer) {
				synchronized (bufferPool) {
					bufferPool.notifyAll();
				}
			}

			return buff;
		} catch (InterruptedException e) {
			throw new BufferAbortException();
		}
	}
913802
public static GethbinfoResult mmpaymkttransfersGethbinfo(Gethbinfo gethbinfo,String key){
		Map<String,String> map = MapUtil.objectToMap( gethbinfo);
		String sign = SignatureUtil.generateSign(map,gethbinfo.getSign_type(),key);
		gethbinfo.setSign(sign);
		String secapiPayRefundXML = XMLConverUtil.convertToXML( gethbinfo);
		HttpUriRequest httpUriRequest = RequestBuilder.post()
				.setHeader(xmlHeader)
				.setUri(baseURI()+ "/mmpaymkttransfers/gethbinfo")
				.setEntity(new StringEntity(secapiPayRefundXML,Charset.forName("utf-8")))
				.build();
		return LocalHttpClient.keyStoreExecuteXmlResult(gethbinfo.getMch_id(),httpUriRequest,GethbinfoResult.class,gethbinfo.getSign_type(),key);
	}
1160037
@Override
    protected int writeBytesWireFormat ( byte[] dst, int dstIndex ) {
        int start = dstIndex;

        SMBUtil.writeInt2(41, dst, dstIndex);
        dst[ dstIndex + 2 ] = this.infoType;
        dst[ dstIndex + 3 ] = this.fileInfoClass;
        dstIndex += 4;

        SMBUtil.writeInt4(this.outputBufferLength, dst, dstIndex);
        dstIndex += 4;
        int inBufferOffsetOffset = dstIndex;
        dstIndex += 4;
        int inBufferLengthOffset = dstIndex;
        dstIndex += 4;
        SMBUtil.writeInt4(this.additionalInformation, dst, dstIndex);
        dstIndex += 4;
        SMBUtil.writeInt4(this.queryFlags, dst, dstIndex);
        dstIndex += 4;
        System.arraycopy(this.fileId, 0, dst, dstIndex, 16);
        dstIndex += 16;

        if ( this.inputBuffer == null ) {
            SMBUtil.writeInt2(0, dst, inBufferOffsetOffset);
            SMBUtil.writeInt4(0, dst, inBufferLengthOffset);
        }
        else {
            SMBUtil.writeInt2(dstIndex - getHeaderStart(), dst, inBufferOffsetOffset);
            int len = this.inputBuffer.encode(dst, dstIndex);
            SMBUtil.writeInt4(len, dst, inBufferLengthOffset);
            dstIndex += len;
        }
        return dstIndex - start;
    }
923605
public void setPin(int pin, boolean active) {
        Buffer buffer = new Buffer();
        buffer.writeIntLe(pin);
        buffer.writeByte(active ? 1 : 0);
        sendMessage(BeanMessageID.BT_SET_PIN, buffer);
    }
628407
private static final ProtoFieldInterpreter enumTypeField(final EnumDescriptor enumDescriptor) {
    return new ProtoFieldInterpreter() {

      @Override
      public SoyValue soyFromProto(Object field) {
        int value;
        if (field instanceof ProtocolMessageEnum) {
          value = ((ProtocolMessageEnum) field).getNumber();
        } else {
          // The value will be an EnumValueDescriptor when fetched via reflection or a
          // ProtocolMessageEnum otherwise.  Who knows why.
          value = ((EnumValueDescriptor) field).getNumber();
        }
        return IntegerData.forValue(value);
      }

      @Override
      Object protoFromSoy(SoyValue field) {
        // The proto reflection api wants the EnumValueDescriptor, not the actual enum instance
        int value = field.integerValue();
        // in proto3 we preserve unknown enum values (for consistency with jbcsrc), but for proto2
        // we don't, and so if the field is unknown we will return null which will trigger an NPE
        // again, for consistency with jbcsrc.
        if (enumDescriptor.getFile().getSyntax() == Syntax.PROTO3) {
          return enumDescriptor.findValueByNumberCreatingIfUnknown(value);
        }
        return enumDescriptor.findValueByNumber(value);
      }
    };
  }
37085
private static void pushStackType(Scope scope, BytecodeBlock block, Type sqlType, BytecodeBlock getBlockBytecode, Class<?> parameter, CallSiteBinder callSiteBinder)
    {
        Variable position = scope.getVariable("position");
        if (parameter == long.class) {
            block.comment("%s.getLong(block, position)", sqlType.getTypeSignature())
                    .append(constantType(callSiteBinder, sqlType))
                    .append(getBlockBytecode)
                    .append(position)
                    .invokeInterface(Type.class, "getLong", long.class, Block.class, int.class);
        }
        else if (parameter == double.class) {
            block.comment("%s.getDouble(block, position)", sqlType.getTypeSignature())
                    .append(constantType(callSiteBinder, sqlType))
                    .append(getBlockBytecode)
                    .append(position)
                    .invokeInterface(Type.class, "getDouble", double.class, Block.class, int.class);
        }
        else if (parameter == boolean.class) {
            block.comment("%s.getBoolean(block, position)", sqlType.getTypeSignature())
                    .append(constantType(callSiteBinder, sqlType))
                    .append(getBlockBytecode)
                    .append(position)
                    .invokeInterface(Type.class, "getBoolean", boolean.class, Block.class, int.class);
        }
        else if (parameter == Slice.class) {
            block.comment("%s.getSlice(block, position)", sqlType.getTypeSignature())
                    .append(constantType(callSiteBinder, sqlType))
                    .append(getBlockBytecode)
                    .append(position)
                    .invokeInterface(Type.class, "getSlice", Slice.class, Block.class, int.class);
        }
        else {
            block.comment("%s.getObject(block, position)", sqlType.getTypeSignature())
                    .append(constantType(callSiteBinder, sqlType))
                    .append(getBlockBytecode)
                    .append(position)
                    .invokeInterface(Type.class, "getObject", Object.class, Block.class, int.class);
        }
    }
506521
public BlockHeader read(byte[] buffer, int offset, int postHeaderSkipBytes)
   {
      m_offset = offset;

      System.arraycopy(buffer, m_offset, m_header, 0, 8);
      m_offset += 8;

      int nameLength = FastTrackUtility.getInt(buffer, m_offset);
      m_offset += 4;

      if (nameLength < 1 || nameLength > 255)
      {
         throw new UnexpectedStructureException();
      }

      m_name = new String(buffer, m_offset, nameLength, CharsetHelper.UTF16LE);
      m_offset += nameLength;

      m_columnType = FastTrackUtility.getShort(buffer, m_offset);
      m_offset += 2;

      m_flags = FastTrackUtility.getShort(buffer, m_offset);
      m_offset += 2;

      m_skip = new byte[postHeaderSkipBytes];
      System.arraycopy(buffer, m_offset, m_skip, 0, postHeaderSkipBytes);
      m_offset += postHeaderSkipBytes;

      return this;
   }
1367187
@Override
    protected int readBytesWireFormat ( byte[] buffer, int bufferIndex ) throws SMBProtocolDecodingException {
        int start = bufferIndex;
        int structureSize = SMBUtil.readInt2(buffer, bufferIndex);
        if ( structureSize != 16 ) {
            throw new SMBProtocolDecodingException("Structure size is not 16");
        }

        this.shareType = buffer[ bufferIndex + 2 ];
        bufferIndex += 4;
        this.shareFlags = SMBUtil.readInt4(buffer, bufferIndex);
        bufferIndex += 4;
        this.capabilities = SMBUtil.readInt4(buffer, bufferIndex);
        bufferIndex += 4;
        this.maximalAccess = SMBUtil.readInt4(buffer, bufferIndex);
        bufferIndex += 4;
        return bufferIndex - start;
    }
1333301
private synchronized DatanodeInfo blockSeekTo(long target,
      boolean throwWhenNotFound) throws IOException {
    // We only allow to seek before the end of the file, or the end of the file
    // and allowSeedtoEnd, which is the case called by available().
    //
    if (target > getFileLength() || (target == getFileLength() && throwWhenNotFound)) {
      throw new IOException("Attempted to read past end of file");
    }

    // Will be getting a new BlockReader.
    if ( blockReader != null ) {
      closeBlockReader(blockReader, false);
      blockReader = null;
    }
    
    //
    // Compute desired block.
    //
    LocatedBlock targetBlock = getBlockAt(target, true, throwWhenNotFound);
    // Given target<= fileLength, when and only whenallowSeektoEnd is true and
    // there is no block for the file yet, getBlockAt() returns null, in this
    // case we should simply return null.
    //
    if (targetBlock == null) {
      assert target == 0;
      return null;
    }
    assert (target==this.pos) : "Wrong postion " + pos + " expect " + target;
    long offsetIntoBlock = target - targetBlock.getStartOffset();

    //
    // Connect to best DataNode for desired Block, with potential offset
    //
    DatanodeInfo chosenNode = null;
    BlockSeekContext seekContext = new BlockSeekContext(targetBlock);
    while (true) {
      DNAddrPair retval = chooseDataNode(seekContext);
      chosenNode = retval.info;
      InetSocketAddress targetAddr = retval.addr;
      final InetAddress chosenDataNodeAddress = targetAddr.getAddress();
      final boolean isChosenDatanodeLocal = NetUtils.isLocalAddressWithCaching(chosenDataNodeAddress)
          || (dfsClient.localHost != null && dfsClient.localHost.equals(chosenDataNodeAddress));
      
      // try reading the block locally. if this fails, then go via
      // the datanode
      Block blk = seekContext.getTargetBlock().getBlock();
      try {
        if (DFSClient.LOG.isDebugEnabled()) {
          DFSClient.LOG.warn("blockSeekTo shortCircuitLocalReads "
                   + dfsClient.shortCircuitLocalReads +
                   " localhost " + dfsClient.localHost +
                   " targetAddr " + targetAddr);
        }
        if (dfsClient.shortCircuitLocalReads && isChosenDatanodeLocal) {
          blockReader = BlockReaderLocalBase.newBlockReader(dfsClient.conf, src,
                                                 dfsClient.namespaceId, blk,
                                                 chosenNode,
                                                 offsetIntoBlock,
                                                 blk.getNumBytes() - offsetIntoBlock,
                                                 dfsClient.metrics, 
                                                 this.verifyChecksum,
                                                 this.clearOsBuffer,
                                                 false);
          if (blockReader != null) {
            blockReader.setReadLocal(true);
            blockReader.setFsStats(dfsClient.stats);
            if (cliData != null) {
              cliData.recordReadBlockSeekToTime();
            }
            return chosenNode;
          } else if (!dfsClient.shortcircuitDisableWhenFail) {
            throw new IOException(
                "Short circuit local read not supported for inline checksum file.");
          }
        }
      } catch (IOException ex) {
        DFSClient.LOG.info("Failed to read block " + seekContext.getTargetBlock().getBlock() +
                 " on local machine " + dfsClient.localHost +
                 ". Try via the datanode on " + targetAddr + ":"
                  + StringUtils.stringifyException(ex));
      }

      try {
        long minReadSpeedBps = (dfsClient.numNodeLeft(seekContext.getTargetBlock().getLocations(),
            deadNodes) > 1) ? dfsClient.minReadSpeedBps : -1;
        blockReader = getBlockReader(
            dfsClient.getDataTransferProtocolVersion(), dfsClient.namespaceId,
            targetAddr, src, blk.getBlockId(),
            blk.getGenerationStamp(),
            offsetIntoBlock, blk.getNumBytes() - offsetIntoBlock,
            buffersize, verifyChecksum,
            dfsClient.clientName, dfsClient.bytesToCheckReadSpeed,
            minReadSpeedBps, false, cliData);
        blockReader.setReadLocal(isChosenDatanodeLocal);
        blockReader.enableThrowForSlow = dfsClient.enableThrowForSlow;
        if (!isChosenDatanodeLocal) {
          blockReader
              .setReadRackLocal(dfsClient.isInLocalRack(targetAddr));
        }
        blockReader.setFsStats(dfsClient.stats);
        if (cliData != null) {
          cliData.recordReadBlockSeekToTime();
        }
        return chosenNode;
      } catch (IOException ex) {
        // Put chosen node into dead list, continue
        DFSClient.LOG.warn("Failed to connect to " + targetAddr, ex);
        addToDeadNodes(chosenNode);
      }
    }
  }
691597
public static <T> void registerBlockData(String identifier, Function<ByteBuf, T> fromBytes, Function<T, ByteBuf> toBytes)
	{
		instance.handlerInfos.put(identifier, new HandlerInfo<>(identifier, fromBytes, toBytes));
	}
849683
def ConvertFromWireFormat(self, value, container=None):
    """"""
    result = AnyValue()
    ReadIntoObject(value[2], 0, result)
    if self._type is not None:
      converted_value = self._type(container)
    else:
      converted_value = self._TypeFromAnyValue(result)

    # If one of the protobuf library wrapper classes is used, unwrap the value.
    if result.type_url.startswith("type.googleapis.com/google.protobuf."):
      wrapper_cls = self.__class__.WRAPPER_BY_TYPE[
          converted_value.data_store_type]
      wrapper_value = wrapper_cls()
      wrapper_value.ParseFromString(result.value)
      return converted_value.FromDatastoreValue(wrapper_value.value)
    else:
      # TODO(user): Type stored in type_url is currently ignored when value
      # is decoded. We should use it to deserialize the value and then check
      # that value type and dynamic type are compatible.
      return converted_value.FromSerializedString(result.value)
747202
public Collection<BasicBlock> getBlocksContainingInstructionWithOffset(int offset) {
        LinkedList<BasicBlock> result = new LinkedList<>();
        for (Iterator<BasicBlock> i = blockIterator(); i.hasNext();) {
            BasicBlock block = i.next();
            if (block.containsInstructionWithOffset(offset)) {
                result.add(block);
            }
        }
        return result;
    }
732062
public BlockInfo getInfo(long blockId) throws IOException {
    try (CloseableResource<BlockMasterClient> masterClientResource =
        mContext.acquireBlockMasterClientResource()) {
      return masterClientResource.get().getBlockInfo(blockId);
    }
  }
581805
@Override
    public WsByteBuffer[] marshallBinaryFirstLine() {
        WsByteBuffer[] firstLine = new WsByteBuffer[1];
        firstLine[0] = allocateBuffer(getOutgoingBufferSize());

        // prepend the binary protocol version first
        firstLine = putByte(HttpInternalConstants.BINARY_TRANSPORT_V1, firstLine);
        if (getVersionValue().isUndefined()) {
            // unknown version....marshall (masked(len)+Str)
            byte[] data = getVersionValue().getByteArray();
            firstLine = putInt(data.length | GenericConstants.KNOWN_MASK, firstLine);
            firstLine = putBytes(data, firstLine);
        } else {
            // known version...marshall versionID
            firstLine = putInt(getVersionValue().getOrdinal(), firstLine);
        }

        // Status Code
        firstLine = putInt(this.myStatusCode.getIntCode(), firstLine);

        if (null != this.myReasonBytes) {
            // Reason exists....marshall (len+Str)
            firstLine = putInt(this.myReasonBytes.length, firstLine);
            firstLine = putBytes(this.myReasonBytes, firstLine);
        } else {
            // reason does not exist...marshall 0 as len
            firstLine = putInt(0, firstLine);
        }
        if (TraceComponent.isAnyTracingEnabled() && tc.isEventEnabled()) {
            Tr.event(tc, "Marshalling binary first line: " + getVersion() + " " + getStatusCodeAsInt() + " " + getReasonPhrase());
        }
        // don't flip the last buffer as headers get tacked on the end
        return firstLine;
    }
990856
public ObjectType createAnonymousObjectType(JSDocInfo info) {
    PrototypeObjectType type = new PrototypeObjectType(
        this, null, null, true /* anonymousType */);
    type.setPrettyPrint(true);
    type.setJSDocInfo(info);
    return type;
  }