@ Override public Message deserialize ( ByteBuffer in ) throws ProtocolException , IOException { // A Bitcoin protocol message has the following format. // // - 4 byte magic number: 0xfabfb5da for the testnet or // 0xf9beb4d9 for production // - 12 byte command in ASCII // - 4 byte payload size // - 4 byte checksum // - Payload data // // The checksum is the first 4 bytes of a SHA256 hash of the message payload. It isn't // present for all messages, notably, the first one on a connection. // // Bitcoin Core ignores garbage before the magic header bytes. We have to do the same because // sometimes it sends us stuff that isn't part of any message. seekPastMagicBytes ( in ) ; BitcoinPacketHeader header = new BitcoinPacketHeader ( in ) ; // Now try to read the whole message. return deserializePayload ( header , in ) ; }
Reads a message from the given ByteBuffer and returns it .