
io.datakernel.crdt.CrdtDataSerializer Maven / Gradle / Ivy
/*
* Copyright (C) 2015-2018 SoftIndex LLC.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.datakernel.crdt;
import io.datakernel.serializer.BinarySerializer;
import io.datakernel.serializer.util.BinaryInput;
import io.datakernel.serializer.util.BinaryOutput;
public final class CrdtDataSerializer, S> implements BinarySerializer> {
private final BinarySerializer keySerializer;
private final BinarySerializer stateSerializer;
public CrdtDataSerializer(BinarySerializer keySerializer, BinarySerializer stateSerializer) {
this.keySerializer = keySerializer;
this.stateSerializer = stateSerializer;
}
public BinarySerializer getKeySerializer() {
return keySerializer;
}
public BinarySerializer getStateSerializer() {
return stateSerializer;
}
@Override
public void encode(BinaryOutput out, CrdtData item) {
keySerializer.encode(out, item.getKey());
stateSerializer.encode(out, item.getState());
}
@Override
public CrdtData decode(BinaryInput in) {
return new CrdtData<>(keySerializer.decode(in), stateSerializer.decode(in));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy