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

org.redkalex.convert.protobuf.ProtobufMapEncoder 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 ProtobufMapEncoder extends MapEncoder {

    private final boolean enumtostring;

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

    @Override
    protected void writeMemberValue(Writer out, EnMember member, K key, V value, boolean first) {
        ProtobufWriter tmp = new ProtobufWriter().configFieldFunc(out);
        if (member != null) out.writeFieldName(member);
        tmp.writeUInt32(1 << 3 | ProtobufFactory.wireType(keyEncoder.getType(), enumtostring));
        keyEncoder.convertTo(tmp, key);
        tmp.writeUInt32(2 << 3 | ProtobufFactory.wireType(valueEncoder.getType(), enumtostring));
        valueEncoder.convertTo(tmp, value);
        int length = tmp.count();
        ((ProtobufWriter) out).writeUInt32(length);
        ((ProtobufWriter) out).writeTo(tmp.toArray());
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy