use of io.pravega.segmentstore.server.containers.MetadataStore.SegmentInfo in project pravega by pravega.
the class ContainerMetadataSerializer method deserialize.
@Override
public String deserialize(ByteBuffer serializedValue) {
StringBuilder stringValueBuilder;
try {
SegmentInfo data = SERIALIZER.deserialize(new ByteArraySegment(serializedValue).getReader());
stringValueBuilder = new StringBuilder();
appendField(stringValueBuilder, SEGMENT_ID, String.valueOf(data.getSegmentId()));
SegmentProperties sp = data.getProperties();
SEGMENT_PROPERTIES_FIELD_MAP.forEach((name, f) -> appendField(stringValueBuilder, name, String.valueOf(f.apply(sp))));
sp.getAttributes().forEach((attributeId, attributeValue) -> appendField(stringValueBuilder, attributeId.toString(), attributeValue.toString()));
} catch (IOException e) {
throw new RuntimeException(e);
}
return stringValueBuilder.toString();
}
use of io.pravega.segmentstore.server.containers.MetadataStore.SegmentInfo in project pravega by pravega.
the class ContainerMetadataSerializer 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);
long segmentId = Long.parseLong(getAndRemoveIfExists(data, SEGMENT_ID));
// Use the map to build SegmentProperties. The fields/keys are removed after being queried to ensure attributes
// can be handled without interference. If the field/key queried does not exist we throw an IllegalArgumentException.
StreamSegmentInformation properties = StreamSegmentInformation.builder().name(getAndRemoveIfExists(data, SEGMENT_PROPERTIES_NAME)).sealed(Boolean.parseBoolean(getAndRemoveIfExists(data, SEGMENT_PROPERTIES_SEALED))).startOffset(Long.parseLong(getAndRemoveIfExists(data, SEGMENT_PROPERTIES_START_OFFSET))).length(Long.parseLong(getAndRemoveIfExists(data, SEGMENT_PROPERTIES_LENGTH))).attributes(getAttributes(data)).build();
SegmentInfo segment = SegmentInfo.builder().segmentId(segmentId).properties(properties).build();
buf = SERIALIZER.serialize(segment).asByteBuffer();
} catch (IOException e) {
throw new RuntimeException(e);
}
return buf;
}
Aggregations