org.bitcoinj.core.Utils.uint32ToByteArrayBE()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(8.3k)|赞(0)|评价(0)|浏览(81)

本文整理了Java中org.bitcoinj.core.Utils.uint32ToByteArrayBE()方法的一些代码示例,展示了Utils.uint32ToByteArrayBE()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utils.uint32ToByteArrayBE()方法的具体详情如下:
包路径:org.bitcoinj.core.Utils
类名称:Utils
方法名:uint32ToByteArrayBE

Utils.uint32ToByteArrayBE介绍

暂无

代码示例

代码示例来源:origin: fr.acinq/bitcoinj-core

byte[] result = new byte[length + 4];
System.arraycopy(array, 0, result, length - array.length + 3, array.length);
uint32ToByteArrayBE(length, result, 0);
if (isNegative)
  result[4] |= 0x80;

代码示例来源:origin: greenaddress/GreenBits

/**
 * Writes message to to the output stream.
 */
@Override
public void serialize(String name, byte[] message, OutputStream out) throws IOException {
  byte[] header = new byte[4 + COMMAND_LEN + 4 + 4 /* checksum */];
  uint32ToByteArrayBE(params.getPacketMagic(), header, 0);
  // The header array is initialized to zero by Java so we don't have to worry about
  // NULL terminating the string here.
  for (int i = 0; i < name.length() && i < COMMAND_LEN; i++) {
    header[4 + i] = (byte) (name.codePointAt(i) & 0xFF);
  }
  Utils.uint32ToByteArrayLE(message.length, header, 4 + COMMAND_LEN);
  byte[] hash = Sha256Hash.hashTwice(message);
  System.arraycopy(hash, 0, header, 4 + COMMAND_LEN + 4, 4);
  out.write(header);
  out.write(message);
  if (log.isDebugEnabled())
    log.debug("Sending {} message: {}", name, HEX.encode(header) + HEX.encode(message));
}

代码示例来源:origin: cash.bitcoinj/bitcoinj-core

byte[] result = new byte[length + 4];
System.arraycopy(array, 0, result, length - array.length + 3, array.length);
uint32ToByteArrayBE(length, result, 0);
if (isNegative)
  result[4] |= 0x80;

代码示例来源:origin: greenaddress/GreenBits

byte[] result = new byte[length + 4];
System.arraycopy(array, 0, result, length - array.length + 3, array.length);
uint32ToByteArrayBE(length, result, 0);
if (isNegative)
  result[4] |= 0x80;

代码示例来源:origin: HashEngineering/dashj

byte[] result = new byte[length + 4];
System.arraycopy(array, 0, result, length - array.length + 3, array.length);
uint32ToByteArrayBE(length, result, 0);
if (isNegative)
  result[4] |= 0x80;

代码示例来源:origin: HashEngineering/dashj

/**
 * Writes message to to the output stream.
 */
@Override
public void serialize(String name, byte[] message, OutputStream out) throws IOException {
  byte[] header = new byte[4 + COMMAND_LEN + 4 + 4 /* checksum */];
  uint32ToByteArrayBE(params.getPacketMagic(), header, 0);
  // The header array is initialized to zero by Java so we don't have to worry about
  // NULL terminating the string here.
  for (int i = 0; i < name.length() && i < COMMAND_LEN; i++) {
    header[4 + i] = (byte) (name.codePointAt(i) & 0xFF);
  }
  Utils.uint32ToByteArrayLE(message.length, header, 4 + COMMAND_LEN);
  byte[] hash = Sha256Hash.hashTwice(message);
  System.arraycopy(hash, 0, header, 4 + COMMAND_LEN + 4, 4);
  out.write(header);
  out.write(message);
  if (log.isDebugEnabled())
    log.debug("Sending {} message: {}", name, HEX.encode(header) + HEX.encode(message));
}

代码示例来源:origin: cash.bitcoinj/bitcoinj-core

/**
 * Writes message to to the output stream.
 */
@Override
public void serialize(String name, byte[] message, OutputStream out) throws IOException {
  byte[] header = new byte[4 + COMMAND_LEN + 4 + 4 /* checksum */];
  uint32ToByteArrayBE(params.getPacketMagic(), header, 0);
  // The header array is initialized to zero by Java so we don't have to worry about
  // NULL terminating the string here.
  for (int i = 0; i < name.length() && i < COMMAND_LEN; i++) {
    header[4 + i] = (byte) (name.codePointAt(i) & 0xFF);
  }
  Utils.uint32ToByteArrayLE(message.length, header, 4 + COMMAND_LEN);
  byte[] hash = Sha256Hash.hashTwice(message);
  System.arraycopy(hash, 0, header, 4 + COMMAND_LEN + 4, 4);
  out.write(header);
  out.write(message);
  if (log.isDebugEnabled())
    log.debug("Sending {} message: {}", name, HEX.encode(header) + HEX.encode(message));
}

代码示例来源:origin: fr.acinq/bitcoinj-core

/**
 * Writes message to to the output stream.
 */
@Override
public void serialize(String name, byte[] message, OutputStream out) throws IOException {
  byte[] header = new byte[4 + COMMAND_LEN + 4 + 4 /* checksum */];
  uint32ToByteArrayBE(params.getPacketMagic(), header, 0);
  // The header array is initialized to zero by Java so we don't have to worry about
  // NULL terminating the string here.
  for (int i = 0; i < name.length() && i < COMMAND_LEN; i++) {
    header[4 + i] = (byte) (name.codePointAt(i) & 0xFF);
  }
  Utils.uint32ToByteArrayLE(message.length, header, 4 + COMMAND_LEN);
  byte[] hash = Sha256Hash.hashTwice(message);
  System.arraycopy(hash, 0, header, 4 + COMMAND_LEN + 4, 4);
  out.write(header);
  out.write(message);
  if (log.isDebugEnabled())
    log.debug("Sending {} message: {}", name, HEX.encode(header) + HEX.encode(message));
}

