mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-02-22 14:22:45 +01:00
BaseMessage: make bitcoinSerializeToStream()
abstract
Rather than log an error at runtime, the compiler should fail with an error when subclasses of `BaseMessage` don't implement `bitcoinSerializeToStream()`.
This commit is contained in:
parent
792183dfef
commit
97b88fffdf
2 changed files with 5 additions and 3 deletions
|
@ -62,9 +62,7 @@ public abstract class BaseMessage implements Message {
|
|||
/**
|
||||
* Serializes this message to the provided stream. If you just want the raw bytes use bitcoinSerialize().
|
||||
*/
|
||||
protected void bitcoinSerializeToStream(OutputStream stream) throws IOException {
|
||||
log.error("Error: {} class has not implemented bitcoinSerializeToStream method. Generating message with no payload", getClass());
|
||||
}
|
||||
protected abstract void bitcoinSerializeToStream(OutputStream stream) throws IOException;
|
||||
|
||||
/** @deprecated use {@link Transaction#getTxId()}, {@link Block#getHash()}, {@link FilteredBlock#getHash()} or {@link TransactionOutPoint#hash()} */
|
||||
@Deprecated
|
||||
|
|
|
@ -25,6 +25,8 @@ import org.bitcoinj.params.TestNet3Params;
|
|||
import org.junit.Test;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.math.BigInteger;
|
||||
import java.net.InetAddress;
|
||||
import java.nio.BufferUnderflowException;
|
||||
|
@ -234,6 +236,8 @@ public class BitcoinSerializerTest {
|
|||
MessageSerializer serializer = MAINNET.getDefaultSerializer();
|
||||
|
||||
Message unknownMessage = new BaseMessage() {
|
||||
@Override
|
||||
protected void bitcoinSerializeToStream(OutputStream stream) {}
|
||||
};
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream(ADDRESS_MESSAGE_BYTES.length);
|
||||
serializer.serialize(unknownMessage, bos);
|
||||
|
|
Loading…
Add table
Reference in a new issue