All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.redkalex.convert.protobuf.ProtobufMapDecoder Maven / Gradle / Ivy

There is a newer version: 2.7.7
Show newest version
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.redkalex.convert.protobuf;

import java.lang.reflect.Type;
import org.redkale.convert.*;

/**
 *
 * @author zhangjx
 * @param  K
 * @param  V
 */
public class ProtobufMapDecoder extends MapDecoder {

    private final boolean enumtostring;

    public ProtobufMapDecoder(ConvertFactory factory, Type type) {
        super(factory, type);
        this.enumtostring = ((ProtobufFactory) factory).enumtostring;
    }

    @Override
    protected Reader getEntryReader(Reader in, DeMember member, boolean first) {
        ProtobufReader reader = (ProtobufReader) in;
        if (!first && member != null) {
            int tag = reader.readTag();
            if (tag != member.getTag()) {
                reader.backTag(tag);
                return null;
            }
        }
        byte[] bs = reader.readByteArray();
        return new ProtobufReader(bs);
    }

    @Override
    protected K readKeyMember(Reader in, DeMember member, Decodeable decoder, boolean first) {
        ProtobufReader reader = (ProtobufReader) in;
        reader.readTag();
        return decoder.convertFrom(in);
    }

    @Override
    protected V readValueMember(Reader in, DeMember member, Decodeable decoder, boolean first) {
        ProtobufReader reader = (ProtobufReader) in;
        reader.readTag();
        return decoder.convertFrom(in);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy