otobuf.2.4.20.source-code.jprotobuf_classes_template.tpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jprotobuf Show documentation
Show all versions of jprotobuf Show documentation
A useful utility library for java programmer using google protobuf.
${package}
import java.io.Serializable;
import ${importPackage};
public class ${className} implements ${codecClassName}<${targetProxyClassName}>, Serializable {
public static final long serialVersionUID = 1L;
private ${descriptorClsName} descriptor;
public byte[] encode(${targetProxyClassName} t) throws IOException {
CodecOutputByteArray output = CodecOutputByteArray.get();
doWriteTo(t, output.getCodedOutputStream());
return output.getData();
}
public ${targetProxyClassName} decode(byte[] bb) throws IOException {
CodedInputStream input = CodedInputStream.newInstance(bb, 0, bb.length);
return readFrom(input);
}
public int size(${targetProxyClassName} t) throws IOException {
int size = 0;
${encodeFieldType} ${encodeFieldName} = null;
if (!CodedConstant.isNull(${encodeFieldGetter})) {
${encodeFieldName} = ${writeValueToField};
size += ${calcSize}
}
${checkNull}
return size;
}
public void doWriteTo(${targetProxyClassName} t, CodedOutputStream output)
throws IOException {
${encodeFieldType} ${encodeFieldName} = null;
if (!CodedConstant.isNull(${encodeFieldGetter})) {
${encodeFieldName} = ${writeValueToField};
${encodeWriteFieldValue}
}
}
public void writeTo(${targetProxyClassName} t, CodedOutputStream output)
throws IOException {
doWriteTo(t, output);
}
public ${targetProxyClassName} readFrom(CodedInputStream input) throws IOException {
${targetProxyClassName} ret = new ${targetProxyClassName}();
${initListMapFields}
${enumInitialize};
try {
boolean done = false;
Codec codec = null;
while (!done) {
int tag = input.readTag();
if (tag == 0) {
break;
}
if (tag == ${decodeOrder}) {
${objectDecodeExpress}
${decodeFieldSetValue}
${objectDecodeExpressSuffix}
${deocdeCheckNull}
continue;
}
${objectPackedDecodeExpress}
input.skipField(tag);
}
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
throw e;
} catch (java.io.IOException e) {
throw e;
}
return ret;
}
public com.google.protobuf.Descriptors.Descriptor getDescriptor() throws IOException {
if (this.descriptor != null) {
return this.descriptor;
}
com.google.protobuf.Descriptors.Descriptor descriptor =
CodedConstant.getDescriptor(${targetProxyClassName}.class);
return (this.descriptor = descriptor);
}
}