Search in sources :

Example 1 with MetadataValueBuilder

use of io.nem.symbol.catapult.builders.MetadataValueBuilder in project nem2-sdk-java by nemtech.

the class MetadataTest method testMetadataValueBuilder.

@Test
public void testMetadataValueBuilder() {
    String plainText = "Some String";
    MetadataValueBuilder builder = MetadataValueBuilder.create(ByteBuffer.wrap(StringEncoder.getBytes(plainText)));
    Assertions.assertEquals(11, StringEncoder.getBytes(plainText).length);
    // Assertions.assertEquals(11, builder.getStreamSize());
    Assertions.assertEquals(13, builder.getSize());
    Assertions.assertEquals(plainText, StringEncoder.getString(builder.getData().array()));
    MetadataValueBuilder deserializedBuilder = MetadataValueBuilder.loadFromBinary(SerializationUtils.toDataInput(builder.serialize()));
    Assertions.assertEquals(plainText, StringEncoder.getString(deserializedBuilder.getData().array()));
    Assertions.assertEquals(13, deserializedBuilder.getSize());
}
Also used : MetadataValueBuilder(io.nem.symbol.catapult.builders.MetadataValueBuilder) Test(org.junit.jupiter.api.Test)

Example 2 with MetadataValueBuilder

use of io.nem.symbol.catapult.builders.MetadataValueBuilder in project nem2-sdk-java by nemtech.

the class Metadata method serialize.

/**
 * @return serializes the state of this object.
 */
public byte[] serialize() {
    AddressDto sourceAddress = SerializationUtils.toAddressDto(getSourceAddress());
    AddressDto targetAddress = SerializationUtils.toAddressDto(getTargetAddress());
    ScopedMetadataKeyDto scopedMetadataKey = new ScopedMetadataKeyDto(getScopedMetadataKey().longValue());
    long targetId = getTargetId().map(this::toTargetId).orElse(0L);
    MetadataTypeDto metadataType = MetadataTypeDto.rawValueOf((byte) getMetadataType().getValue());
    MetadataValueBuilder value = toMetadataValueBuilder(getValue());
    return MetadataEntryBuilder.create((short) getVersion(), sourceAddress, targetAddress, scopedMetadataKey, targetId, metadataType, value).serialize();
}
Also used : MetadataValueBuilder(io.nem.symbol.catapult.builders.MetadataValueBuilder) AddressDto(io.nem.symbol.catapult.builders.AddressDto) ScopedMetadataKeyDto(io.nem.symbol.catapult.builders.ScopedMetadataKeyDto) MetadataTypeDto(io.nem.symbol.catapult.builders.MetadataTypeDto)

Aggregations

MetadataValueBuilder (io.nem.symbol.catapult.builders.MetadataValueBuilder)2 AddressDto (io.nem.symbol.catapult.builders.AddressDto)1 MetadataTypeDto (io.nem.symbol.catapult.builders.MetadataTypeDto)1 ScopedMetadataKeyDto (io.nem.symbol.catapult.builders.ScopedMetadataKeyDto)1 Test (org.junit.jupiter.api.Test)1