Search in sources :

Example 21 with SerializableDataInputStream

use of com.swirlds.common.io.SerializableDataInputStream in project hedera-services by hashgraph.

the class MerkleUniqueTokenTest method liveFireSerdeWorks.

@Test
void liveFireSerdeWorks() throws IOException, ConstructableRegistryException {
    // setup:
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final var dos = new SerializableDataOutputStream(baos);
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(MerkleUniqueToken.class, MerkleUniqueToken::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(EntityId.class, EntityId::new));
    // given:
    subject.serialize(dos);
    dos.flush();
    // and:
    final var bytes = baos.toByteArray();
    final ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
    final var din = new SerializableDataInputStream(bais);
    // when:
    final var newSubject = new MerkleUniqueToken();
    newSubject.deserialize(din, MerkleToken.CURRENT_VERSION);
    // then:
    assertEquals(subject, newSubject);
}
Also used : EntityId(com.hedera.services.state.submerkle.EntityId) ByteArrayInputStream(java.io.ByteArrayInputStream) SerializableDataOutputStream(com.swirlds.common.io.SerializableDataOutputStream) SerializableDataInputStream(com.swirlds.common.io.SerializableDataInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ClassConstructorPair(com.swirlds.common.constructable.ClassConstructorPair) Test(org.junit.jupiter.api.Test)

Aggregations

SerializableDataInputStream (com.swirlds.common.io.SerializableDataInputStream)21 Test (org.junit.jupiter.api.Test)20 SerializableDataOutputStream (com.swirlds.common.io.SerializableDataOutputStream)15 ByteArrayInputStream (java.io.ByteArrayInputStream)14 ByteArrayOutputStream (java.io.ByteArrayOutputStream)14 ClassConstructorPair (com.swirlds.common.constructable.ClassConstructorPair)9 DomainSerdes (com.hedera.services.state.serdes.DomainSerdes)2 EntityId (com.hedera.services.state.submerkle.EntityId)2 JKeySerializer (com.hedera.services.legacy.core.jproto.JKeySerializer)1 FilePart (com.hedera.services.state.merkle.internals.FilePart)1 FcCustomFee (com.hedera.services.state.submerkle.FcCustomFee)1 EntityNumPair (com.hedera.services.utils.EntityNumPair)1 FCQueue (com.swirlds.fcqueue.FCQueue)1