代码示例来源:origin: cash.bitcoinj/bitcoinj-core

/**
   * <p>Writes the given message to the other side of the connection, prefixing it with the proper 4-byte prefix.</p>
   *
   * <p>Provides a write-order guarantee.</p>
   *
   * @throws IllegalStateException If the encoded message is larger than the maximum message size.
   */
  public void write(MessageType msg) throws IllegalStateException {
    byte[] messageBytes = msg.toByteArray();
    checkState(messageBytes.length <= maxMessageSize);
    byte[] messageLength = new byte[4];
    Utils.uint32ToByteArrayBE(messageBytes.length, messageLength, 0);
    try {
      MessageWriteTarget target = writeTarget.get();
      target.writeBytes(messageLength);
      target.writeBytes(messageBytes);
    } catch (IOException e) {
      closeConnection();
    }
  }
}

代码示例来源:origin: fr.acinq/bitcoinj-core

/**
   * <p>Writes the given message to the other side of the connection, prefixing it with the proper 4-byte prefix.</p>
   *
   * <p>Provides a write-order guarantee.</p>
   *
   * @throws IllegalStateException If the encoded message is larger than the maximum message size.
   */
  public void write(MessageType msg) throws IllegalStateException {
    byte[] messageBytes = msg.toByteArray();
    checkState(messageBytes.length <= maxMessageSize);
    byte[] messageLength = new byte[4];
    Utils.uint32ToByteArrayBE(messageBytes.length, messageLength, 0);
    try {
      MessageWriteTarget target = writeTarget.get();
      target.writeBytes(messageLength);
      target.writeBytes(messageBytes);
    } catch (IOException e) {
      closeConnection();
    }
  }
}

代码示例来源:origin: greenaddress/GreenBits

/**
   * <p>Writes the given message to the other side of the connection, prefixing it with the proper 4-byte prefix.</p>
   *
   * <p>Provides a write-order guarantee.</p>
   *
   * @throws IllegalStateException If the encoded message is larger than the maximum message size.
   */
  public void write(MessageType msg) throws IllegalStateException {
    byte[] messageBytes = msg.toByteArray();
    checkState(messageBytes.length <= maxMessageSize);
    byte[] messageLength = new byte[4];
    Utils.uint32ToByteArrayBE(messageBytes.length, messageLength, 0);
    try {
      MessageWriteTarget target = writeTarget.get();
      target.writeBytes(messageLength);
      target.writeBytes(messageBytes);
    } catch (IOException e) {
      closeConnection();
    }
  }
}

代码示例来源:origin: HashEngineering/dashj

/**
   * <p>Writes the given message to the other side of the connection, prefixing it with the proper 4-byte prefix.</p>
   *
   * <p>Provides a write-order guarantee.</p>
   *
   * @throws IllegalStateException If the encoded message is larger than the maximum message size.
   */
  public void write(MessageType msg) throws IllegalStateException {
    byte[] messageBytes = msg.toByteArray();
    checkState(messageBytes.length <= maxMessageSize);
    byte[] messageLength = new byte[4];
    Utils.uint32ToByteArrayBE(messageBytes.length, messageLength, 0);
    try {
      MessageWriteTarget target = writeTarget.get();
      target.writeBytes(messageLength);
      target.writeBytes(messageBytes);
    } catch (IOException e) {
      closeConnection();
    }
  }
}

代码示例来源:origin: greenaddress/GreenBits

@Override
  public boolean add(Rule element) {
    if (outStream != null && element instanceof BlockAndValidity) {
      try {
        outStream.write((int) (params.getPacketMagic() >>> 24));
        outStream.write((int) (params.getPacketMagic() >>> 16));
        outStream.write((int) (params.getPacketMagic() >>> 8));
        outStream.write((int) params.getPacketMagic());
        byte[] block = ((BlockAndValidity)element).block.bitcoinSerialize();
        byte[] length = new byte[4];
        Utils.uint32ToByteArrayBE(block.length, length, 0);
        outStream.write(Utils.reverseBytes(length));
        outStream.write(block);
        ((BlockAndValidity)element).block = null;
      } catch (IOException e) {
        throw new RuntimeException(e);
      }
    }
    return super.add(element);
  }
};

代码示例来源:origin: greenaddress/GreenBits

Utils.uint32ToByteArrayBE(messageBytes.length, messageLength, 0);
client.writeBytes(new byte[]{messageLength[0], messageLength[1]});
Thread.sleep(10);
Utils.uint32ToByteArrayBE(messageBytes2.length, messageLength2, 0);
byte[] sendBytes = Arrays.copyOf(new byte[] {messageBytes[messageBytes.length-1]}, 1 + messageBytes2.length*2 + messageLength2.length*2);
System.arraycopy(messageLength2, 0, sendBytes, 1, 4);
Utils.uint32ToByteArrayBE(messageBytes2.length, messageLength2, 0);
client.writeBytes(new byte[]{messageLength2[0], messageLength2[1]});
Thread.sleep(10);
Utils.uint32ToByteArrayBE(msg5.toByteArray().length, messageLength5, 0);
client.writeBytes(messageLength5);

相关文章