Search in sources :

Example 1 with TransactionData

use of io.pravega.segmentstore.storage.metadata.BaseMetadataStore.TransactionData in project pravega by pravega.

the class SltsMetadataSerializer method serialize.

@Override
public ByteBuffer serialize(String value) {
    ByteBuffer buf;
    try {
        // Convert string to map with fields and values.
        Map<String, String> data = parseStringData(value);
        // Use the map to build TransactionData. If the field/key queried does not exist we throw an IllegalArgumentException.
        // The value is handled by checking if a unique field corresponding to any specific implementation of StorageMetadata exists.
        // The correct instance of StorageMetadata is then generated.
        TransactionData transactionData = TransactionData.builder().key(getAndRemoveIfExists(data, TRANSACTION_DATA_KEY)).version(Long.parseLong(getAndRemoveIfExists(data, TRANSACTION_DATA_VERSION))).value(generateStorageMetadataValue(data)).build();
        buf = SERIALIZER.serialize(transactionData).asByteBuffer();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return buf;
}
Also used : TransactionData(io.pravega.segmentstore.storage.metadata.BaseMetadataStore.TransactionData) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer)

Example 2 with TransactionData

use of io.pravega.segmentstore.storage.metadata.BaseMetadataStore.TransactionData in project pravega by pravega.

the class SltsMetadataSerializer method deserialize.

@Override
public String deserialize(ByteBuffer serializedValue) {
    StringBuilder stringValueBuilder;
    try {
        TransactionData data = SERIALIZER.deserialize(new ByteArraySegment(serializedValue).getReader());
        stringValueBuilder = new StringBuilder();
        appendField(stringValueBuilder, TRANSACTION_DATA_KEY, data.getKey());
        appendField(stringValueBuilder, TRANSACTION_DATA_VERSION, String.valueOf(data.getVersion()));
        handleStorageMetadataValue(stringValueBuilder, data.getValue());
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return stringValueBuilder.toString();
}
Also used : ByteArraySegment(io.pravega.common.util.ByteArraySegment) TransactionData(io.pravega.segmentstore.storage.metadata.BaseMetadataStore.TransactionData) IOException(java.io.IOException)

Aggregations

TransactionData (io.pravega.segmentstore.storage.metadata.BaseMetadataStore.TransactionData)2 IOException (java.io.IOException)2 ByteArraySegment (io.pravega.common.util.ByteArraySegment)1 ByteBuffer (java.nio.ByteBuffer)1