org.wildfly.clustering.marshalling.protostream.util.MapMarshaller Maven / Gradle / Ivy
/*
* Copyright The WildFly Authors
* SPDX-License-Identifier: Apache-2.0
*/
package org.wildfly.clustering.marshalling.protostream.util;
import java.io.IOException;
import java.util.AbstractMap;
import java.util.Map;
import java.util.function.Supplier;
import org.infinispan.protostream.descriptors.WireType;
import org.wildfly.clustering.marshalling.protostream.ProtoStreamReader;
/**
* Marshaller for a {@link Map}.
* @author Paul Ferraro
* @param the map type of this marshaller
*/
public class MapMarshaller> extends AbstractMapMarshaller {
private final Supplier factory;
@SuppressWarnings("unchecked")
public MapMarshaller(Supplier factory) {
super((Class) factory.get().getClass());
this.factory = factory;
}
@Override
public T readFrom(ProtoStreamReader reader) throws IOException {
T map = this.factory.get();
while (!reader.isAtEnd()) {
int tag = reader.readTag();
int index = WireType.getTagFieldNumber(tag);
switch (index) {
case ENTRY_INDEX:
Map.Entry