org.redkalex.convert.protobuf.ProtobufMapEncoder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of redkale-plugins Show documentation
Show all versions of redkale-plugins Show documentation
Redkale-Plugins -- java framework
/*
* 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