Services: migrate to byte[] serialize() from ByteBuffer buffer()

This commit is contained in:
Andreas Schildbach 2023-04-03 21:21:21 +02:00
parent 5ded7782be
commit 98d86375ae
3 changed files with 6 additions and 9 deletions

View File

@ -189,7 +189,7 @@ public class PeerAddress extends Message {
throw new IllegalStateException();
}
} else {
stream.write(services.buffer().array());
stream.write(services.serialize());
if (addr != null) {
// Java does not provide any utility to map an IPv4 address into IPv6 space, so we have to do it by
// hand.

View File

@ -136,15 +136,12 @@ public class Services {
}
/**
* Allocates a buffer and writes the node service bits into it. The buffer is backed by a byte array and it's
* already rewound for reading.
* Allocates a byte array and writes the node service bits into it.
*
* @return buffer containing the service bits
* @return byte array containing the service bits
*/
public ByteBuffer buffer() {
ByteBuffer buf = write(ByteBuffer.allocate(BYTES));
((Buffer) buf).rewind();
return buf;
public byte[] serialize() {
return write(ByteBuffer.allocate(BYTES)).array();
}
public String toString() {

View File

@ -171,7 +171,7 @@ public class VersionMessage extends Message {
@Override
public void bitcoinSerializeToStream(OutputStream buf) throws IOException {
ByteUtils.writeInt32LE(clientVersion, buf);
buf.write(localServices.buffer().array());
buf.write(localServices.serialize());
ByteUtils.writeInt64LE(time.getEpochSecond(), buf);
receivingAddr.bitcoinSerializeToStream(buf);
fromAddr.bitcoinSerializeToStream(buf);