All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hedera.hapi.block.PublishStreamRequest Maven / Gradle / Ivy

There is a newer version: 0.54.0
Show newest version
package com.hedera.hapi.block;

import com.hedera.hapi.block.stream.*;
import com.hedera.pbj.runtime.*;
import com.hedera.pbj.runtime.io.*;
import com.hedera.pbj.runtime.io.buffer.*;
import com.hedera.pbj.runtime.io.stream.*;
import edu.umd.cs.findbugs.annotations.*;

import com.hedera.pbj.runtime.Codec;
import java.util.function.Consumer;
import edu.umd.cs.findbugs.annotations.Nullable;
import edu.umd.cs.findbugs.annotations.NonNull;
import static java.util.Objects.requireNonNull;

/**
 * Publish a stream of blocks.
 * 

* Each item in the stream MUST contain one `BlockItem`.
* Each Block MUST begin with a single `BlockHeader` block item.
* The block node SHALL append each `BlockItem` to an internal structure * to reconstruct full blocks.
* The block node MUST verify the block proof for each block before sending a * response message acknowledging that block.
* Each Block MUST end with a single `BlockStateProof` block item.
* The block node MUST verify the Block using the `BlockStateProof` to * ensure all data was received and processed correctly.
* * @param blockItem (1) A single item written to the block stream. */ public record PublishStreamRequest( @Nullable BlockItem blockItem ) { /** Protobuf codec for reading and writing in protobuf format */ public static final Codec PROTOBUF = new com.hedera.hapi.block.codec.PublishStreamRequestProtoCodec(); /** JSON codec for reading and writing in JSON format */ public static final JsonCodec JSON = new com.hedera.hapi.block.codec.PublishStreamRequestJsonCodec(); /** Default instance with all fields set to default values */ public static final PublishStreamRequest DEFAULT = newBuilder().build(); /** * Create a pre-populated PublishStreamRequest. * * @param blockItem (1) A single item written to the block stream. */ public PublishStreamRequest(BlockItem blockItem) { this.blockItem = blockItem; } /** * Override the default hashCode method for * all other objects to make hashCode */ @Override public int hashCode() { int result = 1; if (blockItem != null && !blockItem.equals(DEFAULT.blockItem)) { result = 31 * result + blockItem.hashCode(); } long hashCode = result; // Shifts: 30, 27, 16, 20, 5, 18, 10, 24, 30 hashCode += hashCode << 30; hashCode ^= hashCode >>> 27; hashCode += hashCode << 16; hashCode ^= hashCode >>> 20; hashCode += hashCode << 5; hashCode ^= hashCode >>> 18; hashCode += hashCode << 10; hashCode ^= hashCode >>> 24; hashCode += hashCode << 30; return (int)hashCode; } /** * Override the default equals method for */ @Override public boolean equals(Object that) { if (that == null || this.getClass() != that.getClass()) { return false; } PublishStreamRequest thatObj = (PublishStreamRequest)that; if (blockItem == null && thatObj.blockItem != null) { return false; } if (blockItem != null && !blockItem.equals(thatObj.blockItem)) { return false; } return true; } /** * Convenience method to check if the blockItem has a value * * @return true of the blockItem has a value */ public boolean hasBlockItem() { return blockItem != null; } /** * Gets the value for blockItem if it has a value, or else returns the default * value for the type. * * @param defaultValue the default value to return if blockItem is null * @return the value for blockItem if it has a value, or else returns the default value */ public BlockItem blockItemOrElse(@NonNull final BlockItem defaultValue) { return hasBlockItem() ? blockItem : defaultValue; } /** * Gets the value for blockItem if it has a value, or else throws an NPE. * value for the type. * * @return the value for blockItem if it has a value * @throws NullPointerException if blockItem is null */ public @NonNull BlockItem blockItemOrThrow() { return requireNonNull(blockItem, "Field blockItem is null"); } /** * Executes the supplied {@link Consumer} if, and only if, the blockItem has a value * * @param ifPresent the {@link Consumer} to execute */ public void ifBlockItem(@NonNull final Consumer ifPresent) { if (hasBlockItem()) { ifPresent.accept(blockItem); } } /** * Return a builder for building a copy of this model object. It will be pre-populated with all the data from this * model object. * * @return a pre-populated builder */ public Builder copyBuilder() { return new Builder(blockItem); } /** * Return a new builder for building a model object. This is just a shortcut for new Model.Builder(). * * @return a new builder */ public static Builder newBuilder() { return new Builder(); } /** * Builder class for easy creation, ideal for clean code where performance is not critical. In critical performance * paths use the constructor directly. */ public static final class Builder { @Nullable private BlockItem blockItem = null; /** * Create an empty builder */ public Builder() {} /** * Create a pre-populated Builder. * * @param blockItem (1) A single item written to the block stream. */ public Builder(BlockItem blockItem) { this.blockItem = blockItem; } /** * Build a new model record with data set on builder * * @return new model record with data set */ public PublishStreamRequest build() { return new PublishStreamRequest(blockItem); } /** * (1) A single item written to the block stream. * * @param blockItem value to set * @return builder to continue building with */ public Builder blockItem(@Nullable BlockItem blockItem) { this.blockItem = blockItem; return this; } /** * (1) A single item written to the block stream. * * @param builder A pre-populated builder * @return builder to continue building with */ public Builder blockItem(BlockItem.Builder builder) { this.blockItem = builder.build() ; return this; } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy