From 94121da0f3cb703570347f5be6ef1d166df9cd05 Mon Sep 17 00:00:00 2001 From: redkale Date: Sat, 16 Sep 2023 14:44:52 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0ProtobufConvert?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/redkale/annotation/Scheduled.java | 13 +- .../org/redkale/convert/ConvertFactory.java | 36 +- .../protobuf/ProtobufArrayDecoder.java | 42 + .../protobuf/ProtobufArrayEncoder.java | 53 + .../protobuf/ProtobufByteBufferReader.java | 206 + .../protobuf/ProtobufByteBufferWriter.java | 147 + .../protobuf/ProtobufCollectionDecoder.java | 41 + .../protobuf/ProtobufCollectionEncoder.java | 54 + .../convert/protobuf/ProtobufConvert.java | 777 +++ .../protobuf/ProtobufConvertProvider.java | 28 + .../protobuf/ProtobufEnumSimpledCoder.java | 72 + .../convert/protobuf/ProtobufFactory.java | 340 ++ .../convert/protobuf/ProtobufMapDecoder.java | 53 + .../convert/protobuf/ProtobufMapEncoder.java | 38 + .../protobuf/ProtobufObjectDecoder.java | 71 + .../protobuf/ProtobufObjectEncoder.java | 35 + .../convert/protobuf/ProtobufReader.java | 456 ++ .../protobuf/ProtobufStreamDecoder.java | 41 + .../protobuf/ProtobufStreamEncoder.java | 52 + .../protobuf/ProtobufStreamReader.java | 52 + .../protobuf/ProtobufStreamWriter.java | 50 + .../convert/protobuf/ProtobufWriter.java | 638 +++ .../java/org/redkale/mq/MessageConsumer.java | 2 +- .../java/org/redkale/mq/MessageProducer.java | 21 +- .../java/org/redkale/source/ColumnValue.java | 4 + .../test/convert/protobuf/ArrayBean.java | 59 + .../convert/protobuf/PBCustMessage2Test.java | 231 + .../convert/protobuf/PBCustMessageTest.java | 204 + .../test/convert/protobuf/PSimpleBean.proto | 21 + .../protobuf/PSimpleBeanOuterClass.java | 2342 +++++++++ .../test/convert/protobuf/PTestBean.proto | 36 + .../convert/protobuf/PTestBeanOuterClass.java | 4539 +++++++++++++++++ .../test/convert/protobuf/SimpleBean.java | 105 + .../test/convert/protobuf/TestBean.java | 241 + 34 files changed, 11064 insertions(+), 36 deletions(-) create mode 100644 src/main/java/org/redkale/convert/protobuf/ProtobufArrayDecoder.java create mode 100644 src/main/java/org/redkale/convert/protobuf/ProtobufArrayEncoder.java create mode 100644 src/main/java/org/redkale/convert/protobuf/ProtobufByteBufferReader.java create mode 100644 src/main/java/org/redkale/convert/protobuf/ProtobufByteBufferWriter.java create mode 100644 src/main/java/org/redkale/convert/protobuf/ProtobufCollectionDecoder.java create mode 100644 src/main/java/org/redkale/convert/protobuf/ProtobufCollectionEncoder.java create mode 100644 src/main/java/org/redkale/convert/protobuf/ProtobufConvert.java create mode 100644 src/main/java/org/redkale/convert/protobuf/ProtobufConvertProvider.java create mode 100644 src/main/java/org/redkale/convert/protobuf/ProtobufEnumSimpledCoder.java create mode 100644 src/main/java/org/redkale/convert/protobuf/ProtobufFactory.java create mode 100644 src/main/java/org/redkale/convert/protobuf/ProtobufMapDecoder.java create mode 100644 src/main/java/org/redkale/convert/protobuf/ProtobufMapEncoder.java create mode 100644 src/main/java/org/redkale/convert/protobuf/ProtobufObjectDecoder.java create mode 100644 src/main/java/org/redkale/convert/protobuf/ProtobufObjectEncoder.java create mode 100644 src/main/java/org/redkale/convert/protobuf/ProtobufReader.java create mode 100644 src/main/java/org/redkale/convert/protobuf/ProtobufStreamDecoder.java create mode 100644 src/main/java/org/redkale/convert/protobuf/ProtobufStreamEncoder.java create mode 100644 src/main/java/org/redkale/convert/protobuf/ProtobufStreamReader.java create mode 100644 src/main/java/org/redkale/convert/protobuf/ProtobufStreamWriter.java create mode 100644 src/main/java/org/redkale/convert/protobuf/ProtobufWriter.java create mode 100644 src/test/java/org/redkale/test/convert/protobuf/ArrayBean.java create mode 100644 src/test/java/org/redkale/test/convert/protobuf/PBCustMessage2Test.java create mode 100644 src/test/java/org/redkale/test/convert/protobuf/PBCustMessageTest.java create mode 100644 src/test/java/org/redkale/test/convert/protobuf/PSimpleBean.proto create mode 100644 src/test/java/org/redkale/test/convert/protobuf/PSimpleBeanOuterClass.java create mode 100644 src/test/java/org/redkale/test/convert/protobuf/PTestBean.proto create mode 100644 src/test/java/org/redkale/test/convert/protobuf/PTestBeanOuterClass.java create mode 100644 src/test/java/org/redkale/test/convert/protobuf/SimpleBean.java create mode 100644 src/test/java/org/redkale/test/convert/protobuf/TestBean.java diff --git a/src/main/java/org/redkale/annotation/Scheduled.java b/src/main/java/org/redkale/annotation/Scheduled.java index 72aaa8b83..03ed8ebbd 100644 --- a/src/main/java/org/redkale/annotation/Scheduled.java +++ b/src/main/java/org/redkale/annotation/Scheduled.java @@ -23,17 +23,12 @@ public @interface Scheduled { String zone() default ""; - long fixedDelay() default -1; + String fixedDelay() default "-1"; - String fixedDelayString() default ""; + String fixedRate() default "-1"; - long fixedRate() default -1; - - String fixedRateString() default ""; - - long initialDelay() default -1; - - String initialDelayString() default ""; + String initialDelay() default "-1"; TimeUnit timeUnit() default TimeUnit.MILLISECONDS; + } diff --git a/src/main/java/org/redkale/convert/ConvertFactory.java b/src/main/java/org/redkale/convert/ConvertFactory.java index 09e4a89ce..a97c3d68e 100644 --- a/src/main/java/org/redkale/convert/ConvertFactory.java +++ b/src/main/java/org/redkale/convert/ConvertFactory.java @@ -21,6 +21,7 @@ import org.redkale.annotation.ConstructorParameters; import org.redkale.convert.bson.BsonConvert; import org.redkale.convert.ext.*; import org.redkale.convert.json.JsonConvert; +import org.redkale.convert.protobuf.ProtobufConvert; import org.redkale.util.*; /** @@ -36,10 +37,6 @@ import org.redkale.util.*; @SuppressWarnings("unchecked") public abstract class ConvertFactory { - private static final AtomicBoolean loaderInited = new AtomicBoolean(); - - private static Convert defProtobufConvert; - private final ConvertFactory parent; protected Convert convert; @@ -212,32 +209,27 @@ public abstract class ConvertFactory { } public static Convert findConvert(ConvertType type) { - if (type == null) { - return null; - } + Objects.requireNonNull(type); if (type == ConvertType.JSON) { return JsonConvert.root(); } if (type == ConvertType.BSON) { return BsonConvert.root(); } - if (loaderInited.get()) { - if (type == ConvertType.PROTOBUF) { - return defProtobufConvert; + if (type == ConvertType.PROTOBUF) { + return ProtobufConvert.root(); + } + + Iterator it = ServiceLoader.load(ConvertProvider.class).iterator(); + RedkaleClassLoader.putServiceLoader(ConvertProvider.class); + while (it.hasNext()) { + ConvertProvider cl = it.next(); + RedkaleClassLoader.putReflectionPublicConstructors(cl.getClass(), cl.getClass().getName()); + if (cl.type() == ConvertType.PROTOBUF) { + return cl.convert(); } } - if (loaderInited.compareAndSet(false, true)) { - Iterator it = ServiceLoader.load(ConvertProvider.class).iterator(); - RedkaleClassLoader.putServiceLoader(ConvertProvider.class); - while (it.hasNext()) { - ConvertProvider cl = it.next(); - RedkaleClassLoader.putReflectionPublicConstructors(cl.getClass(), cl.getClass().getName()); - if (cl.type() == ConvertType.PROTOBUF) { - defProtobufConvert = cl.convert(); - } - } - } - return type == ConvertType.PROTOBUF ? defProtobufConvert : null; + return null; } protected static int getSystemPropertyInt(String key, String parentkey, boolean defvalue, int feature) { diff --git a/src/main/java/org/redkale/convert/protobuf/ProtobufArrayDecoder.java b/src/main/java/org/redkale/convert/protobuf/ProtobufArrayDecoder.java new file mode 100644 index 000000000..28cc04ac8 --- /dev/null +++ b/src/main/java/org/redkale/convert/protobuf/ProtobufArrayDecoder.java @@ -0,0 +1,42 @@ +/* + * 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.redkale.convert.protobuf; + +import java.lang.reflect.Type; +import java.util.concurrent.atomic.*; +import org.redkale.convert.*; + +/** + * + * @author zhangjx + * @param T + */ +public class ProtobufArrayDecoder extends ArrayDecoder { + + protected final boolean simple; + + private final boolean string; + + private final boolean enumtostring; + + public ProtobufArrayDecoder(ConvertFactory factory, Type type) { + super(factory, type); + this.enumtostring = ((ProtobufFactory) factory).enumtostring; + Type comtype = this.getComponentType(); + this.string = String.class == comtype; + this.simple = Boolean.class == comtype || Short.class == comtype + || Character.class == comtype || Integer.class == comtype || Float.class == comtype + || Long.class == comtype || Double.class == comtype + || AtomicInteger.class == comtype || AtomicLong.class == comtype; + } + + @Override + protected Reader getItemReader(Reader in, DeMember member, boolean first) { + if (simple) return in; + return ProtobufFactory.getItemReader(string, simple, in, member, enumtostring, first); + } + +} diff --git a/src/main/java/org/redkale/convert/protobuf/ProtobufArrayEncoder.java b/src/main/java/org/redkale/convert/protobuf/ProtobufArrayEncoder.java new file mode 100644 index 000000000..fcfa056b6 --- /dev/null +++ b/src/main/java/org/redkale/convert/protobuf/ProtobufArrayEncoder.java @@ -0,0 +1,53 @@ +/* + * 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.redkale.convert.protobuf; + +import java.lang.reflect.Type; +import java.util.concurrent.atomic.*; +import org.redkale.convert.*; + +/** + * + * @author zhangjx + * @param T + */ +public class ProtobufArrayEncoder extends ArrayEncoder { + + protected final boolean simple; + + public ProtobufArrayEncoder(ConvertFactory factory, Type type) { + super(factory, type); + Type comtype = this.getComponentType(); + this.simple = Boolean.class == comtype || Short.class == comtype + || Character.class == comtype || Integer.class == comtype || Float.class == comtype + || Long.class == comtype || Double.class == comtype + || AtomicInteger.class == comtype || AtomicLong.class == comtype; + } + + @Override + protected void writeMemberValue(Writer out, EnMember member, Encodeable encoder, Object item, int index) { + if (simple) { + if (item == null) { + ((ProtobufWriter) out).writeUInt32(0); + } else { + componentEncoder.convertTo(out, item); + } + return; + } + if (member != null) out.writeFieldName(member); + if (item == null) { + ((ProtobufWriter) out).writeUInt32(0); + } else if (item instanceof CharSequence) { + encoder.convertTo(out, item); + } else { + ProtobufWriter tmp = new ProtobufWriter().configFieldFunc(out); + encoder.convertTo(tmp, item); + int length = tmp.count(); + ((ProtobufWriter) out).writeUInt32(length); + ((ProtobufWriter) out).writeTo(tmp.toArray()); + } + } +} diff --git a/src/main/java/org/redkale/convert/protobuf/ProtobufByteBufferReader.java b/src/main/java/org/redkale/convert/protobuf/ProtobufByteBufferReader.java new file mode 100644 index 000000000..e4619394c --- /dev/null +++ b/src/main/java/org/redkale/convert/protobuf/ProtobufByteBufferReader.java @@ -0,0 +1,206 @@ +/* + * 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.redkale.convert.protobuf; + +import java.nio.ByteBuffer; +import org.redkale.convert.*; + +/** + * + * @author zhangjx + */ +public class ProtobufByteBufferReader extends ProtobufReader { + + private ByteBuffer[] buffers; + + private int currentIndex = 0; + + private ByteBuffer currentBuffer; + + protected ConvertMask mask; + + protected ProtobufByteBufferReader(ConvertMask mask, ByteBuffer... buffers) { + this.mask = mask; + this.buffers = buffers; + if (buffers != null && buffers.length > 0) this.currentBuffer = buffers[currentIndex]; + } + + @Override + protected boolean recycle() { + super.recycle(); // this.position 初始化值为-1 + this.currentIndex = 0; + this.currentBuffer = null; + this.buffers = null; + this.mask = null; + return false; + } + + @Override + protected byte currentByte() { + return mask == null ? currentBuffer.get(currentBuffer.position()) : mask.unmask(currentBuffer.get(currentBuffer.position())); + } + + protected byte nextByte() { + if (this.currentBuffer.hasRemaining()) { + this.position++; + return mask == null ? this.currentBuffer.get() : mask.unmask(this.currentBuffer.get()); + } + for (;;) { + this.currentBuffer = this.buffers[++this.currentIndex]; + if (this.currentBuffer.hasRemaining()) { + this.position++; + return mask == null ? this.currentBuffer.get() : mask.unmask(this.currentBuffer.get()); + } + } + } +// +// //------------------------------------------------------------ +// /** +// * 判断对象是否存在下一个属性或者数组是否存在下一个元素 +// * +// * @param startPosition 起始位置 +// * @param contentLength 内容大小, 不确定的传-1 +// * +// * @return 是否存在 +// */ +// @Override +// public boolean hasNext(int startPosition, int contentLength) { +// //("-------------: " + startPosition + ", " + contentLength + ", " + this.position); +// if (startPosition >= 0 && contentLength >= 0) { +// return (this.position) < (startPosition + contentLength); +// } +// return (this.position + 1) < this.content.length; +// } +// +// @Override +// public byte[] readByteArray() { +// final int size = readRawVarint32(); +// byte[] bs = new byte[size]; +// System.arraycopy(content, position + 1, bs, 0, size); +// position += size; +// return bs; +// } +// +// protected int readRawVarint32() { //readUInt32 +// fastpath: +// { +// int tempPos = this.position; +// if ((tempPos + 1) == content.length) break fastpath; +// +// int x; +// if ((x = content[++tempPos]) >= 0) { +// this.position = tempPos; +// return x; +// } else if (content.length - (tempPos + 1) < 9) { +// break fastpath; +// } else if ((x ^= (content[++tempPos] << 7)) < 0) { +// x ^= (~0 << 7); +// } else if ((x ^= (content[++tempPos] << 14)) >= 0) { +// x ^= (~0 << 7) ^ (~0 << 14); +// } else if ((x ^= (content[++tempPos] << 21)) < 0) { +// x ^= (~0 << 7) ^ (~0 << 14) ^ (~0 << 21); +// } else { +// int y = content[++tempPos]; +// x ^= y << 28; +// x ^= (~0 << 7) ^ (~0 << 14) ^ (~0 << 21) ^ (~0 << 28); +// if (y < 0 +// && content[++tempPos] < 0 +// && content[++tempPos] < 0 +// && content[++tempPos] < 0 +// && content[++tempPos] < 0 +// && content[++tempPos] < 0) { +// break fastpath; // Will throw malformedVarint() +// } +// } +// this.position = tempPos; +// return x; +// } +// return (int) readRawVarint64SlowPath(); +// } +// +// protected long readRawVarint64() { +// fastpath: +// { +// int tempPos = this.position; +// if ((tempPos + 1) == content.length) break fastpath; +// +// long x; +// int y; +// if ((y = content[++tempPos]) >= 0) { +// this.position = tempPos; +// return y; +// } else if (content.length - (tempPos + 1) < 9) { +// break fastpath; +// } else if ((y ^= (content[++tempPos] << 7)) < 0) { +// x = y ^ (~0 << 7); +// } else if ((y ^= (content[++tempPos] << 14)) >= 0) { +// x = y ^ ((~0 << 7) ^ (~0 << 14)); +// } else if ((y ^= (content[++tempPos] << 21)) < 0) { +// x = y ^ ((~0 << 7) ^ (~0 << 14) ^ (~0 << 21)); +// } else if ((x = y ^ ((long) content[++tempPos] << 28)) >= 0L) { +// x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28); +// } else if ((x ^= ((long) content[++tempPos] << 35)) < 0L) { +// x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28) ^ (~0L << 35); +// } else if ((x ^= ((long) content[++tempPos] << 42)) >= 0L) { +// x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28) ^ (~0L << 35) ^ (~0L << 42); +// } else if ((x ^= ((long) content[++tempPos] << 49)) < 0L) { +// x ^= (~0L << 7) +// ^ (~0L << 14) +// ^ (~0L << 21) +// ^ (~0L << 28) +// ^ (~0L << 35) +// ^ (~0L << 42) +// ^ (~0L << 49); +// } else { +// x ^= ((long) content[++tempPos] << 56); +// x ^= (~0L << 7) +// ^ (~0L << 14) +// ^ (~0L << 21) +// ^ (~0L << 28) +// ^ (~0L << 35) +// ^ (~0L << 42) +// ^ (~0L << 49) +// ^ (~0L << 56); +// if (x < 0L) { +// if (content[++tempPos] < 0L) { +// break fastpath; // Will throw malformedVarint() +// } +// } +// } +// this.position = tempPos; +// return x; +// } +// return readRawVarint64SlowPath(); +// } +// +// protected long readRawVarint64SlowPath() { +// long result = 0; +// for (int shift = 0; shift < 64; shift += 7) { +// final byte b = content[++this.position]; +// result |= (long) (b & 0x7F) << shift; +// if ((b & 0x80) == 0) return result; +// } +// throw new ConvertException("readRawVarint64SlowPath error"); +// } +// +// protected int readRawLittleEndian32() { +// return ((content[++this.position] & 0xff) +// | ((content[++this.position] & 0xff) << 8) +// | ((content[++this.position] & 0xff) << 16) +// | ((content[++this.position] & 0xff) << 24)); +// } +// +// protected long readRawLittleEndian64() { +// return ((content[++this.position] & 0xffL) +// | ((content[++this.position] & 0xffL) << 8) +// | ((content[++this.position] & 0xffL) << 16) +// | ((content[++this.position] & 0xffL) << 24) +// | ((content[++this.position] & 0xffL) << 32) +// | ((content[++this.position] & 0xffL) << 40) +// | ((content[++this.position] & 0xffL) << 48) +// | ((content[++this.position] & 0xffL) << 56)); +// } +} diff --git a/src/main/java/org/redkale/convert/protobuf/ProtobufByteBufferWriter.java b/src/main/java/org/redkale/convert/protobuf/ProtobufByteBufferWriter.java new file mode 100644 index 000000000..5d99d83ec --- /dev/null +++ b/src/main/java/org/redkale/convert/protobuf/ProtobufByteBufferWriter.java @@ -0,0 +1,147 @@ +/* + * 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.redkale.convert.protobuf; + +import java.nio.ByteBuffer; +import java.util.function.Supplier; +import org.redkale.util.Utility; + +/** + * + * @author zhangjx + */ +public class ProtobufByteBufferWriter extends ProtobufWriter { + + private final Supplier supplier; + + private ByteBuffer[] buffers; + + private int index; + + public ProtobufByteBufferWriter(int features, boolean enumtostring, Supplier supplier) { + super((byte[]) null); + this.features = features; + this.enumtostring = enumtostring; + this.supplier = supplier; + } + + @Override + protected boolean recycle() { + super.recycle(); + this.buffers = null; + this.index = 0; + return false; + } + + @Override + public ByteBuffer[] toBuffers() { + if (buffers == null) { + return new ByteBuffer[0]; + } + for (int i = index; i < this.buffers.length; i++) { + ByteBuffer buf = this.buffers[i]; + if (buf.position() != 0) { + buf.flip(); + } + } + return this.buffers; + } + + @Override + public byte[] toArray() { + if (buffers == null) { + return new byte[0]; + } + int pos = 0; + byte[] bytes = new byte[this.count]; + for (ByteBuffer buf : toBuffers()) { + int r = buf.remaining(); + buf.get(bytes, pos, r); + buf.flip(); + pos += r; + } + return bytes; + } + + @Override + public String toString() { + return this.getClass().getSimpleName() + "[count=" + this.count + "]"; + } + + @Override + protected int expand(final int byteLength) { + if (this.buffers == null) { + this.index = 0; + this.buffers = new ByteBuffer[]{supplier.get()}; + } + ByteBuffer buffer = this.buffers[index]; + if (!buffer.hasRemaining()) { + buffer.flip(); + buffer = supplier.get(); + this.buffers = Utility.append(this.buffers, buffer); + this.index++; + } + int len = buffer.remaining(); + int size = 0; + while (len < byteLength) { + buffer = supplier.get(); + this.buffers = Utility.append(this.buffers, buffer); + len += buffer.remaining(); + size++; + } + return size; + } + + @Override + public void writeTo(final byte[] chs, final int start, final int len) { + if (expand(len) == 0) { + this.buffers[index].put(chs, start, len); + } else { + ByteBuffer buffer = this.buffers[index]; + final int end = start + len; + int remain = len; //还剩多少没有写 + while (remain > 0) { + final int br = buffer.remaining(); + if (remain > br) { //一个buffer写不完 + buffer.put(chs, end - remain, br); + buffer = nextByteBuffer(); + remain -= br; + } else { + buffer.put(chs, end - remain, remain); + remain = 0; + } + } + } + this.count += len; + } + + private ByteBuffer nextByteBuffer() { + this.buffers[this.index].flip(); + return this.buffers[++this.index]; + } + + @Override + public void writeTo(final byte ch) { + expand(1); + this.buffers[index].put(ch); + count++; + } + + @Override + public byte[] content() { + throw new UnsupportedOperationException("Not supported yet."); //无需实现 + } + + @Override + public int offset() { + throw new UnsupportedOperationException("Not supported yet.");//无需实现 + } + + @Override + public int length() { + throw new UnsupportedOperationException("Not supported yet."); //无需实现 + } +} diff --git a/src/main/java/org/redkale/convert/protobuf/ProtobufCollectionDecoder.java b/src/main/java/org/redkale/convert/protobuf/ProtobufCollectionDecoder.java new file mode 100644 index 000000000..20551f0a3 --- /dev/null +++ b/src/main/java/org/redkale/convert/protobuf/ProtobufCollectionDecoder.java @@ -0,0 +1,41 @@ +/* + * 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.redkale.convert.protobuf; + +import java.lang.reflect.Type; +import java.util.concurrent.atomic.*; +import org.redkale.convert.*; + +/** + * + * @author zhangjx + * @param T + */ +public class ProtobufCollectionDecoder extends CollectionDecoder { + + protected final boolean simple; + + private final boolean string; + + private final boolean enumtostring; + + public ProtobufCollectionDecoder(ConvertFactory factory, Type type) { + super(factory, type); + this.enumtostring = ((ProtobufFactory) factory).enumtostring; + Type comtype = this.getComponentType(); + this.string = String.class == comtype; + this.simple = Boolean.class == comtype || Short.class == comtype + || Character.class == comtype || Integer.class == comtype || Float.class == comtype + || Long.class == comtype || Double.class == comtype + || AtomicInteger.class == comtype || AtomicLong.class == comtype; + } + + @Override + protected Reader getItemReader(Reader in, DeMember member, boolean first) { + if (simple) return in; + return ProtobufFactory.getItemReader(string, simple, in, member, enumtostring, first); + } +} diff --git a/src/main/java/org/redkale/convert/protobuf/ProtobufCollectionEncoder.java b/src/main/java/org/redkale/convert/protobuf/ProtobufCollectionEncoder.java new file mode 100644 index 000000000..53fe9b314 --- /dev/null +++ b/src/main/java/org/redkale/convert/protobuf/ProtobufCollectionEncoder.java @@ -0,0 +1,54 @@ +/* + * 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.redkale.convert.protobuf; + +import java.lang.reflect.Type; +import java.util.concurrent.atomic.*; +import org.redkale.convert.*; + +/** + * + * @author zhangjx + * @param T + */ +public class ProtobufCollectionEncoder extends CollectionEncoder { + + protected final boolean simple; + + + public ProtobufCollectionEncoder(ConvertFactory factory, Type type) { + super(factory, type); + Type comtype = this.getComponentType(); + this.simple = Boolean.class == comtype || Short.class == comtype + || Character.class == comtype || Integer.class == comtype || Float.class == comtype + || Long.class == comtype || Double.class == comtype + || AtomicInteger.class == comtype || AtomicLong.class == comtype; + } + + @Override + protected void writeMemberValue(Writer out, EnMember member, Object item, boolean first) { + if (simple) { + if (item == null) { + ((ProtobufWriter) out).writeUInt32(0); + } else { + componentEncoder.convertTo(out, item); + } + return; + } + if (member != null) out.writeFieldName(member); + if (item == null) { + ((ProtobufWriter) out).writeUInt32(0); + } else if (item instanceof CharSequence) { + componentEncoder.convertTo(out, item); + } else { + ProtobufWriter tmp = new ProtobufWriter().configFieldFunc(out); + componentEncoder.convertTo(tmp, item); + int length = tmp.count(); + ((ProtobufWriter) out).writeUInt32(length); + ((ProtobufWriter) out).writeTo(tmp.toArray()); + } + } +} diff --git a/src/main/java/org/redkale/convert/protobuf/ProtobufConvert.java b/src/main/java/org/redkale/convert/protobuf/ProtobufConvert.java new file mode 100644 index 000000000..f6d1e6c3e --- /dev/null +++ b/src/main/java/org/redkale/convert/protobuf/ProtobufConvert.java @@ -0,0 +1,777 @@ +/* + * 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.redkale.convert.protobuf; + +import java.io.*; +import java.lang.reflect.*; +import java.nio.ByteBuffer; +import java.util.*; +import java.util.function.*; +import org.redkale.convert.*; +import org.redkale.convert.ext.StringArraySimpledCoder; +import org.redkale.util.*; + +/** + * protobuf的Convert实现
+ * 注意:
+ * 1、 只实现proto3版本
+ * 2、 int统一使用sint32, long统一使用sint64
+ * 3、 集合统一 packed repeated
+ * 4、 目前使用的基础数据类型为:bool、sint32、sint64、float、double、bytes、string、map、Any
+ * + * @author zhangjx + */ +public class ProtobufConvert extends BinaryConvert { + + private final ThreadLocal writerPool = ThreadLocal.withInitial(ProtobufWriter::new); + + private final Consumer writerConsumer = w -> offerWriter(w); + + private final ThreadLocal readerPool = ThreadLocal.withInitial(ProtobufReader::new); + + private Encodeable lastConvertEncodeable; + + private Decodeable lastConvertDecodeable; + + protected ProtobufConvert(ConvertFactory factory, int features) { + super(factory, features); + } + + @Override + public ProtobufFactory getFactory() { + return (ProtobufFactory) factory; + } + + public static ProtobufConvert root() { + return ProtobufFactory.root().getConvert(); + } + + @Override + public ProtobufConvert newConvert(final BiFunction objFieldFunc) { + return newConvert(objFieldFunc, null, null); + } + + @Override + public ProtobufConvert newConvert(final BiFunction objFieldFunc, BiFunction mapFieldFunc) { + return newConvert(objFieldFunc, mapFieldFunc, null); + } + + @Override + public ProtobufConvert newConvert(final BiFunction objFieldFunc, Function objExtFunc) { + return newConvert(objFieldFunc, null, objExtFunc); + } + + @Override + public ProtobufConvert newConvert(final BiFunction fieldFunc, BiFunction mapFieldFunc, Function objExtFunc) { + return new ProtobufConvert(getFactory(), features) { + @Override + protected S configWrite(S writer) { + super.configWrite(writer); + return fieldFunc(writer, fieldFunc, mapFieldFunc, objExtFunc); + } + }; + } + + @Override + public ProtobufReader pollReader() { + ProtobufReader reader = readerPool.get(); + if (reader == null) { + reader = new ProtobufReader(); + } else { + readerPool.set(null); + } + return reader; + } + + @Override + public void offerReader(final ProtobufReader in) { + if (in != null) { + in.recycle(); + readerPool.set(in); + } + } + + //------------------------------ writer ----------------------------------------------------------- + @Override + protected S configWrite(S writer) { + writer.initOffset = writer.count; + return writer; + } + + public ProtobufByteBufferWriter pollProtobufWriter(final Supplier supplier) { + return configWrite(new ProtobufByteBufferWriter(features, ((ProtobufFactory) factory).enumtostring, supplier)); + } + + public ProtobufWriter pollProtobufWriter(final OutputStream out) { + return configWrite(new ProtobufStreamWriter(features, ((ProtobufFactory) factory).enumtostring, out)); + } + + @Override + public ProtobufWriter pollWriter() { + ProtobufWriter writer = writerPool.get(); + if (writer == null) { + writer = new ProtobufWriter(); + } else { + writerPool.set(null); + } + return configWrite(writer.withFeatures(features).enumtostring(((ProtobufFactory) factory).enumtostring)); + } + + @Override + public void offerWriter(final ProtobufWriter out) { + if (out != null) { + out.recycle(); + writerPool.set(out); + } + } + + /** + * 请求参数的类型 + * + * @param type 请求参数的类型 + * + * @return String + */ + public String getJsonDecodeDescriptor(Type type) { + StringBuilder sb = new StringBuilder(); + defineJsonDecodeDescriptor(null, new ArrayList<>(), type, sb, "", null); + return sb.toString(); + } + + public String getJsonDecodeDescriptor(Type type, BiFunction func) { + StringBuilder sb = new StringBuilder(); + defineJsonDecodeDescriptor(null, new ArrayList<>(), type, sb, "", func); + return sb.toString(); + } + + protected String getJsonDecodeDescriptor(Type parent, List list, Type type, BiFunction func) { + StringBuilder sb = new StringBuilder(); + defineJsonDecodeDescriptor(parent, list, type, sb, "", func); + return sb.toString(); + } + + protected void defineJsonDecodeDescriptor(Type parent, List list, Type type, StringBuilder sb, String prefix, BiFunction excludeFunc) { + Decodeable decoder = factory.loadDecoder(type); + boolean dot = sb.length() > 0; + if (decoder instanceof ObjectDecoder) { + if (sb.length() > 0) { + if (list.contains(parent + "" + defineTypeName(type))) { + return; + } + list.add(parent + "" + defineTypeName(type)); + sb.append(prefix).append("\"message ").append(defineTypeName(type)).append("\" : {\r\n"); + } else { + sb.append("{\r\n"); + } + DeMember[] ems = ((ObjectDecoder) decoder).getMembers(); + List members = new ArrayList<>(); + for (DeMember member : ems) { + if (excludeFunc != null && excludeFunc.apply(type, member)) { + continue; + } + members.add(member); + } + for (DeMember member : members) { + Type mtype = member.getDecoder().getType(); + if (!(mtype instanceof Class)) { + if (mtype instanceof ParameterizedType) { + final ParameterizedType pt = (ParameterizedType) mtype; + if (pt.getActualTypeArguments().length == 1 && (pt.getActualTypeArguments()[0] instanceof Class)) { + defineJsonDecodeDescriptor(parent, list, mtype, sb, prefix + " ", excludeFunc); + } + } else if (mtype instanceof GenericArrayType) { + final GenericArrayType gt = (GenericArrayType) mtype; + if (!gt.getGenericComponentType().toString().startsWith("java") + && !gt.getGenericComponentType().toString().startsWith("class java") + && gt.getGenericComponentType().toString().indexOf('.') > 0) { + defineJsonDecodeDescriptor(parent, list, gt.getGenericComponentType(), sb, prefix + " ", excludeFunc); + } + } + continue; + } + Class mclz = (Class) member.getDecoder().getType(); + if (!mclz.isArray() && !mclz.isEnum() && !mclz.isPrimitive() && !mclz.getName().startsWith("java")) { + defineJsonDecodeDescriptor(parent, list, mclz, sb, prefix + " ", excludeFunc); + } else if (mclz.isArray() && !mclz.getComponentType().getName().startsWith("java") + && !mclz.getComponentType().isPrimitive() && !mclz.getComponentType().isArray() + && !mclz.getComponentType().getName().equals("boolean") && !mclz.getComponentType().getName().equals("byte") + && !mclz.getComponentType().getName().equals("char") && !mclz.getComponentType().getName().equals("short") + && !mclz.getComponentType().getName().equals("int") && !mclz.getComponentType().getName().equals("long") + && !mclz.getComponentType().getName().equals("float") && !mclz.getComponentType().getName().equals("double")) { + defineJsonDecodeDescriptor(parent, list, mclz.getComponentType(), sb, prefix + " ", excludeFunc); + } + } + for (int i = 0; i < members.size(); i++) { + DeMember member = members.get(i); + try { + sb.append(prefix).append(" \"").append(ProtobufFactory.wireTypeString(member.getDecoder().getType(), ((ProtobufFactory) factory).enumtostring)) + .append(" ").append(member.getAttribute().field()).append("\" : ").append(member.getPosition()).append(i == members.size() - 1 ? "\r\n" : ",\r\n"); + } catch (RuntimeException e) { + System.err.println("member = " + member); + throw e; + } + } + sb.append(prefix).append(dot ? "}," : "}").append("\r\n"); + } else if ((!(type instanceof Class) || !((Class) type).isArray() || !((Class) type).getComponentType().getName().startsWith("java")) && (decoder instanceof ProtobufArrayDecoder || decoder instanceof ProtobufCollectionDecoder)) { + Type mtype = decoder instanceof ProtobufArrayDecoder ? ((ProtobufArrayDecoder) decoder).getComponentType() : ((ProtobufCollectionDecoder) decoder).getComponentType(); + if (!mtype.toString().startsWith("java") && !mtype.toString().startsWith("class java") && mtype.toString().indexOf('.') > 0) { + defineJsonDecodeDescriptor(parent, list, mtype, sb, prefix, excludeFunc); + } + } else if (sb.length() == 0) { + if (decoder instanceof SimpledCoder + || decoder instanceof StringArraySimpledCoder + || (decoder instanceof ProtobufArrayDecoder && ((ProtobufArrayDecoder) decoder).getComponentDecoder() instanceof SimpledCoder) + || (decoder instanceof ProtobufCollectionDecoder && ((ProtobufCollectionDecoder) decoder).getComponentDecoder() instanceof SimpledCoder)) { + sb.append(prefix).append("{\r\n"); + sb.append(prefix).append(" \"").append(ProtobufFactory.wireTypeString(type, ((ProtobufFactory) factory).enumtostring)).append(" 0\" : 0\r\n"); + sb.append(prefix).append(dot ? "}," : "}").append("\r\n"); + } else if (decoder instanceof MapDecoder) { + sb.append(prefix).append("{\r\n"); + sb.append(prefix).append(" \"").append(ProtobufFactory.wireTypeString(type, ((ProtobufFactory) factory).enumtostring)).append(" 0\" : 0\r\n"); + sb.append(prefix).append(dot ? "}," : "}").append("\r\n"); + } else { + throw new ConvertException("Not support type (" + type + ")"); + } + } else { + throw new ConvertException("Not support the type (" + type + ")"); + } + } + + /** + * 输出结果的类型 + * + * @param type 输出结果的类型 + * + * @return String + */ + public String getJsonEncodeDescriptor(Type type) { + StringBuilder sb = new StringBuilder(); + defineJsonEncodeDescriptor(null, new ArrayList<>(), type, sb, "", null); + return sb.toString(); + } + + public String getJsonEncodeDescriptor(Type type, BiFunction func) { + StringBuilder sb = new StringBuilder(); + defineJsonEncodeDescriptor(null, new ArrayList<>(), type, sb, "", func); + return sb.toString(); + } + + protected String getJsonEncodeDescriptor(Type parent, List list, Type type, BiFunction func) { + StringBuilder sb = new StringBuilder(); + defineJsonEncodeDescriptor(parent, list, type, sb, "", func); + return sb.toString(); + } + + protected void defineJsonEncodeDescriptor(Type parent, List list, Type type, StringBuilder sb, String prefix, BiFunction excludeFunc) { + Encodeable encoder = factory.loadEncoder(type); + boolean dot = sb.length() > 0; + if (encoder instanceof ObjectEncoder) { + if (sb.length() > 0) { + if (list.contains(parent + "" + defineTypeName(type))) { + return; + } + list.add(parent + "" + defineTypeName(type)); + sb.append(prefix).append("\"message ").append(defineTypeName(type)).append("\" : {\r\n"); + } else { + sb.append("{\r\n"); + } + EnMember[] ems = ((ObjectEncoder) encoder).getMembers(); + List members = new ArrayList<>(); + for (EnMember member : ems) { + if (excludeFunc != null && excludeFunc.apply(type, member)) { + continue; + } + members.add(member); + } + for (EnMember member : members) { + Type mtype = member.getEncoder().getType(); + if (!(mtype instanceof Class)) { + if (mtype instanceof ParameterizedType) { + final ParameterizedType pt = (ParameterizedType) mtype; + if (pt.getActualTypeArguments().length == 1 && (pt.getActualTypeArguments()[0] instanceof Class)) { + defineJsonEncodeDescriptor(parent, list, mtype, sb, prefix + " ", excludeFunc); + } + } else if (mtype instanceof GenericArrayType) { + final GenericArrayType gt = (GenericArrayType) mtype; + if (!gt.getGenericComponentType().toString().startsWith("java") + && !gt.getGenericComponentType().toString().startsWith("class java") + && gt.getGenericComponentType().toString().indexOf('.') > 0) { + defineJsonEncodeDescriptor(parent, list, gt.getGenericComponentType(), sb, prefix + " ", excludeFunc); + } + } + continue; + } + Class mclz = (Class) member.getEncoder().getType(); + if (!mclz.isArray() && !mclz.isEnum() && !mclz.getName().startsWith("java")) { + defineJsonEncodeDescriptor(parent, list, mclz, sb, prefix + " ", excludeFunc); + } else if (mclz.isArray() && !mclz.getComponentType().getName().startsWith("java") + && !mclz.getComponentType().getName().equals("boolean") && !mclz.getComponentType().getName().equals("byte") + && !mclz.getComponentType().getName().equals("char") && !mclz.getComponentType().getName().equals("short") + && !mclz.getComponentType().getName().equals("int") && !mclz.getComponentType().getName().equals("long") + && !mclz.getComponentType().getName().equals("float") && !mclz.getComponentType().getName().equals("double")) { + defineJsonEncodeDescriptor(parent, list, mclz.getComponentType(), sb, prefix + " ", excludeFunc); + } + } + for (int i = 0; i < members.size(); i++) { + EnMember member = members.get(i); + try { + sb.append(prefix).append(" \"").append(ProtobufFactory.wireTypeString(member.getEncoder().getType(), ((ProtobufFactory) factory).enumtostring)) + .append(" ").append(member.getAttribute().field()).append("\" : ").append(member.getPosition()).append(i == members.size() - 1 ? "\r\n" : ",\r\n"); + } catch (RuntimeException e) { + System.err.println("member = " + member); + throw e; + } + } + sb.append(prefix).append(dot ? "}," : "}").append("\r\n"); + } else if (encoder instanceof ProtobufArrayEncoder || encoder instanceof ProtobufCollectionEncoder) { + Type mtype = encoder instanceof ProtobufArrayEncoder ? ((ProtobufArrayEncoder) encoder).getComponentType() : ((ProtobufCollectionEncoder) encoder).getComponentType(); + if (!mtype.toString().startsWith("java") && !mtype.toString().startsWith("class java") && mtype.toString().indexOf('.') > 0) { + defineJsonEncodeDescriptor(parent, list, mtype, sb, prefix, excludeFunc); + } + } else if (sb.length() == 0) { + if (encoder instanceof SimpledCoder + || (encoder instanceof ProtobufArrayEncoder && ((ProtobufArrayEncoder) encoder).getComponentEncoder() instanceof SimpledCoder) + || (encoder instanceof ProtobufCollectionEncoder && ((ProtobufCollectionEncoder) encoder).getComponentEncoder() instanceof SimpledCoder)) { + sb.append(prefix).append("{\r\n"); + sb.append(prefix).append(" \"").append(ProtobufFactory.wireTypeString(type, ((ProtobufFactory) factory).enumtostring)).append(" 0\" : 0\r\n"); + sb.append(prefix).append(dot ? "}," : "}").append("\r\n"); + } else if (encoder instanceof MapEncoder) { + sb.append(prefix).append("{\r\n"); + sb.append(prefix).append(" \"").append(ProtobufFactory.wireTypeString(type, ((ProtobufFactory) factory).enumtostring)).append(" 0\" : 0\r\n"); + sb.append(prefix).append(dot ? "}," : "}").append("\r\n"); + } else { + throw new ConvertException("Not support the type (" + type + ")"); + } + } else { + throw new ConvertException("Not support the type (" + type + ")"); + } + } + + public String getProtoDescriptor(Type type) { + StringBuilder sb = new StringBuilder(); + Class clazz = TypeToken.typeToClass(type); + sb.append("//java ").append(clazz.isArray() ? (clazz.getComponentType().getName() + "[]") : clazz.getName()).append("\r\n\r\n"); + if (type instanceof Class) { + sb.append("option java_package = \"").append(clazz.getPackage().getName()).append("\";\r\n\r\n"); + } + sb.append("syntax = \"proto3\";\r\n\r\n"); + //defineProtoDescriptor(type, sb, ""); + defineProtoDescriptor(null, new ArrayList<>(), type, sb, "", null); + return sb.toString(); + } + + protected String defineProtoDescriptor(Type parent, List list, Type type, BiFunction func) { + StringBuilder sb = new StringBuilder(); + defineProtoDescriptor(parent, list, type, sb, "", func); + return sb.toString(); + } + + protected void defineProtoDescriptor(Type parent, List list, Type type, StringBuilder sb, String prefix, BiFunction excludeFunc) { + Encodeable encoder = factory.loadEncoder(type); + if (encoder instanceof ObjectEncoder) { + if (list.contains(parent + "" + defineTypeName(type))) { + return; + } + list.add(parent + "" + defineTypeName(type)); + + List members = new ArrayList<>(); + EnMember[] ems = ((ObjectEncoder) encoder).getMembers(); + for (EnMember member : ems) { + if (excludeFunc != null && excludeFunc.apply(type, member)) { + continue; + } + members.add(member); + } + final List sblist = new ArrayList<>(); + for (EnMember member : members) { + Type mtype = member.getEncoder().getType(); + if (!(mtype instanceof Class)) { + if (mtype instanceof ParameterizedType) { + final ParameterizedType pt = (ParameterizedType) mtype; + if (pt.getActualTypeArguments().length == 1 && (pt.getActualTypeArguments()[0] instanceof Class)) { + StringBuilder innersb = new StringBuilder(); + defineProtoDescriptor(parent, list, mtype, innersb, prefix, excludeFunc); + sblist.add(innersb); + } + } else if (mtype instanceof GenericArrayType) { + final GenericArrayType gt = (GenericArrayType) mtype; + if (!gt.getGenericComponentType().toString().startsWith("java") + && !gt.getGenericComponentType().toString().startsWith("class java") + && gt.getGenericComponentType().toString().indexOf('.') > 0) { + StringBuilder innersb = new StringBuilder(); + defineProtoDescriptor(parent, list, gt.getGenericComponentType(), innersb, prefix, excludeFunc); + sblist.add(innersb); + } + } + continue; + } + Class mclz = (Class) member.getEncoder().getType(); + if (!mclz.isArray() && !mclz.isEnum() && !mclz.getName().startsWith("java")) { + StringBuilder innersb = new StringBuilder(); + defineProtoDescriptor(parent, list, mclz, innersb, prefix, excludeFunc); + sblist.add(innersb); + } else if (mclz.isArray() && !mclz.getComponentType().getName().startsWith("java") + && !mclz.getComponentType().getName().equals("boolean") && !mclz.getComponentType().getName().equals("byte") + && !mclz.getComponentType().getName().equals("char") && !mclz.getComponentType().getName().equals("short") + && !mclz.getComponentType().getName().equals("int") && !mclz.getComponentType().getName().equals("long") + && !mclz.getComponentType().getName().equals("float") && !mclz.getComponentType().getName().equals("double")) { + StringBuilder innersb = new StringBuilder(); + defineProtoDescriptor(parent, list, mclz.getComponentType(), innersb, prefix, excludeFunc); + sblist.add(innersb); + } + } + for (StringBuilder sbitem : sblist) { + if (sbitem.length() < 1) { + continue; + } + sb.append(sbitem.toString().trim()).append("\r\n\r\n"); + } + sb.append(prefix).append("message ").append(defineTypeName(type)).append(" {\r\n"); + for (int i = 0; i < members.size(); i++) { + EnMember member = members.get(i); + try { + sb.append(prefix).append(" ").append(ProtobufFactory.wireTypeString(member.getEncoder().getType(), ((ProtobufFactory) factory).enumtostring)) + .append(" ").append(member.getAttribute().field()).append(" = ").append(member.getPosition()).append(member.getComment().isEmpty() ? ";\r\n" : ("; //" + member.getComment() + " \r\n")); + } catch (RuntimeException e) { + System.err.println("member = " + member); + throw e; + } + } + sb.append(prefix).append("}").append("\r\n"); + } else if (encoder instanceof ProtobufArrayEncoder || encoder instanceof ProtobufCollectionEncoder) { + Type mtype = encoder instanceof ProtobufArrayEncoder ? ((ProtobufArrayEncoder) encoder).getComponentType() : ((ProtobufCollectionEncoder) encoder).getComponentType(); + if (!mtype.toString().startsWith("java") && !mtype.toString().startsWith("class java") && mtype.toString().indexOf('.') > 0) { + defineProtoDescriptor(parent, list, mtype, sb, prefix, excludeFunc); + } + } else { + throw new ConvertException("Not support the type (" + type + ")"); + } + } + + protected StringBuilder defineTypeName(Type type) { + StringBuilder sb = new StringBuilder(); + if (type instanceof Class) { + sb.append(((Class) type).getSimpleName().replace("[]", "_Array")); + } else if (type instanceof ParameterizedType) { + Type raw = ((ParameterizedType) type).getRawType(); + sb.append(((Class) raw).getSimpleName().replace("[]", "_Array")); + Type[] ts = ((ParameterizedType) type).getActualTypeArguments(); + if (ts != null) { + for (Type t : ts) { + if (t != null) { + sb.append('_').append(defineTypeName(t)); + } + } + } + } + return sb; + } + + //------------------------------ convertFrom ----------------------------------------------------------- + @Override + public T convertFrom(final Type type, final byte[] bytes) { + if (bytes == null) { + return null; + } + return convertFrom(type, bytes, 0, bytes.length); + } + + @Override + @SuppressWarnings("unchecked") + public T convertFrom(final Type type, final byte[] bytes, final int offset, final int len) { + if (type == null) { + return null; + } + final ProtobufReader reader = new ProtobufReader(bytes, offset, len); + Decodeable decoder = this.lastConvertDecodeable; + if (decoder == null || decoder.getType() != type) { + decoder = factory.loadDecoder(type); + this.lastConvertDecodeable = decoder; + } + if (!(decoder instanceof ObjectDecoder) && !(decoder instanceof SimpledCoder)) { + throw new ConvertException(this.getClass().getSimpleName() + " not supported type(" + type + ")"); + } + T rs = (T) decoder.convertFrom(reader); + return rs; + } + + @SuppressWarnings("unchecked") + public T convertFrom(final Type type, final InputStream in) { + if (true) { + throw new ConvertException(this.getClass().getSimpleName() + " not supported convertFrom InputStream"); + } + if (type == null || in == null) { + return null; + } + Decodeable decoder = this.lastConvertDecodeable; + if (decoder == null || decoder.getType() != type) { + decoder = factory.loadDecoder(type); + this.lastConvertDecodeable = decoder; + } + if (!(decoder instanceof ObjectDecoder)) { + throw new ConvertException(this.getClass().getSimpleName() + " not supported type(" + type + ")"); + } + return (T) decoder.convertFrom(new ProtobufStreamReader(in)); + } + + @Override + @SuppressWarnings("unchecked") + public T convertFrom(final Type type, final ByteBuffer... buffers) { + if (true) { + throw new ConvertException(this.getClass().getSimpleName() + " not supported convertFrom ByteBuffer"); + } + if (type == null || buffers.length < 1) { + return null; + } + Decodeable decoder = this.lastConvertDecodeable; + if (decoder == null || decoder.getType() != type) { + decoder = factory.loadDecoder(type); + this.lastConvertDecodeable = decoder; + } + if (!(decoder instanceof ObjectDecoder)) { + throw new ConvertException(this.getClass().getSimpleName() + " not supported type(" + type + ")"); + } + return (T) decoder.convertFrom(new ProtobufByteBufferReader((ConvertMask) null, buffers)); + } + + @Override + @SuppressWarnings("unchecked") + public T convertFrom(final Type type, final ConvertMask mask, final ByteBuffer... buffers) { + if (true) { + throw new ConvertException(this.getClass().getSimpleName() + " not supported convertFrom ByteBuffer"); + } + if (type == null || buffers.length < 1) { + return null; + } + Decodeable decoder = this.lastConvertDecodeable; + if (decoder == null || decoder.getType() != type) { + decoder = factory.loadDecoder(type); + this.lastConvertDecodeable = decoder; + } + if (!(decoder instanceof ObjectDecoder)) { + throw new ConvertException(this.getClass().getSimpleName() + " not supported type(" + type + ")"); + } + return (T) decoder.convertFrom(new ProtobufByteBufferReader(mask, buffers)); + } + + @Override + @SuppressWarnings("unchecked") + public T convertFrom(final Type type, final ProtobufReader reader) { + if (type == null) { + return null; + } + Decodeable decoder = this.lastConvertDecodeable; + if (decoder == null || decoder.getType() != type) { + decoder = factory.loadDecoder(type); + this.lastConvertDecodeable = decoder; + } + if (!(decoder instanceof ObjectDecoder)) { + throw new ConvertException(this.getClass().getSimpleName() + " not supported type(" + type + ")"); + } + T rs = (T) decoder.convertFrom(reader); + return rs; + } + + //------------------------------ convertTo ----------------------------------------------------------- + @Override + public byte[] convertTo(final Type type, final Object value) { + if (value == null) { + final ProtobufWriter writer = pollWriter(); + writer.writeNull(); + byte[] result = writer.toArray(); + offerWriter(writer); + return result; + } + final Type t = type == null ? value.getClass() : type; + final ProtobufWriter writer = pollWriter(); + Encodeable encoder = this.lastConvertEncodeable; + if (encoder == null || encoder.getType() != t) { + encoder = factory.loadEncoder(t); + this.lastConvertEncodeable = encoder; + } + if (encoder.specifyable()) { + writer.specificObjectType(t); + } + if (!(encoder instanceof ObjectEncoder) && !(encoder instanceof SimpledCoder)) { + throw new ConvertException(this.getClass().getSimpleName() + " not supported type(" + t + ")"); + } + encoder.convertTo(writer, value); + byte[] result = writer.toArray(); + offerWriter(writer); + return result; + } + + public byte[] convertTo(final Object value, int tag, byte... appends) { + return convertTo(value.getClass(), value, tag, appends); + } + + public byte[] convertTo(final Type type, final Object value, int tag, byte... appends) { + if (type == null) { + return null; + } + final ProtobufWriter writer = pollWriter(); + Encodeable encoder = this.lastConvertEncodeable; + if (encoder == null || encoder.getType() != type) { + encoder = factory.loadEncoder(type); + this.lastConvertEncodeable = encoder; + } + if (encoder.specifyable()) { + writer.specificObjectType(type); + } + if (!(encoder instanceof ObjectEncoder) && !(encoder instanceof SimpledCoder)) { + throw new ConvertException(this.getClass().getSimpleName() + " not supported type(" + type + ")"); + } + encoder.convertTo(writer, value); + writer.writeUInt32(tag); + writer.writeUInt32(appends.length); + writer.writeTo(appends); + byte[] result = writer.toArray(); + offerWriter(writer); + return result; + } + + @Override + public byte[] convertToBytes(final Type type, final Object value) { + return convertTo(type, value); + } + + @Override + public void convertToBytes(final Type type, final Object value, final ConvertBytesHandler handler) { + final ProtobufWriter writer = pollWriter(); + if (value == null) { + writer.writeNull(); + } else { + final Type t = type == null ? value.getClass() : type; + Encodeable encoder = this.lastConvertEncodeable; + if (encoder == null || encoder.getType() != t) { + encoder = factory.loadEncoder(t); + this.lastConvertEncodeable = encoder; + } + if (encoder.specifyable()) { + writer.specificObjectType(t); + } + if (!(encoder instanceof ObjectEncoder) && !(encoder instanceof SimpledCoder)) { + throw new ConvertException(this.getClass().getSimpleName() + " not supported type(" + t + ")"); + } + encoder.convertTo(writer, value); + } + writer.completed(handler, writerConsumer); + } + + @Override + public void convertToBytes(final ByteArray array, final Type type, final Object value) { + Objects.requireNonNull(array); + final ProtobufWriter writer = configWrite(new ProtobufWriter(array).withFeatures(features).enumtostring(((ProtobufFactory) factory).enumtostring)); + if (value == null) { + writer.writeNull(); + } else { + final Type t = type == null ? value.getClass() : type; + Encodeable encoder = this.lastConvertEncodeable; + if (encoder == null || encoder.getType() != t) { + encoder = factory.loadEncoder(t); + this.lastConvertEncodeable = encoder; + } + if (encoder.specifyable()) { + writer.specificObjectType(t); + } + if (!(encoder instanceof ObjectEncoder) && !(encoder instanceof SimpledCoder)) { + throw new ConvertException(this.getClass().getSimpleName() + " not supported type(" + t + ")"); + } + encoder.convertTo(writer, value); + } + writer.directTo(array); + } + + public void convertTo(final OutputStream out, final Type type, final Object value) { + if (true) { + throw new ConvertException(this.getClass().getSimpleName() + " not supported convertTo OutputStream"); + } + ProtobufWriter writer = pollProtobufWriter(out); + if (value == null) { + writer.writeNull(); + } else { + final Type t = type == null ? value.getClass() : type; + Encodeable encoder = this.lastConvertEncodeable; + if (encoder == null || encoder.getType() != t) { + encoder = factory.loadEncoder(t); + this.lastConvertEncodeable = encoder; + } + if (encoder.specifyable()) { + writer.specificObjectType(t); + } + if (!(encoder instanceof ObjectEncoder)) { + throw new ConvertException(this.getClass().getSimpleName() + " not supported type(" + t + ")"); + } + encoder.convertTo(writer, value); + } + } + + @Override + public ByteBuffer[] convertTo(final Supplier supplier, final Type type, final Object value) { + //if (true) throw new ConvertException(this.getClass().getSimpleName() + " not supported convertTo ByteBuffer"); + Objects.requireNonNull(supplier); + ProtobufByteBufferWriter writer = pollProtobufWriter(supplier); + if (value == null) { + writer.writeNull(); + } else { + final Type t = type == null ? value.getClass() : type; + Encodeable encoder = this.lastConvertEncodeable; + if (encoder == null || encoder.getType() != t) { + encoder = factory.loadEncoder(t); + this.lastConvertEncodeable = encoder; + } + if (encoder.specifyable()) { + writer.specificObjectType(t); + } + if (!(encoder instanceof ObjectEncoder)) { + throw new ConvertException(this.getClass().getSimpleName() + " not supported type(" + t + ")"); + } + encoder.convertTo(writer, value); + } + return writer.toBuffers(); + } + + @Override + public void convertTo(final ProtobufWriter writer, final Type type, final Object value) { + if (value == null) { + writer.writeNull(); + return; + } + writer.initOffset = writer.count; + final Type t = type == null ? value.getClass() : type; + Encodeable encoder = this.lastConvertEncodeable; + if (encoder == null || encoder.getType() != t) { + encoder = factory.loadEncoder(t); + this.lastConvertEncodeable = encoder; + } + if (encoder.specifyable()) { + writer.specificObjectType(t); + } + encoder.convertTo(writer, value); + } + + public ProtobufWriter convertToWriter(final Type type, final Object value) { + if (value == null) { + return null; + } + final ProtobufWriter writer = pollWriter(); + final Type t = type == null ? value.getClass() : type; + Encodeable encoder = this.lastConvertEncodeable; + if (encoder == null || encoder.getType() != t) { + encoder = factory.loadEncoder(t); + this.lastConvertEncodeable = encoder; + } + if (encoder.specifyable()) { + writer.specificObjectType(t); + } + if (!(encoder instanceof ObjectEncoder)) { + throw new ConvertException(this.getClass().getSimpleName() + " not supported type(" + t + ")"); + } + encoder.convertTo(writer, value); + return writer; + } + +} diff --git a/src/main/java/org/redkale/convert/protobuf/ProtobufConvertProvider.java b/src/main/java/org/redkale/convert/protobuf/ProtobufConvertProvider.java new file mode 100644 index 000000000..45023d16b --- /dev/null +++ b/src/main/java/org/redkale/convert/protobuf/ProtobufConvertProvider.java @@ -0,0 +1,28 @@ +/* + * 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.redkale.convert.protobuf; + +import org.redkale.annotation.Priority; +import org.redkale.convert.*; + +/** + * + * @author zhangjx + */ +@Priority(-900) +public class ProtobufConvertProvider implements ConvertProvider { + + @Override + public ConvertType type() { + return ConvertType.PROTOBUF; + } + + @Override + public Convert convert() { + return ProtobufConvert.root(); + } + +} diff --git a/src/main/java/org/redkale/convert/protobuf/ProtobufEnumSimpledCoder.java b/src/main/java/org/redkale/convert/protobuf/ProtobufEnumSimpledCoder.java new file mode 100644 index 000000000..939d037a3 --- /dev/null +++ b/src/main/java/org/redkale/convert/protobuf/ProtobufEnumSimpledCoder.java @@ -0,0 +1,72 @@ +/* + * 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.redkale.convert.protobuf; + +import java.lang.reflect.Method; +import java.util.*; +import org.redkale.convert.*; +import org.redkale.util.RedkaleClassLoader; + +/** + * 枚举 的SimpledCoder实现 + * + *

+ * 详情见: https://redkale.org + * + * @author zhangjx + * @param Reader输入的子类型 + * @param Writer输出的子类型 + * @param Enum的子类 + */ +public class ProtobufEnumSimpledCoder extends SimpledCoder { + + private final Map values = new HashMap<>(); + + private final boolean enumtostring; + + public ProtobufEnumSimpledCoder(Class type, boolean enumtostring) { + this.type = type; + this.enumtostring = enumtostring; + try { + final Method method = type.getMethod("values"); + RedkaleClassLoader.putReflectionMethod(type.getName(), method); + for (E item : (E[]) method.invoke(null)) { + values.put(item.ordinal(), item); + } + } catch (Exception e) { + throw new ConvertException(e); + } + } + + @Override + public void convertTo(final W out, final E value) { + if (value == null) { + out.writeNull(); + } else if (enumtostring) { + out.writeSmallString(value.toString()); + } else { + ((ProtobufWriter) out).writeUInt32(value.ordinal()); + } + } + + @Override + @SuppressWarnings("unchecked") + public E convertFrom(final R in) { + if (enumtostring) { + String value = in.readSmallString(); + if (value == null) return null; + return (E) Enum.valueOf((Class) type, value); + } + int value = ((ProtobufReader) in).readRawVarint32(); + return values.get(value); + } + + @Override + public Class getType() { + return (Class) type; + } + +} diff --git a/src/main/java/org/redkale/convert/protobuf/ProtobufFactory.java b/src/main/java/org/redkale/convert/protobuf/ProtobufFactory.java new file mode 100644 index 000000000..00cb213e7 --- /dev/null +++ b/src/main/java/org/redkale/convert/protobuf/ProtobufFactory.java @@ -0,0 +1,340 @@ +/* + * 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.redkale.convert.protobuf; + +import java.io.Serializable; +import java.lang.reflect.*; +import java.util.*; +import java.util.concurrent.atomic.*; +import java.util.stream.Stream; +import org.redkale.convert.*; +import org.redkale.util.AnyValue; + +/** + * + * @author zhangjx + */ +public class ProtobufFactory extends ConvertFactory { + + private static final ProtobufFactory instance = new ProtobufFactory(null, + getSystemPropertyInt("redkale.convert.protobuf.tiny", "redkale.convert.tiny", true, Convert.FEATURE_TINY) + | getSystemPropertyInt("redkale.convert.protobuf.nullable", "redkale.convert.nullable", false, Convert.FEATURE_NULLABLE), + Boolean.parseBoolean(System.getProperty("redkale.convert.protobuf.enumtostring", "true"))); + + static final Decodeable objectDecoder = instance.loadDecoder(Object.class); + + static final Encodeable objectEncoder = instance.loadEncoder(Object.class); + + protected final boolean enumtostring; + + protected boolean reversible = false; + + static { + instance.register(Serializable.class, objectDecoder); + instance.register(Serializable.class, objectEncoder); + + instance.register(AnyValue.class, instance.loadDecoder(AnyValue.DefaultAnyValue.class)); + instance.register(AnyValue.class, instance.loadEncoder(AnyValue.DefaultAnyValue.class)); + } + + @SuppressWarnings("OverridableMethodCallInConstructor") + private ProtobufFactory(ProtobufFactory parent, int features, boolean enumtostring) { + super(parent, features); + this.enumtostring = enumtostring; + if (parent == null) { //root + this.register(String[].class, this.createArrayDecoder(String[].class)); + this.register(String[].class, this.createArrayEncoder(String[].class)); + } + } + + public static ProtobufFactory root() { + return instance; + } + + @Override + public ProtobufFactory withFeatures(int features) { + return super.withFeatures(features); + } + + @Override + public ProtobufFactory addFeature(int feature) { + return super.addFeature(feature); + } + + @Override + public ProtobufFactory removeFeature(int feature) { + return super.removeFeature(feature); + } + + @Override + public ProtobufFactory withTinyFeature(boolean tiny) { + return super.withTinyFeature(tiny); + } + + @Override + public ProtobufFactory withNullableFeature(boolean nullable) { + return super.withNullableFeature(nullable); + } + + public static ProtobufFactory create() { + return new ProtobufFactory(null, instance.features, instance.enumtostring); + } + + @Override + protected SimpledCoder createEnumSimpledCoder(Class enumClass) { + return new ProtobufEnumSimpledCoder(enumClass, this.enumtostring); + } + + @Override + protected ObjectDecoder createObjectDecoder(Type type) { + return new ProtobufObjectDecoder(type); + } + + @Override + protected ObjectEncoder createObjectEncoder(Type type) { + return new ProtobufObjectEncoder(type); + } + + @Override + protected Decodeable createMapDecoder(Type type) { + return new ProtobufMapDecoder(this, type); + } + + @Override + protected Encodeable createMapEncoder(Type type) { + return new ProtobufMapEncoder(this, type); + } + + @Override + protected Decodeable createArrayDecoder(Type type) { + return new ProtobufArrayDecoder(this, type); + } + + @Override + protected Encodeable createArrayEncoder(Type type) { + return new ProtobufArrayEncoder(this, type); + } + + @Override + protected Decodeable createCollectionDecoder(Type type) { + return new ProtobufCollectionDecoder(this, type); + } + + @Override + protected Encodeable createCollectionEncoder(Type type) { + return new ProtobufCollectionEncoder(this, type); + } + + @Override + protected Decodeable createStreamDecoder(Type type) { + return new ProtobufStreamDecoder(this, type); + } + + @Override + protected Encodeable createStreamEncoder(Type type) { + return new ProtobufStreamEncoder(this, type); + } + + @Override + public final ProtobufConvert getConvert() { + if (convert == null) { + convert = new ProtobufConvert(this, features); + } + return (ProtobufConvert) convert; + } + + @Override + public ProtobufFactory createChild() { + return new ProtobufFactory(this, features, this.enumtostring); + } + + @Override + public ProtobufFactory createChild(int features) { + return new ProtobufFactory(this, features, this.enumtostring); + } + + @Override + public ConvertType getConvertType() { + return ConvertType.PROTOBUF; + } + + public ProtobufFactory reversible(boolean reversible) { + this.reversible = reversible; + return this; + } + + @Override + public boolean isReversible() { + return reversible; + } + + @Override + public boolean isFieldSort() { + return true; + } + + protected static Reader getItemReader(boolean string, boolean simple, Reader in, DeMember member, boolean enumtostring, boolean first) { + if (string) { + if (member == null || first) { + return in; + } + ProtobufReader reader = (ProtobufReader) in; + int tag = reader.readTag(); + if (tag != member.getTag()) { + reader.backTag(tag); + return null; + } + return in; + } else { + 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); + } + } + + public static int getTag(String fieldName, Type fieldType, int fieldPos, boolean enumtostring) { + int wiretype = ProtobufFactory.wireType(fieldType, enumtostring); + return (fieldPos << 3 | wiretype); + } + + public static int getTag(DeMember member, boolean enumtostring) { + int wiretype = ProtobufFactory.wireType(member.getAttribute().type(), enumtostring); + return (member.getPosition() << 3 | wiretype); + } + + public static int wireType(Type javaType, boolean enumtostring) { + if (javaType == double.class || javaType == Double.class) { + return 1; + } + if (javaType == float.class || javaType == Float.class) { + return 5; + } + if (javaType == boolean.class || javaType == Boolean.class) { + return 0; + } + if (javaType instanceof Class) { + Class javaClazz = (Class) javaType; + if (javaClazz.isEnum()) { + return enumtostring ? 2 : 0; + } + if (javaClazz.isPrimitive() || Number.class.isAssignableFrom(javaClazz)) { + return 0; + } + } + return 2; + } + + public static String wireTypeString(Type javaType, boolean enumtostring) { + if (javaType == double.class || javaType == Double.class) { + return "double"; + } + if (javaType == long.class || javaType == Long.class) { + return "sint64"; + } + if (javaType == float.class || javaType == Float.class) { + return "float"; + } + if (javaType == int.class || javaType == Integer.class) { + return "sint32"; + } + if (javaType == short.class || javaType == Short.class) { + return "sint32"; + } + if (javaType == char.class || javaType == Character.class) { + return "sint32"; + } + if (javaType == byte.class || javaType == Byte.class) { + return "sint32"; + } + if (javaType == boolean.class || javaType == Boolean.class) { + return "bool"; + } + if (javaType == AtomicLong.class) { + return "sint64"; + } + if (javaType == AtomicInteger.class) { + return "sint32"; + } + if (javaType == AtomicBoolean.class) { + return "bool"; + } + + if (javaType == double[].class || javaType == Double[].class) { + return "repeated double"; + } + if (javaType == long[].class || javaType == Long[].class) { + return "repeated sint64"; + } + if (javaType == float[].class || javaType == Float[].class) { + return "repeated float"; + } + if (javaType == int[].class || javaType == Integer[].class) { + return "repeated sint32"; + } + if (javaType == short[].class || javaType == Short[].class) { + return "repeated sint32"; + } + if (javaType == char[].class || javaType == Character[].class) { + return "repeated sint32"; + } + if (javaType == byte[].class || javaType == Byte[].class) { + return "bytes"; + } + if (javaType == boolean[].class || javaType == Boolean[].class) { + return "repeated bool"; + } + if (javaType == AtomicLong[].class) { + return "repeated sint64"; + } + if (javaType == AtomicInteger[].class) { + return "repeated sint32"; + } + if (javaType == AtomicBoolean[].class) { + return "repeated bool"; + } + + if (javaType == java.util.Properties.class) { + return "map"; + } + if (javaType instanceof Class) { + Class javaClazz = (Class) javaType; + if (javaClazz.isArray()) { + return "repeated " + wireTypeString(javaClazz.getComponentType(), enumtostring); + } + if (javaClazz.isEnum()) { + return enumtostring ? "string" : javaClazz.getSimpleName(); + } + if (CharSequence.class.isAssignableFrom(javaClazz)) { + return "string"; + } + return javaClazz == Object.class ? "Any" : javaClazz.getSimpleName(); + } else if (javaType instanceof ParameterizedType) { //Collection、Stream、Map 必须是泛型 + final ParameterizedType pt = (ParameterizedType) javaType; + final Class rawType = (Class) pt.getRawType(); + if (Map.class.isAssignableFrom(rawType)) { + Type keyType = pt.getActualTypeArguments()[0]; + Type valueType = pt.getActualTypeArguments()[1]; + return "map<" + wireTypeString(keyType, enumtostring) + "," + wireTypeString(valueType, enumtostring) + ">"; + } else if (Collection.class.isAssignableFrom(rawType) + || Stream.class.isAssignableFrom(rawType) || rawType.isArray()) { + return "repeated " + wireTypeString(pt.getActualTypeArguments()[0], enumtostring); + } else if (pt.getActualTypeArguments().length == 1 + && (pt.getActualTypeArguments()[0] instanceof Class)) { + return rawType.getSimpleName() + "_" + ((Class) pt.getActualTypeArguments()[0]).getSimpleName(); + } + } else if (javaType instanceof GenericArrayType) { + return "repeated " + wireTypeString(((GenericArrayType) javaType).getGenericComponentType(), enumtostring); + } + throw new UnsupportedOperationException("ProtobufConvert not supported type(" + javaType + ")"); + } +} diff --git a/src/main/java/org/redkale/convert/protobuf/ProtobufMapDecoder.java b/src/main/java/org/redkale/convert/protobuf/ProtobufMapDecoder.java new file mode 100644 index 000000000..a2c8fe781 --- /dev/null +++ b/src/main/java/org/redkale/convert/protobuf/ProtobufMapDecoder.java @@ -0,0 +1,53 @@ +/* + * 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.redkale.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); + } +} diff --git a/src/main/java/org/redkale/convert/protobuf/ProtobufMapEncoder.java b/src/main/java/org/redkale/convert/protobuf/ProtobufMapEncoder.java new file mode 100644 index 000000000..016fabbc2 --- /dev/null +++ b/src/main/java/org/redkale/convert/protobuf/ProtobufMapEncoder.java @@ -0,0 +1,38 @@ +/* + * 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.redkale.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()); + } +} diff --git a/src/main/java/org/redkale/convert/protobuf/ProtobufObjectDecoder.java b/src/main/java/org/redkale/convert/protobuf/ProtobufObjectDecoder.java new file mode 100644 index 000000000..ac87fbcd1 --- /dev/null +++ b/src/main/java/org/redkale/convert/protobuf/ProtobufObjectDecoder.java @@ -0,0 +1,71 @@ +/* + * 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.redkale.convert.protobuf; + +import java.lang.reflect.Type; +import org.redkale.convert.*; +import org.redkale.util.Attribute; + +/** + * + * @author zhangjx + * @param T + */ +public class ProtobufObjectDecoder extends ObjectDecoder { + + protected ProtobufObjectDecoder(Type type) { + super(type); + } + + @Override + protected void initForEachDeMember(ConvertFactory factory, DeMember member) { + Attribute attr = member.getAttribute(); + setTag(member, ProtobufFactory.getTag(attr.field(), attr.genericType(), member.getPosition(), ((ProtobufFactory) factory).enumtostring)); + } + + @Override + protected ProtobufReader objectReader(ProtobufReader in) { + if (in.position() > in.initoffset) return new ProtobufReader(in.readByteArray()); + return in; + } + + @Override + protected boolean hasNext(ProtobufReader in, boolean first) { + return in.hasNext(); + } + + @Override + protected Object readDeMemberValue(ProtobufReader in, DeMember member, boolean first) { + Decodeable decoder = member.getDecoder(); + if (decoder instanceof ProtobufArrayDecoder) { + return ((ProtobufArrayDecoder) decoder).convertFrom(in, member); + } else if (decoder instanceof ProtobufCollectionDecoder) { + return ((ProtobufCollectionDecoder) decoder).convertFrom(in, member); + } else if (decoder instanceof ProtobufStreamDecoder) { + return ((ProtobufStreamDecoder) decoder).convertFrom(in, member); + } else if (decoder instanceof ProtobufMapDecoder) { + return ((ProtobufMapDecoder) decoder).convertFrom(in, member); + } else { + return member.read(in); + } + } + + @Override + protected void readDeMemberValue(ProtobufReader in, DeMember member, T result, boolean first) { + Decodeable decoder = member.getDecoder(); + if (decoder instanceof ProtobufArrayDecoder) { + member.getAttribute().set(result, ((ProtobufArrayDecoder) decoder).convertFrom(in, member)); + } else if (decoder instanceof ProtobufCollectionDecoder) { + member.getAttribute().set(result, ((ProtobufCollectionDecoder) decoder).convertFrom(in, member)); + } else if (decoder instanceof ProtobufStreamDecoder) { + member.getAttribute().set(result, ((ProtobufStreamDecoder) decoder).convertFrom(in, member)); + } else if (decoder instanceof ProtobufMapDecoder) { + member.getAttribute().set(result, ((ProtobufMapDecoder) decoder).convertFrom(in, member)); + } else { + member.read(in, result); + } + } +} diff --git a/src/main/java/org/redkale/convert/protobuf/ProtobufObjectEncoder.java b/src/main/java/org/redkale/convert/protobuf/ProtobufObjectEncoder.java new file mode 100644 index 000000000..0818e6f1c --- /dev/null +++ b/src/main/java/org/redkale/convert/protobuf/ProtobufObjectEncoder.java @@ -0,0 +1,35 @@ +/* + * 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.redkale.convert.protobuf; + +import java.lang.reflect.Type; +import org.redkale.convert.*; +import org.redkale.util.Attribute; + +/** + * + * @author zhangjx + */ +public class ProtobufObjectEncoder extends ObjectEncoder { + + protected ProtobufObjectEncoder(Type type) { + super(type); + } + + @Override + protected void initForEachEnMember(ConvertFactory factory, EnMember member) { + Attribute attr = member.getAttribute(); + setTag(member, ProtobufFactory.getTag(attr.field(), attr.genericType(), member.getPosition(), ((ProtobufFactory) factory).enumtostring)); + } + + @Override + protected ProtobufWriter objectWriter(ProtobufWriter out, T value) { + if (out.count() > out.initOffset) { + return new ProtobufWriter(out, out.getFeatures()).configFieldFunc(out); + } + return out; + } +} diff --git a/src/main/java/org/redkale/convert/protobuf/ProtobufReader.java b/src/main/java/org/redkale/convert/protobuf/ProtobufReader.java new file mode 100644 index 000000000..d00f52721 --- /dev/null +++ b/src/main/java/org/redkale/convert/protobuf/ProtobufReader.java @@ -0,0 +1,456 @@ +/* + * 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.redkale.convert.protobuf; + +import java.lang.reflect.Type; +import java.nio.charset.StandardCharsets; +import java.util.*; +import java.util.concurrent.atomic.*; +import org.redkale.convert.*; +import org.redkale.util.ObjectPool; + +/** + * + * @author zhangjx + */ +public class ProtobufReader extends Reader { + + protected int position = -1; + + protected int initoffset; + + private byte[] content; + + protected int cachetag = Integer.MIN_VALUE; + + protected boolean enumtostring; + + public static ObjectPool createPool(int max) { + return ObjectPool.createSafePool(max, (Object... params) -> new ProtobufReader(), null, (t) -> t.recycle()); + } + + public ProtobufReader() { + } + + public ProtobufReader(byte[] bytes) { + setBytes(bytes, 0, bytes.length); + } + + public ProtobufReader(byte[] bytes, int start, int len) { + setBytes(bytes, start, len); + } + + public ProtobufReader enumtostring(boolean enumtostring) { + this.enumtostring = enumtostring; + return this; + } + + @Override + public void prepare(byte[] bytes) { + setBytes(bytes); + } + + public final void setBytes(byte[] bytes) { + if (bytes == null) { + this.position = 0; + this.initoffset = 0; + } else { + setBytes(bytes, 0, bytes.length); + } + } + + public final void setBytes(byte[] bytes, int start, int len) { + if (bytes == null) { + this.position = 0; + this.initoffset = 0; + } else { + this.content = bytes; + this.position = start - 1; + this.initoffset = this.position; + } + } + + protected boolean recycle() { + this.position = -1; + this.initoffset = -1; + this.content = null; + return true; + } + + public ProtobufReader clear() { + this.recycle(); + return this; + } + + public byte[] remainBytes() { + if (this.position >= this.content.length) { + return new byte[0]; + } + return Arrays.copyOfRange(this.content, this.position + 1, this.content.length); + } + + /** + * 跳过属性的值 + */ + @Override + @SuppressWarnings("unchecked") + public final void skipValue() { + int tag = readTag(); + if (tag == 0) { + return; + } + switch (tag & 0x7) { + case 0: + readRawVarint32(); + break; + case 1: + readRawLittleEndian64(); + break; + case 2: + readByteArray(); + break; + case 5: + readRawLittleEndian32(); + break; + } + } + + @Override + public final String readObjectB(final Class clazz) { + return (this.position + 1) < this.content.length ? "" : null; + } + + @Override + public final void readObjectE(final Class clazz) { + + } + + @Override + public final int readMapB(DeMember member, byte[] typevals, Decodeable keyDecoder, Decodeable valueDecoder) { + return Reader.SIGN_NOLENGTH; + } + + @Override + public final void readMapE() { + } + + /** + * 判断下一个非空白字符是否为[ + * + * @param member DeMember + * @param typevals byte[] + * @param componentDecoder Decodeable + * + * @return SIGN_NOLENGTH 或 SIGN_NULL + */ + @Override + public final int readArrayB(DeMember member, byte[] typevals, Decodeable componentDecoder) { + if (member == null || componentDecoder == null) { + return Reader.SIGN_NOLENBUTBYTES; + } + Type type = componentDecoder.getType(); + if (!(type instanceof Class)) { + return Reader.SIGN_NOLENBUTBYTES; + } + Class clazz = (Class) type; + if (clazz.isPrimitive() || clazz == Boolean.class || clazz == Byte.class + || clazz == Short.class || clazz == Character.class + || clazz == Integer.class || clazz == Float.class + || clazz == Long.class || clazz == Double.class + || clazz == AtomicInteger.class || clazz == AtomicLong.class) { + return Reader.SIGN_NOLENBUTBYTES; + } + return Reader.SIGN_NOLENGTH; + } + + @Override + public final void readArrayE() { + } + + /** + * 判断下一个非空白字节是否: + * + */ + @Override + public final void readBlank() { + } + + @Override + public final int position() { + return this.position; + } + + @Override + public final int readMemberContentLength(DeMember member, Decodeable decoder) { + if (member == null && decoder == null) { + return -1; //为byte[] + } + if (member != null) { + if (member.getDecoder() instanceof ProtobufArrayDecoder) { + ProtobufArrayDecoder pdecoder = (ProtobufArrayDecoder) member.getDecoder(); + if (pdecoder.simple) { + return readRawVarint32(); + } + } else if (member.getDecoder() instanceof ProtobufCollectionDecoder) { + ProtobufCollectionDecoder pdecoder = (ProtobufCollectionDecoder) member.getDecoder(); + if (pdecoder.simple) { + return readRawVarint32(); + } + } else if (member.getDecoder() instanceof ProtobufStreamDecoder) { + ProtobufStreamDecoder pdecoder = (ProtobufStreamDecoder) member.getDecoder(); + if (pdecoder.simple) { + return readRawVarint32(); + } + } + return -1; + } + return readRawVarint32(); //readUInt32 + } + + @Override + public final DeMember readFieldName(final DeMember[] members, Map memberFieldMap, Map memberTagMap) { + int tag = readTag(); + for (DeMember member : members) { + if (member.getTag() == tag) { + return member; + } + } + backTag(tag); + return null; + } + + //------------------------------------------------------------ + @Override + public final boolean readBoolean() { + return readRawVarint64() != 0; + } + + @Override + public final byte readByte() { + return (byte) readInt(); + } + + @Override + public final char readChar() { + return (char) readInt(); + } + + @Override + public final short readShort() { + return (short) readInt(); + } + + @Override + public final int readInt() { //readSInt32 + int n = readRawVarint32(); + return (n >>> 1) ^ -(n & 1); + } + + @Override + public final long readLong() { //readSInt64 + long n = readRawVarint64(); + return (n >>> 1) ^ -(n & 1); + } + + @Override + public final float readFloat() { + return Float.intBitsToFloat(readRawLittleEndian32()); + } + + @Override + public final double readDouble() { + return Double.longBitsToDouble(readRawLittleEndian64()); + } + + @Override + public final String readClassName() { + return ""; + } + + @Override + public final String readSmallString() { + return readString(); + } + + @Override + public final String readString() { + return new String(readByteArray(), StandardCharsets.UTF_8); + } + + protected final int readTag() { + if (cachetag != Integer.MIN_VALUE) { + int tag = cachetag; + cachetag = Integer.MIN_VALUE; + return tag; + } + return readRawVarint32(); + } + + protected final void backTag(int tag) { + this.cachetag = tag; + } + + protected byte currentByte() { + return this.content[this.position]; + } + + /** + * 判断对象是否存在下一个属性或者数组是否存在下一个元素 + * + * @param startPosition 起始位置 + * @param contentLength 内容大小, 不确定的传-1 + * + * @return 是否存在 + */ + @Override + public boolean hasNext(int startPosition, int contentLength) { + //("-------------: " + startPosition + ", " + contentLength + ", " + this.position); + if (startPosition >= 0 && contentLength >= 0) { + return (this.position) < (startPosition + contentLength); + } + return (this.position + 1) < this.content.length; + } + + @Override + public byte[] readByteArray() { + final int size = readRawVarint32(); + byte[] bs = new byte[size]; + System.arraycopy(content, position + 1, bs, 0, size); + position += size; + return bs; + } + + protected int readRawVarint32() { //readUInt32 + fastpath: + { + int tempPos = this.position; + if ((tempPos + 1) == content.length) { + break fastpath; + } + + int x; + if ((x = content[++tempPos]) >= 0) { + this.position = tempPos; + return x; + } else if (content.length - (tempPos + 1) < 9) { + break fastpath; + } else if ((x ^= (content[++tempPos] << 7)) < 0) { + x ^= (~0 << 7); + } else if ((x ^= (content[++tempPos] << 14)) >= 0) { + x ^= (~0 << 7) ^ (~0 << 14); + } else if ((x ^= (content[++tempPos] << 21)) < 0) { + x ^= (~0 << 7) ^ (~0 << 14) ^ (~0 << 21); + } else { + int y = content[++tempPos]; + x ^= y << 28; + x ^= (~0 << 7) ^ (~0 << 14) ^ (~0 << 21) ^ (~0 << 28); + if (y < 0 + && content[++tempPos] < 0 + && content[++tempPos] < 0 + && content[++tempPos] < 0 + && content[++tempPos] < 0 + && content[++tempPos] < 0) { + break fastpath; // Will throw malformedVarint() + } + } + this.position = tempPos; + return x; + } + return (int) readRawVarint64SlowPath(); + } + + protected long readRawVarint64() { + fastpath: + { + int tempPos = this.position; + if ((tempPos + 1) == content.length) { + break fastpath; + } + + long x; + int y; + if ((y = content[++tempPos]) >= 0) { + this.position = tempPos; + return y; + } else if (content.length - (tempPos + 1) < 9) { + break fastpath; + } else if ((y ^= (content[++tempPos] << 7)) < 0) { + x = y ^ (~0 << 7); + } else if ((y ^= (content[++tempPos] << 14)) >= 0) { + x = y ^ ((~0 << 7) ^ (~0 << 14)); + } else if ((y ^= (content[++tempPos] << 21)) < 0) { + x = y ^ ((~0 << 7) ^ (~0 << 14) ^ (~0 << 21)); + } else if ((x = y ^ ((long) content[++tempPos] << 28)) >= 0L) { + x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28); + } else if ((x ^= ((long) content[++tempPos] << 35)) < 0L) { + x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28) ^ (~0L << 35); + } else if ((x ^= ((long) content[++tempPos] << 42)) >= 0L) { + x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28) ^ (~0L << 35) ^ (~0L << 42); + } else if ((x ^= ((long) content[++tempPos] << 49)) < 0L) { + x ^= (~0L << 7) + ^ (~0L << 14) + ^ (~0L << 21) + ^ (~0L << 28) + ^ (~0L << 35) + ^ (~0L << 42) + ^ (~0L << 49); + } else { + x ^= ((long) content[++tempPos] << 56); + x ^= (~0L << 7) + ^ (~0L << 14) + ^ (~0L << 21) + ^ (~0L << 28) + ^ (~0L << 35) + ^ (~0L << 42) + ^ (~0L << 49) + ^ (~0L << 56); + if (x < 0L) { + if (content[++tempPos] < 0L) { + break fastpath; // Will throw malformedVarint() + } + } + } + this.position = tempPos; + return x; + } + return readRawVarint64SlowPath(); + } + + protected long readRawVarint64SlowPath() { + long result = 0; + for (int shift = 0; shift < 64; shift += 7) { + final byte b = content[++this.position]; + result |= (long) (b & 0x7F) << shift; + if ((b & 0x80) == 0) { + return result; + } + } + throw new ConvertException("readRawVarint64SlowPath error"); + } + + protected int readRawLittleEndian32() { + return ((content[++this.position] & 0xff) + | ((content[++this.position] & 0xff) << 8) + | ((content[++this.position] & 0xff) << 16) + | ((content[++this.position] & 0xff) << 24)); + } + + protected long readRawLittleEndian64() { + return ((content[++this.position] & 0xffL) + | ((content[++this.position] & 0xffL) << 8) + | ((content[++this.position] & 0xffL) << 16) + | ((content[++this.position] & 0xffL) << 24) + | ((content[++this.position] & 0xffL) << 32) + | ((content[++this.position] & 0xffL) << 40) + | ((content[++this.position] & 0xffL) << 48) + | ((content[++this.position] & 0xffL) << 56)); + } + + @Override + public ValueType readType() { + throw new UnsupportedOperationException("Not supported yet."); + } +} diff --git a/src/main/java/org/redkale/convert/protobuf/ProtobufStreamDecoder.java b/src/main/java/org/redkale/convert/protobuf/ProtobufStreamDecoder.java new file mode 100644 index 000000000..9a292c529 --- /dev/null +++ b/src/main/java/org/redkale/convert/protobuf/ProtobufStreamDecoder.java @@ -0,0 +1,41 @@ +/* + * 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.redkale.convert.protobuf; + +import java.lang.reflect.Type; +import java.util.concurrent.atomic.*; +import org.redkale.convert.*; + +/** + * + * @author zhangjx + * @param 泛型 + */ +public class ProtobufStreamDecoder extends StreamDecoder { + + protected final boolean simple; + + private final boolean string; + + private final boolean enumtostring; + + public ProtobufStreamDecoder(ConvertFactory factory, Type type) { + super(factory, type); + this.enumtostring = ((ProtobufFactory) factory).enumtostring; + Type comtype = this.getComponentType(); + this.string = String.class == comtype; + this.simple = Boolean.class == comtype || Short.class == comtype + || Character.class == comtype || Integer.class == comtype || Float.class == comtype + || Long.class == comtype || Double.class == comtype + || AtomicInteger.class == comtype || AtomicLong.class == comtype; + } + + @Override + protected Reader getItemReader(Reader in, DeMember member, boolean first) { + if (simple) return in; + return ProtobufFactory.getItemReader(string, simple, in, member, enumtostring, first); + } +} diff --git a/src/main/java/org/redkale/convert/protobuf/ProtobufStreamEncoder.java b/src/main/java/org/redkale/convert/protobuf/ProtobufStreamEncoder.java new file mode 100644 index 000000000..6f4f2f048 --- /dev/null +++ b/src/main/java/org/redkale/convert/protobuf/ProtobufStreamEncoder.java @@ -0,0 +1,52 @@ +/* + * 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.redkale.convert.protobuf; + +import java.lang.reflect.Type; +import java.util.concurrent.atomic.*; +import org.redkale.convert.*; + +/** + * + * @author zhangjx + * @param T + */ +public class ProtobufStreamEncoder extends StreamEncoder { + + protected final boolean simple; + + + public ProtobufStreamEncoder(ConvertFactory factory, Type type) { + super(factory, type); + Type comtype = this.getComponentType(); + this.simple = Boolean.class == comtype || Short.class == comtype + || Character.class == comtype || Integer.class == comtype || Float.class == comtype + || Long.class == comtype || Double.class == comtype + || AtomicInteger.class == comtype || AtomicLong.class == comtype; + } + + @Override + protected void writeMemberValue(Writer out, EnMember member, Object item, boolean first) { + if (simple) { + if (item == null) { + ((ProtobufWriter) out).writeUInt32(0); + } else { + componentEncoder.convertTo(out, item); + } + return; + } + if (member != null) out.writeFieldName(member); + if (item instanceof CharSequence) { + componentEncoder.convertTo(out, item); + } else { + ProtobufWriter tmp = new ProtobufWriter().configFieldFunc(out); + componentEncoder.convertTo(tmp, item); + int length = tmp.count(); + ((ProtobufWriter) out).writeUInt32(length); + ((ProtobufWriter) out).writeTo(tmp.toArray()); + } + } +} diff --git a/src/main/java/org/redkale/convert/protobuf/ProtobufStreamReader.java b/src/main/java/org/redkale/convert/protobuf/ProtobufStreamReader.java new file mode 100644 index 000000000..3f18934e3 --- /dev/null +++ b/src/main/java/org/redkale/convert/protobuf/ProtobufStreamReader.java @@ -0,0 +1,52 @@ +/* + * 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.redkale.convert.protobuf; + +import java.io.*; +import org.redkale.convert.*; + +/** + * + * 详情见: https://redkale.org + * + * @author zhangjx + */ +class ProtobufStreamReader extends ProtobufByteBufferReader { + + private InputStream in; + + private byte currByte; + + protected ProtobufStreamReader(InputStream in) { + super((ConvertMask) null); + this.in = in; + } + + @Override + protected boolean recycle() { + super.recycle(); // this.position 初始化值为-1 + this.in = null; + this.currByte = 0; + return false; + } + + @Override + public byte nextByte() { + try { + byte b = (currByte = (byte) in.read()); + this.position++; + return b; + } catch (IOException e) { + throw new ConvertException(e); + } + } + + @Override + protected byte currentByte() { + return currByte; + } + +} diff --git a/src/main/java/org/redkale/convert/protobuf/ProtobufStreamWriter.java b/src/main/java/org/redkale/convert/protobuf/ProtobufStreamWriter.java new file mode 100644 index 000000000..74f6f3597 --- /dev/null +++ b/src/main/java/org/redkale/convert/protobuf/ProtobufStreamWriter.java @@ -0,0 +1,50 @@ +/* + * 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.redkale.convert.protobuf; + +import java.io.*; +import org.redkale.convert.ConvertException; + +/** + * + * 详情见: https://redkale.org + * + * @author zhangjx + */ +class ProtobufStreamWriter extends ProtobufByteBufferWriter { + + private OutputStream out; + + protected ProtobufStreamWriter(int features, boolean enumtostring, OutputStream out) { + super(features, enumtostring, null); + this.out = out; + } + + @Override + protected boolean recycle() { + super.recycle(); + this.out = null; + return false; + } + + @Override + public void writeTo(final byte[] chs, final int start, final int len) { + try { + out.write(chs, start, len); + } catch (IOException e) { + throw new ConvertException(e); + } + } + + @Override + public void writeTo(final byte ch) { + try { + out.write((byte) ch); + } catch (IOException e) { + throw new ConvertException(e); + } + } +} diff --git a/src/main/java/org/redkale/convert/protobuf/ProtobufWriter.java b/src/main/java/org/redkale/convert/protobuf/ProtobufWriter.java new file mode 100644 index 000000000..f67f46f52 --- /dev/null +++ b/src/main/java/org/redkale/convert/protobuf/ProtobufWriter.java @@ -0,0 +1,638 @@ +/* + * 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.redkale.convert.protobuf; + +import java.lang.reflect.Type; +import java.nio.ByteBuffer; +import java.util.*; +import java.util.concurrent.atomic.*; +import java.util.function.Consumer; +import java.util.stream.Stream; +import org.redkale.convert.*; +import org.redkale.util.*; + +/** + * + * @author zhangjx + */ +public class ProtobufWriter extends Writer implements ByteTuple { + + private static final int defaultSize = Integer.getInteger("convert.protobuf.writer.buffer.defsize", Integer.getInteger("convert.writer.buffer.defsize", 1024)); + + private byte[] content; + + protected int count; + + protected int initOffset; + + protected boolean enumtostring; + + protected ProtobufWriter parent; + + public static ObjectPool createPool(int max) { + return ObjectPool.createSafePool(max, (Object... params) -> new ProtobufWriter(), null, (t) -> t.recycle()); + } + + protected ProtobufWriter(ProtobufWriter parent, int features) { + this(); + this.parent = parent; + this.features = features; + if (parent != null) { + this.enumtostring = parent.enumtostring; + } + } + + protected ProtobufWriter(byte[] bs) { + this.content = bs; + } + + public ProtobufWriter withFeatures(int features) { + super.withFeatures(features); + return this; + } + + protected ProtobufWriter configFieldFunc(Writer writer) { + if (writer == null) { + return this; + } + ProtobufWriter out = (ProtobufWriter) writer; + this.mapFieldFunc = out.mapFieldFunc; + this.objFieldFunc = out.objFieldFunc; + this.objExtFunc = out.objExtFunc; + this.features = out.features; + this.enumtostring = out.enumtostring; + return this; + } + + public ProtobufWriter() { + this(defaultSize); + } + + public ProtobufWriter(int size) { + this.content = new byte[size > 128 ? size : 128]; + } + + public ProtobufWriter(ByteArray array) { + this.content = array.content(); + this.count = array.length(); + } + + @Override + protected boolean recycle() { + super.recycle(); + this.count = 0; + this.initOffset = 0; + if (this.content.length > defaultSize) { + this.content = new byte[defaultSize]; + } + return true; + } + + @Override + public byte[] content() { + return content; + } + + @Override + public int offset() { + return initOffset; + } + + @Override + public int length() { + return count; + } + + /** + * 将本对象的内容引用复制给array + * + * @param array ByteArray + */ + public void directTo(ByteArray array) { + array.directFrom(content, count); + } + + public ByteBuffer[] toBuffers() { + return new ByteBuffer[]{ByteBuffer.wrap(content, 0, count)}; + } + + /** + * 直接获取全部数据, 实际数据需要根据count长度来截取 + * + * @return byte[] + */ + public byte[] directBytes() { + return content; + } + + public void completed(ConvertBytesHandler handler, Consumer callback) { + handler.completed(content, 0, count, callback, this); + } + + public byte[] toArray() { + if (count == content.length) { + return content; + } + byte[] newdata = new byte[count]; + System.arraycopy(content, 0, newdata, 0, count); + return newdata; + } + + public ProtobufWriter enumtostring(boolean enumtostring) { + this.enumtostring = enumtostring; + return this; + } + + protected int expand(int len) { + int newcount = count + len; + if (newcount <= content.length) { + return 0; + } + byte[] newdata = new byte[Math.max(content.length * 3 / 2, newcount)]; + System.arraycopy(content, 0, newdata, 0, count); + this.content = newdata; + return 0; + } + + public void writeTo(final byte ch) { + expand(1); + content[count++] = ch; + } + + public final void writeTo(final byte... chs) { + writeTo(chs, 0, chs.length); + } + + public void writeTo(final byte[] chs, final int start, final int len) { + expand(len); + System.arraycopy(chs, start, content, count, len); + count += len; + } + + public ProtobufWriter clear() { + this.count = 0; + this.initOffset = 0; + return this; + } + + @Override + public String toString() { + return this.getClass().getSimpleName() + "[count=" + this.count + "]"; + } + + //------------------------------------------------------------------------ + public final int count() { + return this.count; + } + + @Override + public final void writeBoolean(boolean value) { + writeTo(value ? (byte) 1 : (byte) 0); + } + + @Override + public void writeNull() { + } + + @Override + public boolean needWriteClassName() { + return false; + } + + @Override + public void writeClassName(String clazz) { + } + + @Override + public int writeObjectB(Object obj) { + super.writeObjectB(obj); + return -1; + } + + @Override + public void writeObjectE(Object obj) { + if (parent != null) { + parent.writeUInt32(count()); + parent.writeTo(toArray()); + } + } + + @Override + public int writeArrayB(int size, Encodeable encoder, Encodeable componentEncoder, Object obj) { + if (obj == null) { + writeNull(); + return 0; + } else if (size < 1) { + //writeUInt32(0); + return 0; + } else if (obj instanceof byte[]) { + int length = ((byte[]) obj).length; + writeUInt32(length); + writeTo((byte[]) obj); + return length; + } else { + final Class type = obj.getClass(); + ProtobufWriter tmp = new ProtobufWriter().configFieldFunc(this); + if (type == boolean[].class) { + for (boolean item : (boolean[]) obj) { + tmp.writeBoolean(item); + } + } else if (type == Boolean[].class) { + for (Boolean item : (Boolean[]) obj) { + tmp.writeBoolean(item == null ? false : item); + } + } else if (type == short[].class) { + for (short item : (short[]) obj) { + tmp.writeShort(item); + } + } else if (type == Short[].class) { + for (Short item : (Short[]) obj) { + tmp.writeShort(item == null ? 0 : item); + } + } else if (type == char[].class) { + for (char item : (char[]) obj) { + tmp.writeChar(item); + } + } else if (type == Character[].class) { + for (Character item : (Character[]) obj) { + tmp.writeChar(item == null ? 0 : item); + } + } else if (type == int[].class) { + for (int item : (int[]) obj) { + tmp.writeInt(item); + } + } else if (type == Integer[].class) { + for (Integer item : (Integer[]) obj) { + tmp.writeInt(item == null ? 0 : item); + } + } else if (type == float[].class) { + for (float item : (float[]) obj) { + tmp.writeFloat(item); + } + } else if (type == Float[].class) { + for (Float item : (Float[]) obj) { + tmp.writeFloat(item == null ? 0F : item); + } + } else if (type == long[].class) { + for (long item : (long[]) obj) { + tmp.writeLong(item); + } + } else if (type == Long[].class) { + for (Long item : (Long[]) obj) { + tmp.writeLong(item == null ? 0L : item); + } + } else if (type == double[].class) { + for (double item : (double[]) obj) { + tmp.writeDouble(item); + } + } else if (type == Double[].class) { + for (Double item : (Double[]) obj) { + tmp.writeDouble(item == null ? 0D : item); + } + } else if (type == AtomicInteger[].class) { + for (AtomicInteger item : (AtomicInteger[]) obj) { + tmp.writeInt(item == null ? 0 : item.get()); + } + } else if (type == AtomicLong[].class) { + for (AtomicLong item : (AtomicLong[]) obj) { + tmp.writeLong(item == null ? 0L : item.get()); + } + } else if (encoder instanceof ProtobufCollectionDecoder) { + ProtobufCollectionDecoder listEncoder = (ProtobufCollectionDecoder) encoder; + Type componentType = listEncoder.getComponentType(); + if (listEncoder.simple) { + if (componentType == Boolean.class) { + for (Boolean item : (Collection) obj) { + tmp.writeBoolean(item); + } + } else if (componentType == Short.class) { + for (Short item : (Collection) obj) { + tmp.writeShort(item); + } + } else if (componentType == Integer.class) { + for (Integer item : (Collection) obj) { + tmp.writeInt(item); + } + } else if (componentType == Float.class) { + for (Float item : (Collection) obj) { + tmp.writeFloat(item); + } + } else if (componentType == Long.class) { + for (Long item : (Collection) obj) { + tmp.writeLong(item); + } + } else if (componentType == Double.class) { + for (Double item : (Collection) obj) { + tmp.writeDouble(item); + } + } else if (componentType == Long.class) { + for (Long item : (Collection) obj) { + tmp.writeLong(item); + } + } else if (componentType == AtomicInteger.class) { + for (AtomicInteger item : (Collection) obj) { + tmp.writeInt(item == null ? 0 : item.get()); + } + } else if (componentType == AtomicLong.class) { + for (AtomicLong item : (Collection) obj) { + tmp.writeLong(item == null ? 0L : item.get()); + } + } + } else { + return -1; + } + } else if (encoder instanceof ProtobufStreamDecoder) { + ProtobufStreamDecoder streamEncoder = (ProtobufStreamDecoder) encoder; + Type componentType = streamEncoder.getComponentType(); + if (streamEncoder.simple) { + if (componentType == Boolean.class) { + ((Stream) obj).forEach(item -> tmp.writeBoolean(item)); + } else if (componentType == Short.class) { + ((Stream) obj).forEach(item -> tmp.writeShort(item)); + } else if (componentType == Integer.class) { + ((Stream) obj).forEach(item -> tmp.writeInt(item)); + } else if (componentType == Float.class) { + ((Stream) obj).forEach(item -> tmp.writeFloat(item)); + } else if (componentType == Long.class) { + ((Stream) obj).forEach(item -> tmp.writeLong(item)); + } else if (componentType == Double.class) { + ((Stream) obj).forEach(item -> tmp.writeDouble(item)); + } else if (componentType == AtomicInteger.class) { + ((Stream) obj).forEach(item -> tmp.writeInt(item == null ? 0 : item.get())); + } else if (componentType == AtomicLong.class) { + ((Stream) obj).forEach(item -> tmp.writeLong(item == null ? 0L : item.get())); + } + } else { + return -1; + } + } else { + return -1; + } + int length = tmp.count(); + writeUInt32(length); + writeTo(tmp.toArray()); + return length; + } + } + + @Override + public void writeArrayMark() { + } + + @Override + public void writeArrayE() { + } + + @Override + public int writeMapB(int size, Encodeable keyEncoder, Encodeable valueEncoder, Object obj) { + return -1; + } + + @Override + public void writeMapMark() { + } + + @Override + public void writeMapE() { + } + + @Override + public void writeFieldName(EnMember member, String fieldName, Type fieldType, int fieldPos) { + int tag = ProtobufFactory.getTag(fieldName, fieldType, fieldPos, enumtostring); + writeUInt32(tag); + } + + @Override + public void writeObjectField(final EnMember member, Object obj) { + Object value; + if (objFieldFunc == null) { + value = member.getAttribute().get(obj); + } else { + value = objFieldFunc.apply(member.getAttribute(), obj); + } + if (value == null) { + this.writeFieldName(member); + writeNull(); + return; + } + if (tiny()) { + if (member.isStringType()) { + if (((CharSequence) value).length() == 0) { + return; + } + } else if (member.isBoolType()) { + if (!((Boolean) value)) { + return; + } + } + } + Type mtype = member.getAttribute().type(); + if (mtype == boolean[].class && ((boolean[]) value).length < 1) { + return; + } + if (mtype == byte[].class && ((byte[]) value).length < 1) { + return; + } + if (mtype == short[].class && ((short[]) value).length < 1) { + return; + } + if (mtype == char[].class && ((char[]) value).length < 1) { + return; + } + if (mtype == int[].class && ((int[]) value).length < 1) { + return; + } + if (mtype == float[].class && ((float[]) value).length < 1) { + return; + } + if (mtype == long[].class && ((long[]) value).length < 1) { + return; + } + if (mtype == double[].class && ((double[]) value).length < 1) { + return; + } + + Encodeable encoder = member.getEncoder(); + if (encoder == null) { + return; + } + if (encoder instanceof MapEncoder) { + if (!((Map) value).isEmpty()) { + ((MapEncoder) encoder).convertTo(this, member, (Map) value); + } + } else if (encoder instanceof ProtobufArrayEncoder) { + ProtobufArrayEncoder arrayEncoder = (ProtobufArrayEncoder) encoder; + if (arrayEncoder.simple) { + if (((Object[]) value).length < 1) { + this.writeFieldName(member); + ProtobufWriter tmp = new ProtobufWriter().configFieldFunc(this); + arrayEncoder.convertTo(tmp, member, (Object[]) value); + //int length = tmp.count(); + //this.writeUInt32(length); + this.writeTo(tmp.toArray()); + } + } else { + arrayEncoder.convertTo(this, member, (Object[]) value); + } + } else if (encoder instanceof ProtobufCollectionEncoder) { + ProtobufCollectionEncoder collectionEncoder = (ProtobufCollectionEncoder) encoder; + if (collectionEncoder.simple) { + if (!((Collection) value).isEmpty()) { + this.writeFieldName(member); + ProtobufWriter tmp = new ProtobufWriter().configFieldFunc(this); + collectionEncoder.convertTo(tmp, member, (Collection) value); + int length = tmp.count(); + this.writeUInt32(length); + this.writeTo(tmp.toArray()); + } + } else { + collectionEncoder.convertTo(this, member, (Collection) value); + } + } else if (encoder instanceof ProtobufStreamEncoder) { + ProtobufStreamEncoder streamEncoder = (ProtobufStreamEncoder) encoder; + if (streamEncoder.simple) { + this.writeFieldName(member); + ProtobufWriter tmp = new ProtobufWriter().configFieldFunc(this); + streamEncoder.convertTo(tmp, member, (Stream) value); + int length = tmp.count(); + this.writeUInt32(length); + this.writeTo(tmp.toArray()); + } else { + streamEncoder.convertTo(this, member, (Stream) value); + } + } else { + this.writeFieldName(member); + encoder.convertTo(this, value); + } + this.comma = true; + } + + @Override + public void writeByte(byte value) { + writeInt(value); + } + + @Override + public final void writeByteArray(byte[] values) { + if (values == null) { + writeNull(); + return; + } + if (writeArrayB(values.length, null, null, values) < 0) { + boolean flag = false; + for (byte v : values) { + if (flag) { + writeArrayMark(); + } + writeByte(v); + flag = true; + } + } + writeArrayE(); + } + + @Override + public void writeChar(char value) { + writeInt(value); + } + + @Override + public void writeShort(short value) { + writeInt(value); + } + + @Override + public void writeInt(int value) { //writeSInt32 + writeUInt32((value << 1) ^ (value >> 31)); + } + + @Override + public void writeLong(long value) { //writeSInt64 + writeUInt64((value << 1) ^ (value >> 63)); + } + + @Override + public void writeFloat(float value) { + writeFixed32(Float.floatToRawIntBits(value)); + } + + @Override + public void writeDouble(double value) { + writeFixed64(Double.doubleToRawLongBits(value)); + } + + @Override + public void writeSmallString(String value) { + writeString(value); + } + + @Override + public void writeString(String value) { + byte[] bs = Utility.isLatin1(value) ? Utility.latin1ByteArray(value) : Utility.encodeUTF8(value); + writeUInt32(bs.length); + writeTo(bs); + } + + @Override + public void writeWrapper(StringWrapper value) { + if (value != null) { + writeString(value.getValue()); + } + } + + public static byte[] uint32(int value) { + byte[] bs = new byte[8]; + int pos = 0; + while (true) { + if ((value & ~0x7F) == 0) { + bs[pos++] = ((byte) value); + return pos == bs.length ? bs : Arrays.copyOf(bs, pos); + } else { + bs[pos++] = ((byte) ((value & 0x7F) | 0x80)); + value >>>= 7; + } + } + } + + protected void writeUInt32(int value) { + while (true) { + if ((value & ~0x7F) == 0) { + writeTo((byte) value); + return; + } else { + writeTo((byte) ((value & 0x7F) | 0x80)); + value >>>= 7; + } + } + } + + protected void writeUInt64(long value) { + while (true) { + if ((value & ~0x7FL) == 0) { + writeTo((byte) value); + return; + } else { + writeTo((byte) (((int) value & 0x7F) | 0x80)); + value >>>= 7; + } + } + } + + protected void writeFixed32(int value) { + writeTo((byte) (value & 0xFF), (byte) ((value >> 8) & 0xFF), (byte) ((value >> 16) & 0xFF), (byte) ((value >> 24) & 0xFF)); + } + + protected void writeFixed64(long value) { + writeTo((byte) ((int) (value) & 0xFF), + (byte) ((int) (value >> 8) & 0xFF), + (byte) ((int) (value >> 16) & 0xFF), + (byte) ((int) (value >> 24) & 0xFF), + (byte) ((int) (value >> 32) & 0xFF), + (byte) ((int) (value >> 40) & 0xFF), + (byte) ((int) (value >> 48) & 0xFF), + (byte) ((int) (value >> 56) & 0xFF)); + } +} diff --git a/src/main/java/org/redkale/mq/MessageConsumer.java b/src/main/java/org/redkale/mq/MessageConsumer.java index d835144ac..c006af927 100644 --- a/src/main/java/org/redkale/mq/MessageConsumer.java +++ b/src/main/java/org/redkale/mq/MessageConsumer.java @@ -25,7 +25,7 @@ public interface MessageConsumer { default void init(AnyValue config) { } - public void onMessage(String topic, T[] messages); + public void onMessage(String topic, Integer partition, T[] messages); default void destroy(AnyValue config) { } diff --git a/src/main/java/org/redkale/mq/MessageProducer.java b/src/main/java/org/redkale/mq/MessageProducer.java index 790880278..fbbfc73a1 100644 --- a/src/main/java/org/redkale/mq/MessageProducer.java +++ b/src/main/java/org/redkale/mq/MessageProducer.java @@ -19,13 +19,26 @@ import org.redkale.convert.Convert; */ public interface MessageProducer { - public CompletableFuture sendMessage(String topic, Object value); + public CompletableFuture sendMessage(String topic, Integer partition, Convert convert, Type type, Object value); - default CompletableFuture sendMessage(String topic, Convert convert, Object value) { - return sendMessage(topic, convert.convertToBytes(value)); + default CompletableFuture sendMessage(String topic, Integer partition, Convert convert, Object value) { + return sendMessage(topic, partition, convert, (Type) null, value); + } + + default CompletableFuture sendMessage(String topic, Integer partition, Object value) { + return sendMessage(topic, partition, (Convert) null, (Type) null, value); } default CompletableFuture sendMessage(String topic, Convert convert, Type type, Object value) { - return sendMessage(topic, convert.convertToBytes(type, value)); + return sendMessage(topic, (Integer) null, convert, type, value); } + + default CompletableFuture sendMessage(String topic, Convert convert, Object value) { + return sendMessage(topic, (Integer) null, convert, value); + } + + default CompletableFuture sendMessage(String topic, Object value) { + return sendMessage(topic, (Integer) null, value); + } + } diff --git a/src/main/java/org/redkale/source/ColumnValue.java b/src/main/java/org/redkale/source/ColumnValue.java index 5237994ce..6c3db1732 100644 --- a/src/main/java/org/redkale/source/ColumnValue.java +++ b/src/main/java/org/redkale/source/ColumnValue.java @@ -7,6 +7,7 @@ package org.redkale.source; import java.io.Serializable; import java.util.Objects; +import org.redkale.convert.ConvertColumn; import static org.redkale.source.ColumnExpress.*; import org.redkale.util.*; @@ -22,10 +23,13 @@ import org.redkale.util.*; */ public class ColumnValue { + @ConvertColumn(index = 1) private String column; + @ConvertColumn(index = 2) private ColumnExpress express; + @ConvertColumn(index = 3) private Serializable value; public ColumnValue() { diff --git a/src/test/java/org/redkale/test/convert/protobuf/ArrayBean.java b/src/test/java/org/redkale/test/convert/protobuf/ArrayBean.java new file mode 100644 index 000000000..83d0cb415 --- /dev/null +++ b/src/test/java/org/redkale/test/convert/protobuf/ArrayBean.java @@ -0,0 +1,59 @@ +/* + * 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.redkale.test.convert.protobuf; + +import java.util.*; +import org.redkale.util.Utility; +import org.redkale.convert.protobuf.ProtobufConvert; + +/** + * + * @author zhangjx + */ +public class ArrayBean { + + public static class IntArrayBean { + + public int[] values1; + } + + public static class IntListBean { + + public List values2; + } + + public static class IntegerArrayBean { + + public Integer[] values3; + } + + public static void main(String[] args) throws Throwable { + IntArrayBean bean1 = new IntArrayBean(); + bean1.values1 = new int[]{2, 3, 4}; + IntListBean bean2 = new IntListBean(); + bean2.values2 = Utility.ofList(2, 3, 4); + IntegerArrayBean bean3 = new IntegerArrayBean(); + bean3.values3 = new Integer[]{2, 3, 4}; + byte[] bs1 = ProtobufConvert.root().convertTo(bean1); + byte[] bs2 = ProtobufConvert.root().convertTo(bean2); + byte[] bs3 = ProtobufConvert.root().convertTo(bean3); + if (!Arrays.equals(bs1, bs2)) { + Utility.println("int数组: ", bs1); + Utility.println("int列表: ", bs2); + } else if (!Arrays.equals(bs1, bs3)) { + Utility.println("int数组: ", bs1); + Utility.println("int集合: ", bs3); + } else { + System.out.println("两者相同"); + } + IntArrayBean bean11 = ProtobufConvert.root().convertFrom(IntArrayBean.class, bs1); + IntListBean bean22 = ProtobufConvert.root().convertFrom(IntListBean.class, bs2); + IntegerArrayBean bean33 = ProtobufConvert.root().convertFrom(IntegerArrayBean.class, bs3); + System.out.println(Arrays.toString(bean11.values1)); + System.out.println(bean22.values2); + System.out.println(Arrays.toString(bean33.values3)); + } +} diff --git a/src/test/java/org/redkale/test/convert/protobuf/PBCustMessage2Test.java b/src/test/java/org/redkale/test/convert/protobuf/PBCustMessage2Test.java new file mode 100644 index 000000000..31ea82c88 --- /dev/null +++ b/src/test/java/org/redkale/test/convert/protobuf/PBCustMessage2Test.java @@ -0,0 +1,231 @@ +/* + */ +package org.redkale.test.convert.protobuf; + +import org.redkale.convert.protobuf.ProtobufObjectEncoder; +import org.redkale.convert.protobuf.ProtobufReader; +import org.redkale.convert.protobuf.ProtobufObjectDecoder; +import org.redkale.convert.protobuf.ProtobufConvert; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; +import java.lang.annotation.*; +import java.util.Arrays; +import java.util.function.*; +import org.junit.jupiter.api.*; +import org.redkale.convert.*; +import org.redkale.convert.json.JsonConvert; +import org.redkale.util.*; + +/** + * + * @author zhangjx + */ +@SuppressWarnings("unchecked") +public class PBCustMessage2Test { + + private boolean main; + + public static void main(String[] args) throws Throwable { + PBCustMessage2Test test = new PBCustMessage2Test(); + test.main = true; + test.run(); + } + + @Test + public void run() throws Exception { + final BiFunction objFieldFunc = (Attribute t, Object u) -> { + if (t.field().equals("retinfo")) return null; + return t.get(u); + }; + OnPlayerLeaveMessage msg1 = new OnPlayerLeaveMessage(100, "haha"); + byte[] bs1 = ProtobufConvert.root().convertTo(msg1); + OnPlayerLeaveMessage2 msg2 = new OnPlayerLeaveMessage2(100, "haha"); + byte[] bs2 = ProtobufConvert.root().convertTo(msg2); + System.out.println(Arrays.toString(bs1)); + System.out.println(Arrays.toString(bs2)); + if (!main) Assertions.assertEquals(Arrays.toString(bs1), Arrays.toString(bs2)); + System.out.println(); + + OnPlayerLeaveMessage2 newmsg2 = ProtobufConvert.root().convertFrom(OnPlayerLeaveMessage2.class, bs1); + byte[] newbs2 = ProtobufConvert.root().convertTo(newmsg2); + System.out.println(Arrays.toString(newbs2)); + if (!main) Assertions.assertEquals(Arrays.toString(bs1), Arrays.toString(newbs2)); + System.out.println(); + + ProtobufConvert convert = ProtobufConvert.root().newConvert(objFieldFunc); + System.out.println(Arrays.toString(convert.convertTo(msg1))); + System.out.println(Arrays.toString(convert.convertTo(msg2))); + if (!main) Assertions.assertEquals(Arrays.toString(convert.convertTo(msg1)), Arrays.toString(convert.convertTo(msg2))); + System.out.println(); + } + + public static interface BaseMessage { + + @Inherited + @Documented + @Target({TYPE}) + @Retention(RUNTIME) + public @interface MessageName { + + String value(); + } + + public static String getMessageName(Class clazz) { + MessageName mn = clazz.getAnnotation(MessageName.class); + if (mn != null) return mn.value(); + char[] fieldChars = clazz.getSimpleName().toCharArray(); + fieldChars[0] = Character.toLowerCase(fieldChars[0]); + return new String(fieldChars); + } + + public static Encodeable createConvertEnCoder(final ConvertFactory factory, final Class clazz) { + Encodeable valEncoder = factory.createEncoder(clazz, true); + final String eventName = getMessageName(clazz); + ObjectEncoder encoder = new ProtobufObjectEncoder< BaseMessage>(clazz) { + @Override + protected void afterInitEnMember(ConvertFactory factory) { + Function func1 = t -> eventName; + Attribute attribute1 = Attribute.create(clazz, "event", String.class, func1, null); + EnMember member1 = new EnMember(attribute1, factory.loadEncoder(String.class), null, null); + setIndex(member1, 1); + setPosition(member1, 1); + initForEachEnMember(factory, member1); + + Function func2 = t -> t; + Attribute attribute2 = Attribute.create(clazz, "data", clazz, func2, null); + EnMember member2 = new EnMember(attribute2, valEncoder, null, null); + setIndex(member2, 2); + setPosition(member2, 2); + initForEachEnMember(factory, member2); + this.members = new EnMember[]{member1, member2}; + } + }; + encoder.init(factory); + return encoder; + } + + public static Decodeable createConvertDeCoder(final ConvertFactory factory, final Class clazz) { + Decodeable valDecoder = factory.createDecoder(clazz, true); + final String eventName = getMessageName(clazz); + ObjectDecoder decoder = new ProtobufObjectDecoder< BaseMessage>(clazz) { + @Override + protected void afterInitDeMember(ConvertFactory factory) { + Function func1 = t -> eventName; + Attribute attribute1 = Attribute.create(clazz, "event", String.class, func1, null); + DeMember member1 = new DeMember(attribute1, factory.loadDecoder(String.class), null, null); + setIndex(member1, 1); + setPosition(member1, 1); + initForEachDeMember(factory, member1); + + this.creator = (Creator) objs -> new Object[1]; + Function func2 = t -> t; + BiConsumer consumer2 = (t, v) -> ((Object[]) t)[0] = v; + Attribute attribute2 = Attribute.create(clazz, "data", clazz, func2, consumer2); + DeMember member2 = new DeMember(attribute2, valDecoder, null, null); + setIndex(member2, 2); + setPosition(member2, 2); + initForEachDeMember(factory, member2); + this.members = new DeMember[]{member1, member2}; + } + + @Override + public BaseMessage convertFrom(ProtobufReader in) { + Object result = (Object) super.convertFrom(in); + return (BaseMessage) ((Object[]) result)[0]; + } + }; + decoder.init(factory); + return decoder; + } + + } + + @BaseMessage.MessageName("onPlayerLeaveMessage") + public static class OnPlayerLeaveMessage2 implements BaseMessage { + + @ConvertColumn(index = 1) + public int userid; + + @ConvertColumn(index = 2) + public String retinfo; + + public OnPlayerLeaveMessage2() { + } + + public OnPlayerLeaveMessage2(int userid, String retinfo) { + this.userid = userid; + this.retinfo = retinfo; + } + + @Override + public String toString() { + return JsonConvert.root().convertTo(this); + } + } + + public static class OnPlayerLeaveMessage { + + private String event = "onPlayerLeaveMessage"; + + private OnPlayerLeaveContent result; + + public OnPlayerLeaveMessage() { + } + + public OnPlayerLeaveMessage(int userid) { + this.result = new OnPlayerLeaveContent(userid); + } + + public OnPlayerLeaveMessage(int userid, String retinfo) { + this.result = new OnPlayerLeaveContent(userid, retinfo); + } + + public String getEvent() { + return event; + } + + public void setEvent(String event) { + this.event = event; + } + + public OnPlayerLeaveContent getResult() { + return result; + } + + public void setResult(OnPlayerLeaveContent result) { + this.result = result; + } + + public static class OnPlayerLeaveContent { + + @ConvertColumn(index = 1) + public int userid; + + @ConvertColumn(index = 2) + public String retinfo; + + public OnPlayerLeaveContent() { + } + + public OnPlayerLeaveContent(int userid) { + this.userid = userid; + } + + public OnPlayerLeaveContent(int userid, String retinfo) { + this.userid = userid; + this.retinfo = retinfo; + } + + @Override + public String toString() { + return JsonConvert.root().convertTo(this); + } + } + + @Override + public String toString() { + return JsonConvert.root().convertTo(this); + } + } + +} diff --git a/src/test/java/org/redkale/test/convert/protobuf/PBCustMessageTest.java b/src/test/java/org/redkale/test/convert/protobuf/PBCustMessageTest.java new file mode 100644 index 000000000..77f3d5f45 --- /dev/null +++ b/src/test/java/org/redkale/test/convert/protobuf/PBCustMessageTest.java @@ -0,0 +1,204 @@ +/* + */ +package org.redkale.test.convert.protobuf; + +import org.redkale.convert.protobuf.ProtobufObjectEncoder; +import org.redkale.convert.protobuf.ProtobufReader; +import org.redkale.convert.protobuf.ProtobufFactory; +import org.redkale.convert.protobuf.ProtobufObjectDecoder; +import org.redkale.convert.protobuf.ProtobufConvert; +import java.lang.annotation.*; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; +import java.util.*; +import java.util.function.*; +import org.junit.jupiter.api.*; +import org.redkale.convert.*; +import org.redkale.convert.json.JsonConvert; +import org.redkale.util.*; + +/** + * + * @author zhangjx + */ +public class PBCustMessageTest { + + private boolean main; + + public static void main(String[] args) throws Throwable { + PBCustMessageTest test = new PBCustMessageTest(); + test.main = true; + test.run(); + } + + @Test + public void run() throws Exception { + final BiFunction objFieldFunc = (Attribute t, Object u) -> { + if (t.field().equals("retinfo")) return null; + return t.get(u); + }; + OnPlayerLeaveMessage msg1 = new OnPlayerLeaveMessage(100, "haha"); + byte[] bs1 = ProtobufConvert.root().convertTo(msg1); + OnPlayerLeaveMessage2 msg2 = new OnPlayerLeaveMessage2(100, "haha"); + byte[] bs2 = ProtobufConvert.root().convertTo(msg2); + System.out.println(Arrays.toString(bs1)); + System.out.println(Arrays.toString(bs2)); + if (!main) Assertions.assertEquals(Arrays.toString(bs1), Arrays.toString(bs2)); + System.out.println(); + + OnPlayerLeaveMessage2 newmsg2 = ProtobufConvert.root().convertFrom(OnPlayerLeaveMessage2.class, bs1); + byte[] newbs2 = ProtobufConvert.root().convertTo(newmsg2); + System.out.println(Arrays.toString(newbs2)); + if (!main) Assertions.assertEquals(Arrays.toString(bs1), Arrays.toString(newbs2)); + System.out.println(); + + ProtobufConvert convert = ProtobufConvert.root().newConvert(objFieldFunc); + System.out.println(Arrays.toString(convert.convertTo(msg1))); + System.out.println(Arrays.toString(convert.convertTo(msg2))); + if (!main) Assertions.assertEquals(Arrays.toString(convert.convertTo(msg1)), Arrays.toString(convert.convertTo(msg2))); + System.out.println(); + } + + public static interface BaseMessage { + + @Inherited + @Documented + @Target({TYPE}) + @Retention(RUNTIME) + public @interface MessageName { + + String value(); + } + + public static String getMessageName(Class clazz) { + MessageName mn = clazz.getAnnotation(MessageName.class); + if (mn != null) return mn.value(); + char[] fieldChars = clazz.getSimpleName().toCharArray(); + fieldChars[0] = Character.toLowerCase(fieldChars[0]); + return new String(fieldChars); + } + + public static Encodeable createConvertCoder(ProtobufFactory factory, Class clazz) { + Encodeable valEncoder = factory.createEncoder(clazz, true); + ObjectEncoder encoder = new ProtobufObjectEncoder< BaseMessage>(clazz) { + @Override + protected void afterInitEnMember(ConvertFactory factory) { + Function func = t -> t; + Attribute attribute = Attribute.create(clazz, getMessageName(clazz), clazz, func, null); + EnMember member = new EnMember(attribute, valEncoder, null, null); + setIndex(member, 1); + setPosition(member, 1); + initForEachEnMember(factory, member); + this.members = new EnMember[]{member}; + } + }; + encoder.init(factory); + return encoder; + } + + public static Decodeable createConvertDeCoder(ProtobufFactory factory, Class clazz) { + Decodeable valDecoder = factory.createDecoder(clazz, true); + ObjectDecoder decoder = new ProtobufObjectDecoder< BaseMessage>(clazz) { + @Override + protected void afterInitDeMember(ConvertFactory factory) { + this.creator = (Creator) objs -> new Object[1]; + Function func = t -> t; + BiConsumer consumer = (t, v) -> ((Object[]) t)[0] = v; + Attribute attribute = Attribute.create(clazz, getMessageName(clazz), clazz, func, consumer); + DeMember member = new DeMember(attribute, valDecoder, null, null); + setIndex(member, 1); + setPosition(member, 1); + initForEachDeMember(factory, member); + this.members = new DeMember[]{member}; + } + + @Override + public BaseMessage convertFrom(ProtobufReader in) { + Object result = (Object) super.convertFrom(in); + return (BaseMessage) ((Object[]) result)[0]; + } + }; + decoder.init(factory); + return decoder; + } + } + + @BaseMessage.MessageName("onPlayerLeaveMessage") + public static class OnPlayerLeaveMessage2 implements BaseMessage { + + @ConvertColumn(index = 1) + public int userid; + + @ConvertColumn(index = 2) + public String retinfo; + + public OnPlayerLeaveMessage2() { + } + + public OnPlayerLeaveMessage2(int userid, String retinfo) { + this.userid = userid; + this.retinfo = retinfo; + } + + @Override + public String toString() { + return JsonConvert.root().convertTo(this); + } + } + + public static class OnPlayerLeaveMessage { + + private OnPlayerLeaveContent onPlayerLeaveMessage; + + public OnPlayerLeaveMessage() { + } + + public OnPlayerLeaveMessage(int userid) { + this.onPlayerLeaveMessage = new OnPlayerLeaveContent(userid); + } + + public OnPlayerLeaveMessage(int userid, String retinfo) { + this.onPlayerLeaveMessage = new OnPlayerLeaveContent(userid, retinfo); + } + + public OnPlayerLeaveContent getOnPlayerLeaveMessage() { + return onPlayerLeaveMessage; + } + + public void setOnPlayerLeaveMessage(OnPlayerLeaveContent onPlayerLeaveMessage) { + this.onPlayerLeaveMessage = onPlayerLeaveMessage; + } + + public static class OnPlayerLeaveContent { + + @ConvertColumn(index = 1) + public int userid; + + @ConvertColumn(index = 2) + public String retinfo; + + public OnPlayerLeaveContent() { + } + + public OnPlayerLeaveContent(int userid) { + this.userid = userid; + } + + public OnPlayerLeaveContent(int userid, String retinfo) { + this.userid = userid; + this.retinfo = retinfo; + } + + @Override + public String toString() { + return JsonConvert.root().convertTo(this); + } + } + + @Override + public String toString() { + return JsonConvert.root().convertTo(this); + } + } + +} diff --git a/src/test/java/org/redkale/test/convert/protobuf/PSimpleBean.proto b/src/test/java/org/redkale/test/convert/protobuf/PSimpleBean.proto new file mode 100644 index 000000000..3b3314551 --- /dev/null +++ b/src/test/java/org/redkale/test/convert/protobuf/PSimpleBean.proto @@ -0,0 +1,21 @@ +syntax = "proto3"; + +// 生成类的包名 +option java_package = "org.redkalex.test.protobuf"; + +message PSimpleBean { + + message PSimpleEntry { + sint32 id = 1; + string name = 2; + string email = 3; + } + + message PTwoEntry { + sint32 status = 1; + sint64 createtime = 2; + } + PSimpleEntry simple = 1; + PTwoEntry two = 2; + string strings = 3 ; +} diff --git a/src/test/java/org/redkale/test/convert/protobuf/PSimpleBeanOuterClass.java b/src/test/java/org/redkale/test/convert/protobuf/PSimpleBeanOuterClass.java new file mode 100644 index 000000000..ac4e8f08c --- /dev/null +++ b/src/test/java/org/redkale/test/convert/protobuf/PSimpleBeanOuterClass.java @@ -0,0 +1,2342 @@ +package org.redkale.test.convert.protobuf; + +//// Generated by the protocol buffer compiler. DO NOT EDIT! +//// source: src/test/java/org/redkalex/test/protobuf/PSimpleBean.proto +// +//package org.redkalex.test.protobuf; +// +//public final class PSimpleBeanOuterClass { +// private PSimpleBeanOuterClass() {} +// public static void registerAllExtensions( +// com.google.protobuf.ExtensionRegistryLite registry) { +// } +// +// public static void registerAllExtensions( +// com.google.protobuf.ExtensionRegistry registry) { +// registerAllExtensions( +// (com.google.protobuf.ExtensionRegistryLite) registry); +// } +// public interface PSimpleBeanOrBuilder extends +// // @@protoc_insertion_point(interface_extends:PSimpleBean) +// com.google.protobuf.MessageOrBuilder { +// +// /** +// * .PSimpleBean.PSimpleEntry simple = 1; +// * @return Whether the simple field is set. +// */ +// boolean hasSimple(); +// /** +// * .PSimpleBean.PSimpleEntry simple = 1; +// * @return The simple. +// */ +// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry getSimple(); +// /** +// * .PSimpleBean.PSimpleEntry simple = 1; +// */ +// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntryOrBuilder getSimpleOrBuilder(); +// +// /** +// * .PSimpleBean.PTwoEntry two = 2; +// * @return Whether the two field is set. +// */ +// boolean hasTwo(); +// /** +// * .PSimpleBean.PTwoEntry two = 2; +// * @return The two. +// */ +// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry getTwo(); +// /** +// * .PSimpleBean.PTwoEntry two = 2; +// */ +// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntryOrBuilder getTwoOrBuilder(); +// +// /** +// * string strings = 3; +// * @return The strings. +// */ +// java.lang.String getStrings(); +// /** +// * string strings = 3; +// * @return The bytes for strings. +// */ +// com.google.protobuf.ByteString +// getStringsBytes(); +// } +// /** +// * Protobuf type {@code PSimpleBean} +// */ +// public static final class PSimpleBean extends +// com.google.protobuf.GeneratedMessageV3 implements +// // @@protoc_insertion_point(message_implements:PSimpleBean) +// PSimpleBeanOrBuilder { +// private static final long serialVersionUID = 0L; +// // Use PSimpleBean.newBuilder() to construct. +// private PSimpleBean(com.google.protobuf.GeneratedMessageV3.Builder builder) { +// super(builder); +// } +// private PSimpleBean() { +// strings_ = ""; +// } +// +// @java.lang.Override +// @SuppressWarnings({"unused"}) +// protected java.lang.Object newInstance( +// UnusedPrivateParameter unused) { +// return new PSimpleBean(); +// } +// +// public static final com.google.protobuf.Descriptors.Descriptor +// getDescriptor() { +// return org.redkalex.test.protobuf.PSimpleBeanOuterClass.internal_static_PSimpleBean_descriptor; +// } +// +// @java.lang.Override +// protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable +// internalGetFieldAccessorTable() { +// return org.redkalex.test.protobuf.PSimpleBeanOuterClass.internal_static_PSimpleBean_fieldAccessorTable +// .ensureFieldAccessorsInitialized( +// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.class, org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.Builder.class); +// } +// +// public interface PSimpleEntryOrBuilder extends +// // @@protoc_insertion_point(interface_extends:PSimpleBean.PSimpleEntry) +// com.google.protobuf.MessageOrBuilder { +// +// /** +// * sint32 id = 1; +// * @return The id. +// */ +// int getId(); +// +// /** +// * string name = 2; +// * @return The name. +// */ +// java.lang.String getName(); +// /** +// * string name = 2; +// * @return The bytes for name. +// */ +// com.google.protobuf.ByteString +// getNameBytes(); +// +// /** +// * string email = 3; +// * @return The email. +// */ +// java.lang.String getEmail(); +// /** +// * string email = 3; +// * @return The bytes for email. +// */ +// com.google.protobuf.ByteString +// getEmailBytes(); +// } +// /** +// * Protobuf type {@code PSimpleBean.PSimpleEntry} +// */ +// public static final class PSimpleEntry extends +// com.google.protobuf.GeneratedMessageV3 implements +// // @@protoc_insertion_point(message_implements:PSimpleBean.PSimpleEntry) +// PSimpleEntryOrBuilder { +// private static final long serialVersionUID = 0L; +// // Use PSimpleEntry.newBuilder() to construct. +// private PSimpleEntry(com.google.protobuf.GeneratedMessageV3.Builder builder) { +// super(builder); +// } +// private PSimpleEntry() { +// name_ = ""; +// email_ = ""; +// } +// +// @java.lang.Override +// @SuppressWarnings({"unused"}) +// protected java.lang.Object newInstance( +// UnusedPrivateParameter unused) { +// return new PSimpleEntry(); +// } +// +// public static final com.google.protobuf.Descriptors.Descriptor +// getDescriptor() { +// return org.redkalex.test.protobuf.PSimpleBeanOuterClass.internal_static_PSimpleBean_PSimpleEntry_descriptor; +// } +// +// @java.lang.Override +// protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable +// internalGetFieldAccessorTable() { +// return org.redkalex.test.protobuf.PSimpleBeanOuterClass.internal_static_PSimpleBean_PSimpleEntry_fieldAccessorTable +// .ensureFieldAccessorsInitialized( +// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry.class, org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry.Builder.class); +// } +// +// public static final int ID_FIELD_NUMBER = 1; +// private int id_ = 0; +// /** +// * sint32 id = 1; +// * @return The id. +// */ +// @java.lang.Override +// public int getId() { +// return id_; +// } +// +// public static final int NAME_FIELD_NUMBER = 2; +// @SuppressWarnings("serial") +// private volatile java.lang.Object name_ = ""; +// /** +// * string name = 2; +// * @return The name. +// */ +// @java.lang.Override +// public java.lang.String getName() { +// java.lang.Object ref = name_; +// if (ref instanceof java.lang.String) { +// return (java.lang.String) ref; +// } else { +// com.google.protobuf.ByteString bs = +// (com.google.protobuf.ByteString) ref; +// java.lang.String s = bs.toStringUtf8(); +// name_ = s; +// return s; +// } +// } +// /** +// * string name = 2; +// * @return The bytes for name. +// */ +// @java.lang.Override +// public com.google.protobuf.ByteString +// getNameBytes() { +// java.lang.Object ref = name_; +// if (ref instanceof java.lang.String) { +// com.google.protobuf.ByteString b = +// com.google.protobuf.ByteString.copyFromUtf8( +// (java.lang.String) ref); +// name_ = b; +// return b; +// } else { +// return (com.google.protobuf.ByteString) ref; +// } +// } +// +// public static final int EMAIL_FIELD_NUMBER = 3; +// @SuppressWarnings("serial") +// private volatile java.lang.Object email_ = ""; +// /** +// * string email = 3; +// * @return The email. +// */ +// @java.lang.Override +// public java.lang.String getEmail() { +// java.lang.Object ref = email_; +// if (ref instanceof java.lang.String) { +// return (java.lang.String) ref; +// } else { +// com.google.protobuf.ByteString bs = +// (com.google.protobuf.ByteString) ref; +// java.lang.String s = bs.toStringUtf8(); +// email_ = s; +// return s; +// } +// } +// /** +// * string email = 3; +// * @return The bytes for email. +// */ +// @java.lang.Override +// public com.google.protobuf.ByteString +// getEmailBytes() { +// java.lang.Object ref = email_; +// if (ref instanceof java.lang.String) { +// com.google.protobuf.ByteString b = +// com.google.protobuf.ByteString.copyFromUtf8( +// (java.lang.String) ref); +// email_ = b; +// return b; +// } else { +// return (com.google.protobuf.ByteString) ref; +// } +// } +// +// private byte memoizedIsInitialized = -1; +// @java.lang.Override +// public final boolean isInitialized() { +// byte isInitialized = memoizedIsInitialized; +// if (isInitialized == 1) return true; +// if (isInitialized == 0) return false; +// +// memoizedIsInitialized = 1; +// return true; +// } +// +// @java.lang.Override +// public void writeTo(com.google.protobuf.CodedOutputStream output) +// throws java.io.IOException { +// if (id_ != 0) { +// output.writeSInt32(1, id_); +// } +// if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(name_)) { +// com.google.protobuf.GeneratedMessageV3.writeString(output, 2, name_); +// } +// if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(email_)) { +// com.google.protobuf.GeneratedMessageV3.writeString(output, 3, email_); +// } +// getUnknownFields().writeTo(output); +// } +// +// @java.lang.Override +// public int getSerializedSize() { +// int size = memoizedSize; +// if (size != -1) return size; +// +// size = 0; +// if (id_ != 0) { +// size += com.google.protobuf.CodedOutputStream +// .computeSInt32Size(1, id_); +// } +// if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(name_)) { +// size += com.google.protobuf.GeneratedMessageV3.computeStringSize(2, name_); +// } +// if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(email_)) { +// size += com.google.protobuf.GeneratedMessageV3.computeStringSize(3, email_); +// } +// size += getUnknownFields().getSerializedSize(); +// memoizedSize = size; +// return size; +// } +// +// @java.lang.Override +// public boolean equals(final java.lang.Object obj) { +// if (obj == this) { +// return true; +// } +// if (!(obj instanceof org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry)) { +// return super.equals(obj); +// } +// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry other = (org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry) obj; +// +// if (getId() +// != other.getId()) return false; +// if (!getName() +// .equals(other.getName())) return false; +// if (!getEmail() +// .equals(other.getEmail())) return false; +// if (!getUnknownFields().equals(other.getUnknownFields())) return false; +// return true; +// } +// +// @java.lang.Override +// public int hashCode() { +// if (memoizedHashCode != 0) { +// return memoizedHashCode; +// } +// int hash = 41; +// hash = (19 * hash) + getDescriptor().hashCode(); +// hash = (37 * hash) + ID_FIELD_NUMBER; +// hash = (53 * hash) + getId(); +// hash = (37 * hash) + NAME_FIELD_NUMBER; +// hash = (53 * hash) + getName().hashCode(); +// hash = (37 * hash) + EMAIL_FIELD_NUMBER; +// hash = (53 * hash) + getEmail().hashCode(); +// hash = (29 * hash) + getUnknownFields().hashCode(); +// memoizedHashCode = hash; +// return hash; +// } +// +// public static org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry parseFrom( +// java.nio.ByteBuffer data) +// throws com.google.protobuf.InvalidProtocolBufferException { +// return PARSER.parseFrom(data); +// } +// public static org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry parseFrom( +// java.nio.ByteBuffer data, +// com.google.protobuf.ExtensionRegistryLite extensionRegistry) +// throws com.google.protobuf.InvalidProtocolBufferException { +// return PARSER.parseFrom(data, extensionRegistry); +// } +// public static org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry parseFrom( +// com.google.protobuf.ByteString data) +// throws com.google.protobuf.InvalidProtocolBufferException { +// return PARSER.parseFrom(data); +// } +// public static org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry parseFrom( +// com.google.protobuf.ByteString data, +// com.google.protobuf.ExtensionRegistryLite extensionRegistry) +// throws com.google.protobuf.InvalidProtocolBufferException { +// return PARSER.parseFrom(data, extensionRegistry); +// } +// public static org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry parseFrom(byte[] data) +// throws com.google.protobuf.InvalidProtocolBufferException { +// return PARSER.parseFrom(data); +// } +// public static org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry parseFrom( +// byte[] data, +// com.google.protobuf.ExtensionRegistryLite extensionRegistry) +// throws com.google.protobuf.InvalidProtocolBufferException { +// return PARSER.parseFrom(data, extensionRegistry); +// } +// public static org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry parseFrom(java.io.InputStream input) +// throws java.io.IOException { +// return com.google.protobuf.GeneratedMessageV3 +// .parseWithIOException(PARSER, input); +// } +// public static org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry parseFrom( +// java.io.InputStream input, +// com.google.protobuf.ExtensionRegistryLite extensionRegistry) +// throws java.io.IOException { +// return com.google.protobuf.GeneratedMessageV3 +// .parseWithIOException(PARSER, input, extensionRegistry); +// } +// +// public static org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry parseDelimitedFrom(java.io.InputStream input) +// throws java.io.IOException { +// return com.google.protobuf.GeneratedMessageV3 +// .parseDelimitedWithIOException(PARSER, input); +// } +// +// public static org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry parseDelimitedFrom( +// java.io.InputStream input, +// com.google.protobuf.ExtensionRegistryLite extensionRegistry) +// throws java.io.IOException { +// return com.google.protobuf.GeneratedMessageV3 +// .parseDelimitedWithIOException(PARSER, input, extensionRegistry); +// } +// public static org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry parseFrom( +// com.google.protobuf.CodedInputStream input) +// throws java.io.IOException { +// return com.google.protobuf.GeneratedMessageV3 +// .parseWithIOException(PARSER, input); +// } +// public static org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry parseFrom( +// com.google.protobuf.CodedInputStream input, +// com.google.protobuf.ExtensionRegistryLite extensionRegistry) +// throws java.io.IOException { +// return com.google.protobuf.GeneratedMessageV3 +// .parseWithIOException(PARSER, input, extensionRegistry); +// } +// +// @java.lang.Override +// public Builder newBuilderForType() { return newBuilder(); } +// public static Builder newBuilder() { +// return DEFAULT_INSTANCE.toBuilder(); +// } +// public static Builder newBuilder(org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry prototype) { +// return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); +// } +// @java.lang.Override +// public Builder toBuilder() { +// return this == DEFAULT_INSTANCE +// ? new Builder() : new Builder().mergeFrom(this); +// } +// +// @java.lang.Override +// protected Builder newBuilderForType( +// com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { +// Builder builder = new Builder(parent); +// return builder; +// } +// /** +// * Protobuf type {@code PSimpleBean.PSimpleEntry} +// */ +// public static final class Builder extends +// com.google.protobuf.GeneratedMessageV3.Builder implements +// // @@protoc_insertion_point(builder_implements:PSimpleBean.PSimpleEntry) +// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntryOrBuilder { +// public static final com.google.protobuf.Descriptors.Descriptor +// getDescriptor() { +// return org.redkalex.test.protobuf.PSimpleBeanOuterClass.internal_static_PSimpleBean_PSimpleEntry_descriptor; +// } +// +// @java.lang.Override +// protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable +// internalGetFieldAccessorTable() { +// return org.redkalex.test.protobuf.PSimpleBeanOuterClass.internal_static_PSimpleBean_PSimpleEntry_fieldAccessorTable +// .ensureFieldAccessorsInitialized( +// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry.class, org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry.Builder.class); +// } +// +// // Construct using org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry.newBuilder() +// private Builder() { +// +// } +// +// private Builder( +// com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { +// super(parent); +// +// } +// @java.lang.Override +// public Builder clear() { +// super.clear(); +// bitField0_ = 0; +// id_ = 0; +// name_ = ""; +// email_ = ""; +// return this; +// } +// +// @java.lang.Override +// public com.google.protobuf.Descriptors.Descriptor +// getDescriptorForType() { +// return org.redkalex.test.protobuf.PSimpleBeanOuterClass.internal_static_PSimpleBean_PSimpleEntry_descriptor; +// } +// +// @java.lang.Override +// public org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry getDefaultInstanceForType() { +// return org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry.getDefaultInstance(); +// } +// +// @java.lang.Override +// public org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry build() { +// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry result = buildPartial(); +// if (!result.isInitialized()) { +// throw newUninitializedMessageException(result); +// } +// return result; +// } +// +// @java.lang.Override +// public org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry buildPartial() { +// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry result = new org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry(this); +// if (bitField0_ != 0) { buildPartial0(result); } +// onBuilt(); +// return result; +// } +// +// private void buildPartial0(org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry result) { +// int from_bitField0_ = bitField0_; +// if (((from_bitField0_ & 0x00000001) != 0)) { +// result.id_ = id_; +// } +// if (((from_bitField0_ & 0x00000002) != 0)) { +// result.name_ = name_; +// } +// if (((from_bitField0_ & 0x00000004) != 0)) { +// result.email_ = email_; +// } +// } +// +// @java.lang.Override +// public Builder clone() { +// return super.clone(); +// } +// @java.lang.Override +// public Builder setField( +// com.google.protobuf.Descriptors.FieldDescriptor field, +// java.lang.Object value) { +// return super.setField(field, value); +// } +// @java.lang.Override +// public Builder clearField( +// com.google.protobuf.Descriptors.FieldDescriptor field) { +// return super.clearField(field); +// } +// @java.lang.Override +// public Builder clearOneof( +// com.google.protobuf.Descriptors.OneofDescriptor oneof) { +// return super.clearOneof(oneof); +// } +// @java.lang.Override +// public Builder setRepeatedField( +// com.google.protobuf.Descriptors.FieldDescriptor field, +// int index, java.lang.Object value) { +// return super.setRepeatedField(field, index, value); +// } +// @java.lang.Override +// public Builder addRepeatedField( +// com.google.protobuf.Descriptors.FieldDescriptor field, +// java.lang.Object value) { +// return super.addRepeatedField(field, value); +// } +// @java.lang.Override +// public Builder mergeFrom(com.google.protobuf.Message other) { +// if (other instanceof org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry) { +// return mergeFrom((org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry)other); +// } else { +// super.mergeFrom(other); +// return this; +// } +// } +// +// public Builder mergeFrom(org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry other) { +// if (other == org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry.getDefaultInstance()) return this; +// if (other.getId() != 0) { +// setId(other.getId()); +// } +// if (!other.getName().isEmpty()) { +// name_ = other.name_; +// bitField0_ |= 0x00000002; +// onChanged(); +// } +// if (!other.getEmail().isEmpty()) { +// email_ = other.email_; +// bitField0_ |= 0x00000004; +// onChanged(); +// } +// this.mergeUnknownFields(other.getUnknownFields()); +// onChanged(); +// return this; +// } +// +// @java.lang.Override +// public final boolean isInitialized() { +// return true; +// } +// +// @java.lang.Override +// public Builder mergeFrom( +// com.google.protobuf.CodedInputStream input, +// com.google.protobuf.ExtensionRegistryLite extensionRegistry) +// throws java.io.IOException { +// if (extensionRegistry == null) { +// throw new java.lang.NullPointerException(); +// } +// try { +// boolean done = false; +// while (!done) { +// int tag = input.readTag(); +// switch (tag) { +// case 0: +// done = true; +// break; +// case 8: { +// id_ = input.readSInt32(); +// bitField0_ |= 0x00000001; +// break; +// } // case 8 +// case 18: { +// name_ = input.readStringRequireUtf8(); +// bitField0_ |= 0x00000002; +// break; +// } // case 18 +// case 26: { +// email_ = input.readStringRequireUtf8(); +// bitField0_ |= 0x00000004; +// break; +// } // case 26 +// default: { +// if (!super.parseUnknownField(input, extensionRegistry, tag)) { +// done = true; // was an endgroup tag +// } +// break; +// } // default: +// } // switch (tag) +// } // while (!done) +// } catch (com.google.protobuf.InvalidProtocolBufferException e) { +// throw e.unwrapIOException(); +// } finally { +// onChanged(); +// } // finally +// return this; +// } +// private int bitField0_; +// +// private int id_ ; +// /** +// * sint32 id = 1; +// * @return The id. +// */ +// @java.lang.Override +// public int getId() { +// return id_; +// } +// /** +// * sint32 id = 1; +// * @param value The id to set. +// * @return This builder for chaining. +// */ +// public Builder setId(int value) { +// +// id_ = value; +// bitField0_ |= 0x00000001; +// onChanged(); +// return this; +// } +// /** +// * sint32 id = 1; +// * @return This builder for chaining. +// */ +// public Builder clearId() { +// bitField0_ = (bitField0_ & ~0x00000001); +// id_ = 0; +// onChanged(); +// return this; +// } +// +// private java.lang.Object name_ = ""; +// /** +// * string name = 2; +// * @return The name. +// */ +// public java.lang.String getName() { +// java.lang.Object ref = name_; +// if (!(ref instanceof java.lang.String)) { +// com.google.protobuf.ByteString bs = +// (com.google.protobuf.ByteString) ref; +// java.lang.String s = bs.toStringUtf8(); +// name_ = s; +// return s; +// } else { +// return (java.lang.String) ref; +// } +// } +// /** +// * string name = 2; +// * @return The bytes for name. +// */ +// public com.google.protobuf.ByteString +// getNameBytes() { +// java.lang.Object ref = name_; +// if (ref instanceof String) { +// com.google.protobuf.ByteString b = +// com.google.protobuf.ByteString.copyFromUtf8( +// (java.lang.String) ref); +// name_ = b; +// return b; +// } else { +// return (com.google.protobuf.ByteString) ref; +// } +// } +// /** +// * string name = 2; +// * @param value The name to set. +// * @return This builder for chaining. +// */ +// public Builder setName( +// java.lang.String value) { +// if (value == null) { throw new NullPointerException(); } +// name_ = value; +// bitField0_ |= 0x00000002; +// onChanged(); +// return this; +// } +// /** +// * string name = 2; +// * @return This builder for chaining. +// */ +// public Builder clearName() { +// name_ = getDefaultInstance().getName(); +// bitField0_ = (bitField0_ & ~0x00000002); +// onChanged(); +// return this; +// } +// /** +// * string name = 2; +// * @param value The bytes for name to set. +// * @return This builder for chaining. +// */ +// public Builder setNameBytes( +// com.google.protobuf.ByteString value) { +// if (value == null) { throw new NullPointerException(); } +// checkByteStringIsUtf8(value); +// name_ = value; +// bitField0_ |= 0x00000002; +// onChanged(); +// return this; +// } +// +// private java.lang.Object email_ = ""; +// /** +// * string email = 3; +// * @return The email. +// */ +// public java.lang.String getEmail() { +// java.lang.Object ref = email_; +// if (!(ref instanceof java.lang.String)) { +// com.google.protobuf.ByteString bs = +// (com.google.protobuf.ByteString) ref; +// java.lang.String s = bs.toStringUtf8(); +// email_ = s; +// return s; +// } else { +// return (java.lang.String) ref; +// } +// } +// /** +// * string email = 3; +// * @return The bytes for email. +// */ +// public com.google.protobuf.ByteString +// getEmailBytes() { +// java.lang.Object ref = email_; +// if (ref instanceof String) { +// com.google.protobuf.ByteString b = +// com.google.protobuf.ByteString.copyFromUtf8( +// (java.lang.String) ref); +// email_ = b; +// return b; +// } else { +// return (com.google.protobuf.ByteString) ref; +// } +// } +// /** +// * string email = 3; +// * @param value The email to set. +// * @return This builder for chaining. +// */ +// public Builder setEmail( +// java.lang.String value) { +// if (value == null) { throw new NullPointerException(); } +// email_ = value; +// bitField0_ |= 0x00000004; +// onChanged(); +// return this; +// } +// /** +// * string email = 3; +// * @return This builder for chaining. +// */ +// public Builder clearEmail() { +// email_ = getDefaultInstance().getEmail(); +// bitField0_ = (bitField0_ & ~0x00000004); +// onChanged(); +// return this; +// } +// /** +// * string email = 3; +// * @param value The bytes for email to set. +// * @return This builder for chaining. +// */ +// public Builder setEmailBytes( +// com.google.protobuf.ByteString value) { +// if (value == null) { throw new NullPointerException(); } +// checkByteStringIsUtf8(value); +// email_ = value; +// bitField0_ |= 0x00000004; +// onChanged(); +// return this; +// } +// @java.lang.Override +// public final Builder setUnknownFields( +// final com.google.protobuf.UnknownFieldSet unknownFields) { +// return super.setUnknownFields(unknownFields); +// } +// +// @java.lang.Override +// public final Builder mergeUnknownFields( +// final com.google.protobuf.UnknownFieldSet unknownFields) { +// return super.mergeUnknownFields(unknownFields); +// } +// +// +// // @@protoc_insertion_point(builder_scope:PSimpleBean.PSimpleEntry) +// } +// +// // @@protoc_insertion_point(class_scope:PSimpleBean.PSimpleEntry) +// private static final org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry DEFAULT_INSTANCE; +// static { +// DEFAULT_INSTANCE = new org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry(); +// } +// +// public static org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry getDefaultInstance() { +// return DEFAULT_INSTANCE; +// } +// +// private static final com.google.protobuf.Parser +// PARSER = new com.google.protobuf.AbstractParser() { +// @java.lang.Override +// public PSimpleEntry parsePartialFrom( +// com.google.protobuf.CodedInputStream input, +// com.google.protobuf.ExtensionRegistryLite extensionRegistry) +// throws com.google.protobuf.InvalidProtocolBufferException { +// Builder builder = newBuilder(); +// try { +// builder.mergeFrom(input, extensionRegistry); +// } catch (com.google.protobuf.InvalidProtocolBufferException e) { +// throw e.setUnfinishedMessage(builder.buildPartial()); +// } catch (com.google.protobuf.UninitializedMessageException e) { +// throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial()); +// } catch (java.io.IOException e) { +// throw new com.google.protobuf.InvalidProtocolBufferException(e) +// .setUnfinishedMessage(builder.buildPartial()); +// } +// return builder.buildPartial(); +// } +// }; +// +// public static com.google.protobuf.Parser parser() { +// return PARSER; +// } +// +// @java.lang.Override +// public com.google.protobuf.Parser getParserForType() { +// return PARSER; +// } +// +// @java.lang.Override +// public org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry getDefaultInstanceForType() { +// return DEFAULT_INSTANCE; +// } +// +// } +// +// public interface PTwoEntryOrBuilder extends +// // @@protoc_insertion_point(interface_extends:PSimpleBean.PTwoEntry) +// com.google.protobuf.MessageOrBuilder { +// +// /** +// * sint32 status = 1; +// * @return The status. +// */ +// int getStatus(); +// +// /** +// * sint64 createtime = 2; +// * @return The createtime. +// */ +// long getCreatetime(); +// } +// /** +// * Protobuf type {@code PSimpleBean.PTwoEntry} +// */ +// public static final class PTwoEntry extends +// com.google.protobuf.GeneratedMessageV3 implements +// // @@protoc_insertion_point(message_implements:PSimpleBean.PTwoEntry) +// PTwoEntryOrBuilder { +// private static final long serialVersionUID = 0L; +// // Use PTwoEntry.newBuilder() to construct. +// private PTwoEntry(com.google.protobuf.GeneratedMessageV3.Builder builder) { +// super(builder); +// } +// private PTwoEntry() { +// } +// +// @java.lang.Override +// @SuppressWarnings({"unused"}) +// protected java.lang.Object newInstance( +// UnusedPrivateParameter unused) { +// return new PTwoEntry(); +// } +// +// public static final com.google.protobuf.Descriptors.Descriptor +// getDescriptor() { +// return org.redkalex.test.protobuf.PSimpleBeanOuterClass.internal_static_PSimpleBean_PTwoEntry_descriptor; +// } +// +// @java.lang.Override +// protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable +// internalGetFieldAccessorTable() { +// return org.redkalex.test.protobuf.PSimpleBeanOuterClass.internal_static_PSimpleBean_PTwoEntry_fieldAccessorTable +// .ensureFieldAccessorsInitialized( +// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry.class, org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry.Builder.class); +// } +// +// public static final int STATUS_FIELD_NUMBER = 1; +// private int status_ = 0; +// /** +// * sint32 status = 1; +// * @return The status. +// */ +// @java.lang.Override +// public int getStatus() { +// return status_; +// } +// +// public static final int CREATETIME_FIELD_NUMBER = 2; +// private long createtime_ = 0L; +// /** +// * sint64 createtime = 2; +// * @return The createtime. +// */ +// @java.lang.Override +// public long getCreatetime() { +// return createtime_; +// } +// +// private byte memoizedIsInitialized = -1; +// @java.lang.Override +// public final boolean isInitialized() { +// byte isInitialized = memoizedIsInitialized; +// if (isInitialized == 1) return true; +// if (isInitialized == 0) return false; +// +// memoizedIsInitialized = 1; +// return true; +// } +// +// @java.lang.Override +// public void writeTo(com.google.protobuf.CodedOutputStream output) +// throws java.io.IOException { +// if (status_ != 0) { +// output.writeSInt32(1, status_); +// } +// if (createtime_ != 0L) { +// output.writeSInt64(2, createtime_); +// } +// getUnknownFields().writeTo(output); +// } +// +// @java.lang.Override +// public int getSerializedSize() { +// int size = memoizedSize; +// if (size != -1) return size; +// +// size = 0; +// if (status_ != 0) { +// size += com.google.protobuf.CodedOutputStream +// .computeSInt32Size(1, status_); +// } +// if (createtime_ != 0L) { +// size += com.google.protobuf.CodedOutputStream +// .computeSInt64Size(2, createtime_); +// } +// size += getUnknownFields().getSerializedSize(); +// memoizedSize = size; +// return size; +// } +// +// @java.lang.Override +// public boolean equals(final java.lang.Object obj) { +// if (obj == this) { +// return true; +// } +// if (!(obj instanceof org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry)) { +// return super.equals(obj); +// } +// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry other = (org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry) obj; +// +// if (getStatus() +// != other.getStatus()) return false; +// if (getCreatetime() +// != other.getCreatetime()) return false; +// if (!getUnknownFields().equals(other.getUnknownFields())) return false; +// return true; +// } +// +// @java.lang.Override +// public int hashCode() { +// if (memoizedHashCode != 0) { +// return memoizedHashCode; +// } +// int hash = 41; +// hash = (19 * hash) + getDescriptor().hashCode(); +// hash = (37 * hash) + STATUS_FIELD_NUMBER; +// hash = (53 * hash) + getStatus(); +// hash = (37 * hash) + CREATETIME_FIELD_NUMBER; +// hash = (53 * hash) + com.google.protobuf.Internal.hashLong( +// getCreatetime()); +// hash = (29 * hash) + getUnknownFields().hashCode(); +// memoizedHashCode = hash; +// return hash; +// } +// +// public static org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry parseFrom( +// java.nio.ByteBuffer data) +// throws com.google.protobuf.InvalidProtocolBufferException { +// return PARSER.parseFrom(data); +// } +// public static org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry parseFrom( +// java.nio.ByteBuffer data, +// com.google.protobuf.ExtensionRegistryLite extensionRegistry) +// throws com.google.protobuf.InvalidProtocolBufferException { +// return PARSER.parseFrom(data, extensionRegistry); +// } +// public static org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry parseFrom( +// com.google.protobuf.ByteString data) +// throws com.google.protobuf.InvalidProtocolBufferException { +// return PARSER.parseFrom(data); +// } +// public static org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry parseFrom( +// com.google.protobuf.ByteString data, +// com.google.protobuf.ExtensionRegistryLite extensionRegistry) +// throws com.google.protobuf.InvalidProtocolBufferException { +// return PARSER.parseFrom(data, extensionRegistry); +// } +// public static org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry parseFrom(byte[] data) +// throws com.google.protobuf.InvalidProtocolBufferException { +// return PARSER.parseFrom(data); +// } +// public static org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry parseFrom( +// byte[] data, +// com.google.protobuf.ExtensionRegistryLite extensionRegistry) +// throws com.google.protobuf.InvalidProtocolBufferException { +// return PARSER.parseFrom(data, extensionRegistry); +// } +// public static org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry parseFrom(java.io.InputStream input) +// throws java.io.IOException { +// return com.google.protobuf.GeneratedMessageV3 +// .parseWithIOException(PARSER, input); +// } +// public static org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry parseFrom( +// java.io.InputStream input, +// com.google.protobuf.ExtensionRegistryLite extensionRegistry) +// throws java.io.IOException { +// return com.google.protobuf.GeneratedMessageV3 +// .parseWithIOException(PARSER, input, extensionRegistry); +// } +// +// public static org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry parseDelimitedFrom(java.io.InputStream input) +// throws java.io.IOException { +// return com.google.protobuf.GeneratedMessageV3 +// .parseDelimitedWithIOException(PARSER, input); +// } +// +// public static org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry parseDelimitedFrom( +// java.io.InputStream input, +// com.google.protobuf.ExtensionRegistryLite extensionRegistry) +// throws java.io.IOException { +// return com.google.protobuf.GeneratedMessageV3 +// .parseDelimitedWithIOException(PARSER, input, extensionRegistry); +// } +// public static org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry parseFrom( +// com.google.protobuf.CodedInputStream input) +// throws java.io.IOException { +// return com.google.protobuf.GeneratedMessageV3 +// .parseWithIOException(PARSER, input); +// } +// public static org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry parseFrom( +// com.google.protobuf.CodedInputStream input, +// com.google.protobuf.ExtensionRegistryLite extensionRegistry) +// throws java.io.IOException { +// return com.google.protobuf.GeneratedMessageV3 +// .parseWithIOException(PARSER, input, extensionRegistry); +// } +// +// @java.lang.Override +// public Builder newBuilderForType() { return newBuilder(); } +// public static Builder newBuilder() { +// return DEFAULT_INSTANCE.toBuilder(); +// } +// public static Builder newBuilder(org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry prototype) { +// return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); +// } +// @java.lang.Override +// public Builder toBuilder() { +// return this == DEFAULT_INSTANCE +// ? new Builder() : new Builder().mergeFrom(this); +// } +// +// @java.lang.Override +// protected Builder newBuilderForType( +// com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { +// Builder builder = new Builder(parent); +// return builder; +// } +// /** +// * Protobuf type {@code PSimpleBean.PTwoEntry} +// */ +// public static final class Builder extends +// com.google.protobuf.GeneratedMessageV3.Builder implements +// // @@protoc_insertion_point(builder_implements:PSimpleBean.PTwoEntry) +// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntryOrBuilder { +// public static final com.google.protobuf.Descriptors.Descriptor +// getDescriptor() { +// return org.redkalex.test.protobuf.PSimpleBeanOuterClass.internal_static_PSimpleBean_PTwoEntry_descriptor; +// } +// +// @java.lang.Override +// protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable +// internalGetFieldAccessorTable() { +// return org.redkalex.test.protobuf.PSimpleBeanOuterClass.internal_static_PSimpleBean_PTwoEntry_fieldAccessorTable +// .ensureFieldAccessorsInitialized( +// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry.class, org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry.Builder.class); +// } +// +// // Construct using org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry.newBuilder() +// private Builder() { +// +// } +// +// private Builder( +// com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { +// super(parent); +// +// } +// @java.lang.Override +// public Builder clear() { +// super.clear(); +// bitField0_ = 0; +// status_ = 0; +// createtime_ = 0L; +// return this; +// } +// +// @java.lang.Override +// public com.google.protobuf.Descriptors.Descriptor +// getDescriptorForType() { +// return org.redkalex.test.protobuf.PSimpleBeanOuterClass.internal_static_PSimpleBean_PTwoEntry_descriptor; +// } +// +// @java.lang.Override +// public org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry getDefaultInstanceForType() { +// return org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry.getDefaultInstance(); +// } +// +// @java.lang.Override +// public org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry build() { +// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry result = buildPartial(); +// if (!result.isInitialized()) { +// throw newUninitializedMessageException(result); +// } +// return result; +// } +// +// @java.lang.Override +// public org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry buildPartial() { +// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry result = new org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry(this); +// if (bitField0_ != 0) { buildPartial0(result); } +// onBuilt(); +// return result; +// } +// +// private void buildPartial0(org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry result) { +// int from_bitField0_ = bitField0_; +// if (((from_bitField0_ & 0x00000001) != 0)) { +// result.status_ = status_; +// } +// if (((from_bitField0_ & 0x00000002) != 0)) { +// result.createtime_ = createtime_; +// } +// } +// +// @java.lang.Override +// public Builder clone() { +// return super.clone(); +// } +// @java.lang.Override +// public Builder setField( +// com.google.protobuf.Descriptors.FieldDescriptor field, +// java.lang.Object value) { +// return super.setField(field, value); +// } +// @java.lang.Override +// public Builder clearField( +// com.google.protobuf.Descriptors.FieldDescriptor field) { +// return super.clearField(field); +// } +// @java.lang.Override +// public Builder clearOneof( +// com.google.protobuf.Descriptors.OneofDescriptor oneof) { +// return super.clearOneof(oneof); +// } +// @java.lang.Override +// public Builder setRepeatedField( +// com.google.protobuf.Descriptors.FieldDescriptor field, +// int index, java.lang.Object value) { +// return super.setRepeatedField(field, index, value); +// } +// @java.lang.Override +// public Builder addRepeatedField( +// com.google.protobuf.Descriptors.FieldDescriptor field, +// java.lang.Object value) { +// return super.addRepeatedField(field, value); +// } +// @java.lang.Override +// public Builder mergeFrom(com.google.protobuf.Message other) { +// if (other instanceof org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry) { +// return mergeFrom((org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry)other); +// } else { +// super.mergeFrom(other); +// return this; +// } +// } +// +// public Builder mergeFrom(org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry other) { +// if (other == org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry.getDefaultInstance()) return this; +// if (other.getStatus() != 0) { +// setStatus(other.getStatus()); +// } +// if (other.getCreatetime() != 0L) { +// setCreatetime(other.getCreatetime()); +// } +// this.mergeUnknownFields(other.getUnknownFields()); +// onChanged(); +// return this; +// } +// +// @java.lang.Override +// public final boolean isInitialized() { +// return true; +// } +// +// @java.lang.Override +// public Builder mergeFrom( +// com.google.protobuf.CodedInputStream input, +// com.google.protobuf.ExtensionRegistryLite extensionRegistry) +// throws java.io.IOException { +// if (extensionRegistry == null) { +// throw new java.lang.NullPointerException(); +// } +// try { +// boolean done = false; +// while (!done) { +// int tag = input.readTag(); +// switch (tag) { +// case 0: +// done = true; +// break; +// case 8: { +// status_ = input.readSInt32(); +// bitField0_ |= 0x00000001; +// break; +// } // case 8 +// case 16: { +// createtime_ = input.readSInt64(); +// bitField0_ |= 0x00000002; +// break; +// } // case 16 +// default: { +// if (!super.parseUnknownField(input, extensionRegistry, tag)) { +// done = true; // was an endgroup tag +// } +// break; +// } // default: +// } // switch (tag) +// } // while (!done) +// } catch (com.google.protobuf.InvalidProtocolBufferException e) { +// throw e.unwrapIOException(); +// } finally { +// onChanged(); +// } // finally +// return this; +// } +// private int bitField0_; +// +// private int status_ ; +// /** +// * sint32 status = 1; +// * @return The status. +// */ +// @java.lang.Override +// public int getStatus() { +// return status_; +// } +// /** +// * sint32 status = 1; +// * @param value The status to set. +// * @return This builder for chaining. +// */ +// public Builder setStatus(int value) { +// +// status_ = value; +// bitField0_ |= 0x00000001; +// onChanged(); +// return this; +// } +// /** +// * sint32 status = 1; +// * @return This builder for chaining. +// */ +// public Builder clearStatus() { +// bitField0_ = (bitField0_ & ~0x00000001); +// status_ = 0; +// onChanged(); +// return this; +// } +// +// private long createtime_ ; +// /** +// * sint64 createtime = 2; +// * @return The createtime. +// */ +// @java.lang.Override +// public long getCreatetime() { +// return createtime_; +// } +// /** +// * sint64 createtime = 2; +// * @param value The createtime to set. +// * @return This builder for chaining. +// */ +// public Builder setCreatetime(long value) { +// +// createtime_ = value; +// bitField0_ |= 0x00000002; +// onChanged(); +// return this; +// } +// /** +// * sint64 createtime = 2; +// * @return This builder for chaining. +// */ +// public Builder clearCreatetime() { +// bitField0_ = (bitField0_ & ~0x00000002); +// createtime_ = 0L; +// onChanged(); +// return this; +// } +// @java.lang.Override +// public final Builder setUnknownFields( +// final com.google.protobuf.UnknownFieldSet unknownFields) { +// return super.setUnknownFields(unknownFields); +// } +// +// @java.lang.Override +// public final Builder mergeUnknownFields( +// final com.google.protobuf.UnknownFieldSet unknownFields) { +// return super.mergeUnknownFields(unknownFields); +// } +// +// +// // @@protoc_insertion_point(builder_scope:PSimpleBean.PTwoEntry) +// } +// +// // @@protoc_insertion_point(class_scope:PSimpleBean.PTwoEntry) +// private static final org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry DEFAULT_INSTANCE; +// static { +// DEFAULT_INSTANCE = new org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry(); +// } +// +// public static org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry getDefaultInstance() { +// return DEFAULT_INSTANCE; +// } +// +// private static final com.google.protobuf.Parser +// PARSER = new com.google.protobuf.AbstractParser() { +// @java.lang.Override +// public PTwoEntry parsePartialFrom( +// com.google.protobuf.CodedInputStream input, +// com.google.protobuf.ExtensionRegistryLite extensionRegistry) +// throws com.google.protobuf.InvalidProtocolBufferException { +// Builder builder = newBuilder(); +// try { +// builder.mergeFrom(input, extensionRegistry); +// } catch (com.google.protobuf.InvalidProtocolBufferException e) { +// throw e.setUnfinishedMessage(builder.buildPartial()); +// } catch (com.google.protobuf.UninitializedMessageException e) { +// throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial()); +// } catch (java.io.IOException e) { +// throw new com.google.protobuf.InvalidProtocolBufferException(e) +// .setUnfinishedMessage(builder.buildPartial()); +// } +// return builder.buildPartial(); +// } +// }; +// +// public static com.google.protobuf.Parser parser() { +// return PARSER; +// } +// +// @java.lang.Override +// public com.google.protobuf.Parser getParserForType() { +// return PARSER; +// } +// +// @java.lang.Override +// public org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry getDefaultInstanceForType() { +// return DEFAULT_INSTANCE; +// } +// +// } +// +// public static final int SIMPLE_FIELD_NUMBER = 1; +// private org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry simple_; +// /** +// * .PSimpleBean.PSimpleEntry simple = 1; +// * @return Whether the simple field is set. +// */ +// @java.lang.Override +// public boolean hasSimple() { +// return simple_ != null; +// } +// /** +// * .PSimpleBean.PSimpleEntry simple = 1; +// * @return The simple. +// */ +// @java.lang.Override +// public org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry getSimple() { +// return simple_ == null ? org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry.getDefaultInstance() : simple_; +// } +// /** +// * .PSimpleBean.PSimpleEntry simple = 1; +// */ +// @java.lang.Override +// public org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntryOrBuilder getSimpleOrBuilder() { +// return simple_ == null ? org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry.getDefaultInstance() : simple_; +// } +// +// public static final int TWO_FIELD_NUMBER = 2; +// private org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry two_; +// /** +// * .PSimpleBean.PTwoEntry two = 2; +// * @return Whether the two field is set. +// */ +// @java.lang.Override +// public boolean hasTwo() { +// return two_ != null; +// } +// /** +// * .PSimpleBean.PTwoEntry two = 2; +// * @return The two. +// */ +// @java.lang.Override +// public org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry getTwo() { +// return two_ == null ? org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry.getDefaultInstance() : two_; +// } +// /** +// * .PSimpleBean.PTwoEntry two = 2; +// */ +// @java.lang.Override +// public org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntryOrBuilder getTwoOrBuilder() { +// return two_ == null ? org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry.getDefaultInstance() : two_; +// } +// +// public static final int STRINGS_FIELD_NUMBER = 3; +// @SuppressWarnings("serial") +// private volatile java.lang.Object strings_ = ""; +// /** +// * string strings = 3; +// * @return The strings. +// */ +// @java.lang.Override +// public java.lang.String getStrings() { +// java.lang.Object ref = strings_; +// if (ref instanceof java.lang.String) { +// return (java.lang.String) ref; +// } else { +// com.google.protobuf.ByteString bs = +// (com.google.protobuf.ByteString) ref; +// java.lang.String s = bs.toStringUtf8(); +// strings_ = s; +// return s; +// } +// } +// /** +// * string strings = 3; +// * @return The bytes for strings. +// */ +// @java.lang.Override +// public com.google.protobuf.ByteString +// getStringsBytes() { +// java.lang.Object ref = strings_; +// if (ref instanceof java.lang.String) { +// com.google.protobuf.ByteString b = +// com.google.protobuf.ByteString.copyFromUtf8( +// (java.lang.String) ref); +// strings_ = b; +// return b; +// } else { +// return (com.google.protobuf.ByteString) ref; +// } +// } +// +// private byte memoizedIsInitialized = -1; +// @java.lang.Override +// public final boolean isInitialized() { +// byte isInitialized = memoizedIsInitialized; +// if (isInitialized == 1) return true; +// if (isInitialized == 0) return false; +// +// memoizedIsInitialized = 1; +// return true; +// } +// +// @java.lang.Override +// public void writeTo(com.google.protobuf.CodedOutputStream output) +// throws java.io.IOException { +// if (simple_ != null) { +// output.writeMessage(1, getSimple()); +// } +// if (two_ != null) { +// output.writeMessage(2, getTwo()); +// } +// if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(strings_)) { +// com.google.protobuf.GeneratedMessageV3.writeString(output, 3, strings_); +// } +// getUnknownFields().writeTo(output); +// } +// +// @java.lang.Override +// public int getSerializedSize() { +// int size = memoizedSize; +// if (size != -1) return size; +// +// size = 0; +// if (simple_ != null) { +// size += com.google.protobuf.CodedOutputStream +// .computeMessageSize(1, getSimple()); +// } +// if (two_ != null) { +// size += com.google.protobuf.CodedOutputStream +// .computeMessageSize(2, getTwo()); +// } +// if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(strings_)) { +// size += com.google.protobuf.GeneratedMessageV3.computeStringSize(3, strings_); +// } +// size += getUnknownFields().getSerializedSize(); +// memoizedSize = size; +// return size; +// } +// +// @java.lang.Override +// public boolean equals(final java.lang.Object obj) { +// if (obj == this) { +// return true; +// } +// if (!(obj instanceof org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean)) { +// return super.equals(obj); +// } +// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean other = (org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean) obj; +// +// if (hasSimple() != other.hasSimple()) return false; +// if (hasSimple()) { +// if (!getSimple() +// .equals(other.getSimple())) return false; +// } +// if (hasTwo() != other.hasTwo()) return false; +// if (hasTwo()) { +// if (!getTwo() +// .equals(other.getTwo())) return false; +// } +// if (!getStrings() +// .equals(other.getStrings())) return false; +// if (!getUnknownFields().equals(other.getUnknownFields())) return false; +// return true; +// } +// +// @java.lang.Override +// public int hashCode() { +// if (memoizedHashCode != 0) { +// return memoizedHashCode; +// } +// int hash = 41; +// hash = (19 * hash) + getDescriptor().hashCode(); +// if (hasSimple()) { +// hash = (37 * hash) + SIMPLE_FIELD_NUMBER; +// hash = (53 * hash) + getSimple().hashCode(); +// } +// if (hasTwo()) { +// hash = (37 * hash) + TWO_FIELD_NUMBER; +// hash = (53 * hash) + getTwo().hashCode(); +// } +// hash = (37 * hash) + STRINGS_FIELD_NUMBER; +// hash = (53 * hash) + getStrings().hashCode(); +// hash = (29 * hash) + getUnknownFields().hashCode(); +// memoizedHashCode = hash; +// return hash; +// } +// +// public static org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean parseFrom( +// java.nio.ByteBuffer data) +// throws com.google.protobuf.InvalidProtocolBufferException { +// return PARSER.parseFrom(data); +// } +// public static org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean parseFrom( +// java.nio.ByteBuffer data, +// com.google.protobuf.ExtensionRegistryLite extensionRegistry) +// throws com.google.protobuf.InvalidProtocolBufferException { +// return PARSER.parseFrom(data, extensionRegistry); +// } +// public static org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean parseFrom( +// com.google.protobuf.ByteString data) +// throws com.google.protobuf.InvalidProtocolBufferException { +// return PARSER.parseFrom(data); +// } +// public static org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean parseFrom( +// com.google.protobuf.ByteString data, +// com.google.protobuf.ExtensionRegistryLite extensionRegistry) +// throws com.google.protobuf.InvalidProtocolBufferException { +// return PARSER.parseFrom(data, extensionRegistry); +// } +// public static org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean parseFrom(byte[] data) +// throws com.google.protobuf.InvalidProtocolBufferException { +// return PARSER.parseFrom(data); +// } +// public static org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean parseFrom( +// byte[] data, +// com.google.protobuf.ExtensionRegistryLite extensionRegistry) +// throws com.google.protobuf.InvalidProtocolBufferException { +// return PARSER.parseFrom(data, extensionRegistry); +// } +// public static org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean parseFrom(java.io.InputStream input) +// throws java.io.IOException { +// return com.google.protobuf.GeneratedMessageV3 +// .parseWithIOException(PARSER, input); +// } +// public static org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean parseFrom( +// java.io.InputStream input, +// com.google.protobuf.ExtensionRegistryLite extensionRegistry) +// throws java.io.IOException { +// return com.google.protobuf.GeneratedMessageV3 +// .parseWithIOException(PARSER, input, extensionRegistry); +// } +// +// public static org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean parseDelimitedFrom(java.io.InputStream input) +// throws java.io.IOException { +// return com.google.protobuf.GeneratedMessageV3 +// .parseDelimitedWithIOException(PARSER, input); +// } +// +// public static org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean parseDelimitedFrom( +// java.io.InputStream input, +// com.google.protobuf.ExtensionRegistryLite extensionRegistry) +// throws java.io.IOException { +// return com.google.protobuf.GeneratedMessageV3 +// .parseDelimitedWithIOException(PARSER, input, extensionRegistry); +// } +// public static org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean parseFrom( +// com.google.protobuf.CodedInputStream input) +// throws java.io.IOException { +// return com.google.protobuf.GeneratedMessageV3 +// .parseWithIOException(PARSER, input); +// } +// public static org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean parseFrom( +// com.google.protobuf.CodedInputStream input, +// com.google.protobuf.ExtensionRegistryLite extensionRegistry) +// throws java.io.IOException { +// return com.google.protobuf.GeneratedMessageV3 +// .parseWithIOException(PARSER, input, extensionRegistry); +// } +// +// @java.lang.Override +// public Builder newBuilderForType() { return newBuilder(); } +// public static Builder newBuilder() { +// return DEFAULT_INSTANCE.toBuilder(); +// } +// public static Builder newBuilder(org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean prototype) { +// return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); +// } +// @java.lang.Override +// public Builder toBuilder() { +// return this == DEFAULT_INSTANCE +// ? new Builder() : new Builder().mergeFrom(this); +// } +// +// @java.lang.Override +// protected Builder newBuilderForType( +// com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { +// Builder builder = new Builder(parent); +// return builder; +// } +// /** +// * Protobuf type {@code PSimpleBean} +// */ +// public static final class Builder extends +// com.google.protobuf.GeneratedMessageV3.Builder implements +// // @@protoc_insertion_point(builder_implements:PSimpleBean) +// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBeanOrBuilder { +// public static final com.google.protobuf.Descriptors.Descriptor +// getDescriptor() { +// return org.redkalex.test.protobuf.PSimpleBeanOuterClass.internal_static_PSimpleBean_descriptor; +// } +// +// @java.lang.Override +// protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable +// internalGetFieldAccessorTable() { +// return org.redkalex.test.protobuf.PSimpleBeanOuterClass.internal_static_PSimpleBean_fieldAccessorTable +// .ensureFieldAccessorsInitialized( +// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.class, org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.Builder.class); +// } +// +// // Construct using org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.newBuilder() +// private Builder() { +// +// } +// +// private Builder( +// com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { +// super(parent); +// +// } +// @java.lang.Override +// public Builder clear() { +// super.clear(); +// bitField0_ = 0; +// simple_ = null; +// if (simpleBuilder_ != null) { +// simpleBuilder_.dispose(); +// simpleBuilder_ = null; +// } +// two_ = null; +// if (twoBuilder_ != null) { +// twoBuilder_.dispose(); +// twoBuilder_ = null; +// } +// strings_ = ""; +// return this; +// } +// +// @java.lang.Override +// public com.google.protobuf.Descriptors.Descriptor +// getDescriptorForType() { +// return org.redkalex.test.protobuf.PSimpleBeanOuterClass.internal_static_PSimpleBean_descriptor; +// } +// +// @java.lang.Override +// public org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean getDefaultInstanceForType() { +// return org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.getDefaultInstance(); +// } +// +// @java.lang.Override +// public org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean build() { +// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean result = buildPartial(); +// if (!result.isInitialized()) { +// throw newUninitializedMessageException(result); +// } +// return result; +// } +// +// @java.lang.Override +// public org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean buildPartial() { +// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean result = new org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean(this); +// if (bitField0_ != 0) { buildPartial0(result); } +// onBuilt(); +// return result; +// } +// +// private void buildPartial0(org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean result) { +// int from_bitField0_ = bitField0_; +// if (((from_bitField0_ & 0x00000001) != 0)) { +// result.simple_ = simpleBuilder_ == null +// ? simple_ +// : simpleBuilder_.build(); +// } +// if (((from_bitField0_ & 0x00000002) != 0)) { +// result.two_ = twoBuilder_ == null +// ? two_ +// : twoBuilder_.build(); +// } +// if (((from_bitField0_ & 0x00000004) != 0)) { +// result.strings_ = strings_; +// } +// } +// +// @java.lang.Override +// public Builder clone() { +// return super.clone(); +// } +// @java.lang.Override +// public Builder setField( +// com.google.protobuf.Descriptors.FieldDescriptor field, +// java.lang.Object value) { +// return super.setField(field, value); +// } +// @java.lang.Override +// public Builder clearField( +// com.google.protobuf.Descriptors.FieldDescriptor field) { +// return super.clearField(field); +// } +// @java.lang.Override +// public Builder clearOneof( +// com.google.protobuf.Descriptors.OneofDescriptor oneof) { +// return super.clearOneof(oneof); +// } +// @java.lang.Override +// public Builder setRepeatedField( +// com.google.protobuf.Descriptors.FieldDescriptor field, +// int index, java.lang.Object value) { +// return super.setRepeatedField(field, index, value); +// } +// @java.lang.Override +// public Builder addRepeatedField( +// com.google.protobuf.Descriptors.FieldDescriptor field, +// java.lang.Object value) { +// return super.addRepeatedField(field, value); +// } +// @java.lang.Override +// public Builder mergeFrom(com.google.protobuf.Message other) { +// if (other instanceof org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean) { +// return mergeFrom((org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean)other); +// } else { +// super.mergeFrom(other); +// return this; +// } +// } +// +// public Builder mergeFrom(org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean other) { +// if (other == org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.getDefaultInstance()) return this; +// if (other.hasSimple()) { +// mergeSimple(other.getSimple()); +// } +// if (other.hasTwo()) { +// mergeTwo(other.getTwo()); +// } +// if (!other.getStrings().isEmpty()) { +// strings_ = other.strings_; +// bitField0_ |= 0x00000004; +// onChanged(); +// } +// this.mergeUnknownFields(other.getUnknownFields()); +// onChanged(); +// return this; +// } +// +// @java.lang.Override +// public final boolean isInitialized() { +// return true; +// } +// +// @java.lang.Override +// public Builder mergeFrom( +// com.google.protobuf.CodedInputStream input, +// com.google.protobuf.ExtensionRegistryLite extensionRegistry) +// throws java.io.IOException { +// if (extensionRegistry == null) { +// throw new java.lang.NullPointerException(); +// } +// try { +// boolean done = false; +// while (!done) { +// int tag = input.readTag(); +// switch (tag) { +// case 0: +// done = true; +// break; +// case 10: { +// input.readMessage( +// getSimpleFieldBuilder().getBuilder(), +// extensionRegistry); +// bitField0_ |= 0x00000001; +// break; +// } // case 10 +// case 18: { +// input.readMessage( +// getTwoFieldBuilder().getBuilder(), +// extensionRegistry); +// bitField0_ |= 0x00000002; +// break; +// } // case 18 +// case 26: { +// strings_ = input.readStringRequireUtf8(); +// bitField0_ |= 0x00000004; +// break; +// } // case 26 +// default: { +// if (!super.parseUnknownField(input, extensionRegistry, tag)) { +// done = true; // was an endgroup tag +// } +// break; +// } // default: +// } // switch (tag) +// } // while (!done) +// } catch (com.google.protobuf.InvalidProtocolBufferException e) { +// throw e.unwrapIOException(); +// } finally { +// onChanged(); +// } // finally +// return this; +// } +// private int bitField0_; +// +// private org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry simple_; +// private com.google.protobuf.SingleFieldBuilderV3< +// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry, org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry.Builder, org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntryOrBuilder> simpleBuilder_; +// /** +// * .PSimpleBean.PSimpleEntry simple = 1; +// * @return Whether the simple field is set. +// */ +// public boolean hasSimple() { +// return ((bitField0_ & 0x00000001) != 0); +// } +// /** +// * .PSimpleBean.PSimpleEntry simple = 1; +// * @return The simple. +// */ +// public org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry getSimple() { +// if (simpleBuilder_ == null) { +// return simple_ == null ? org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry.getDefaultInstance() : simple_; +// } else { +// return simpleBuilder_.getMessage(); +// } +// } +// /** +// * .PSimpleBean.PSimpleEntry simple = 1; +// */ +// public Builder setSimple(org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry value) { +// if (simpleBuilder_ == null) { +// if (value == null) { +// throw new NullPointerException(); +// } +// simple_ = value; +// } else { +// simpleBuilder_.setMessage(value); +// } +// bitField0_ |= 0x00000001; +// onChanged(); +// return this; +// } +// /** +// * .PSimpleBean.PSimpleEntry simple = 1; +// */ +// public Builder setSimple( +// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry.Builder builderForValue) { +// if (simpleBuilder_ == null) { +// simple_ = builderForValue.build(); +// } else { +// simpleBuilder_.setMessage(builderForValue.build()); +// } +// bitField0_ |= 0x00000001; +// onChanged(); +// return this; +// } +// /** +// * .PSimpleBean.PSimpleEntry simple = 1; +// */ +// public Builder mergeSimple(org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry value) { +// if (simpleBuilder_ == null) { +// if (((bitField0_ & 0x00000001) != 0) && +// simple_ != null && +// simple_ != org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry.getDefaultInstance()) { +// getSimpleBuilder().mergeFrom(value); +// } else { +// simple_ = value; +// } +// } else { +// simpleBuilder_.mergeFrom(value); +// } +// bitField0_ |= 0x00000001; +// onChanged(); +// return this; +// } +// /** +// * .PSimpleBean.PSimpleEntry simple = 1; +// */ +// public Builder clearSimple() { +// bitField0_ = (bitField0_ & ~0x00000001); +// simple_ = null; +// if (simpleBuilder_ != null) { +// simpleBuilder_.dispose(); +// simpleBuilder_ = null; +// } +// onChanged(); +// return this; +// } +// /** +// * .PSimpleBean.PSimpleEntry simple = 1; +// */ +// public org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry.Builder getSimpleBuilder() { +// bitField0_ |= 0x00000001; +// onChanged(); +// return getSimpleFieldBuilder().getBuilder(); +// } +// /** +// * .PSimpleBean.PSimpleEntry simple = 1; +// */ +// public org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntryOrBuilder getSimpleOrBuilder() { +// if (simpleBuilder_ != null) { +// return simpleBuilder_.getMessageOrBuilder(); +// } else { +// return simple_ == null ? +// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry.getDefaultInstance() : simple_; +// } +// } +// /** +// * .PSimpleBean.PSimpleEntry simple = 1; +// */ +// private com.google.protobuf.SingleFieldBuilderV3< +// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry, org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry.Builder, org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntryOrBuilder> +// getSimpleFieldBuilder() { +// if (simpleBuilder_ == null) { +// simpleBuilder_ = new com.google.protobuf.SingleFieldBuilderV3< +// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry, org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry.Builder, org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntryOrBuilder>( +// getSimple(), +// getParentForChildren(), +// isClean()); +// simple_ = null; +// } +// return simpleBuilder_; +// } +// +// private org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry two_; +// private com.google.protobuf.SingleFieldBuilderV3< +// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry, org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry.Builder, org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntryOrBuilder> twoBuilder_; +// /** +// * .PSimpleBean.PTwoEntry two = 2; +// * @return Whether the two field is set. +// */ +// public boolean hasTwo() { +// return ((bitField0_ & 0x00000002) != 0); +// } +// /** +// * .PSimpleBean.PTwoEntry two = 2; +// * @return The two. +// */ +// public org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry getTwo() { +// if (twoBuilder_ == null) { +// return two_ == null ? org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry.getDefaultInstance() : two_; +// } else { +// return twoBuilder_.getMessage(); +// } +// } +// /** +// * .PSimpleBean.PTwoEntry two = 2; +// */ +// public Builder setTwo(org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry value) { +// if (twoBuilder_ == null) { +// if (value == null) { +// throw new NullPointerException(); +// } +// two_ = value; +// } else { +// twoBuilder_.setMessage(value); +// } +// bitField0_ |= 0x00000002; +// onChanged(); +// return this; +// } +// /** +// * .PSimpleBean.PTwoEntry two = 2; +// */ +// public Builder setTwo( +// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry.Builder builderForValue) { +// if (twoBuilder_ == null) { +// two_ = builderForValue.build(); +// } else { +// twoBuilder_.setMessage(builderForValue.build()); +// } +// bitField0_ |= 0x00000002; +// onChanged(); +// return this; +// } +// /** +// * .PSimpleBean.PTwoEntry two = 2; +// */ +// public Builder mergeTwo(org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry value) { +// if (twoBuilder_ == null) { +// if (((bitField0_ & 0x00000002) != 0) && +// two_ != null && +// two_ != org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry.getDefaultInstance()) { +// getTwoBuilder().mergeFrom(value); +// } else { +// two_ = value; +// } +// } else { +// twoBuilder_.mergeFrom(value); +// } +// bitField0_ |= 0x00000002; +// onChanged(); +// return this; +// } +// /** +// * .PSimpleBean.PTwoEntry two = 2; +// */ +// public Builder clearTwo() { +// bitField0_ = (bitField0_ & ~0x00000002); +// two_ = null; +// if (twoBuilder_ != null) { +// twoBuilder_.dispose(); +// twoBuilder_ = null; +// } +// onChanged(); +// return this; +// } +// /** +// * .PSimpleBean.PTwoEntry two = 2; +// */ +// public org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry.Builder getTwoBuilder() { +// bitField0_ |= 0x00000002; +// onChanged(); +// return getTwoFieldBuilder().getBuilder(); +// } +// /** +// * .PSimpleBean.PTwoEntry two = 2; +// */ +// public org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntryOrBuilder getTwoOrBuilder() { +// if (twoBuilder_ != null) { +// return twoBuilder_.getMessageOrBuilder(); +// } else { +// return two_ == null ? +// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry.getDefaultInstance() : two_; +// } +// } +// /** +// * .PSimpleBean.PTwoEntry two = 2; +// */ +// private com.google.protobuf.SingleFieldBuilderV3< +// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry, org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry.Builder, org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntryOrBuilder> +// getTwoFieldBuilder() { +// if (twoBuilder_ == null) { +// twoBuilder_ = new com.google.protobuf.SingleFieldBuilderV3< +// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry, org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry.Builder, org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntryOrBuilder>( +// getTwo(), +// getParentForChildren(), +// isClean()); +// two_ = null; +// } +// return twoBuilder_; +// } +// +// private java.lang.Object strings_ = ""; +// /** +// * string strings = 3; +// * @return The strings. +// */ +// public java.lang.String getStrings() { +// java.lang.Object ref = strings_; +// if (!(ref instanceof java.lang.String)) { +// com.google.protobuf.ByteString bs = +// (com.google.protobuf.ByteString) ref; +// java.lang.String s = bs.toStringUtf8(); +// strings_ = s; +// return s; +// } else { +// return (java.lang.String) ref; +// } +// } +// /** +// * string strings = 3; +// * @return The bytes for strings. +// */ +// public com.google.protobuf.ByteString +// getStringsBytes() { +// java.lang.Object ref = strings_; +// if (ref instanceof String) { +// com.google.protobuf.ByteString b = +// com.google.protobuf.ByteString.copyFromUtf8( +// (java.lang.String) ref); +// strings_ = b; +// return b; +// } else { +// return (com.google.protobuf.ByteString) ref; +// } +// } +// /** +// * string strings = 3; +// * @param value The strings to set. +// * @return This builder for chaining. +// */ +// public Builder setStrings( +// java.lang.String value) { +// if (value == null) { throw new NullPointerException(); } +// strings_ = value; +// bitField0_ |= 0x00000004; +// onChanged(); +// return this; +// } +// /** +// * string strings = 3; +// * @return This builder for chaining. +// */ +// public Builder clearStrings() { +// strings_ = getDefaultInstance().getStrings(); +// bitField0_ = (bitField0_ & ~0x00000004); +// onChanged(); +// return this; +// } +// /** +// * string strings = 3; +// * @param value The bytes for strings to set. +// * @return This builder for chaining. +// */ +// public Builder setStringsBytes( +// com.google.protobuf.ByteString value) { +// if (value == null) { throw new NullPointerException(); } +// checkByteStringIsUtf8(value); +// strings_ = value; +// bitField0_ |= 0x00000004; +// onChanged(); +// return this; +// } +// @java.lang.Override +// public final Builder setUnknownFields( +// final com.google.protobuf.UnknownFieldSet unknownFields) { +// return super.setUnknownFields(unknownFields); +// } +// +// @java.lang.Override +// public final Builder mergeUnknownFields( +// final com.google.protobuf.UnknownFieldSet unknownFields) { +// return super.mergeUnknownFields(unknownFields); +// } +// +// +// // @@protoc_insertion_point(builder_scope:PSimpleBean) +// } +// +// // @@protoc_insertion_point(class_scope:PSimpleBean) +// private static final org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean DEFAULT_INSTANCE; +// static { +// DEFAULT_INSTANCE = new org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean(); +// } +// +// public static org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean getDefaultInstance() { +// return DEFAULT_INSTANCE; +// } +// +// private static final com.google.protobuf.Parser +// PARSER = new com.google.protobuf.AbstractParser() { +// @java.lang.Override +// public PSimpleBean parsePartialFrom( +// com.google.protobuf.CodedInputStream input, +// com.google.protobuf.ExtensionRegistryLite extensionRegistry) +// throws com.google.protobuf.InvalidProtocolBufferException { +// Builder builder = newBuilder(); +// try { +// builder.mergeFrom(input, extensionRegistry); +// } catch (com.google.protobuf.InvalidProtocolBufferException e) { +// throw e.setUnfinishedMessage(builder.buildPartial()); +// } catch (com.google.protobuf.UninitializedMessageException e) { +// throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial()); +// } catch (java.io.IOException e) { +// throw new com.google.protobuf.InvalidProtocolBufferException(e) +// .setUnfinishedMessage(builder.buildPartial()); +// } +// return builder.buildPartial(); +// } +// }; +// +// public static com.google.protobuf.Parser parser() { +// return PARSER; +// } +// +// @java.lang.Override +// public com.google.protobuf.Parser getParserForType() { +// return PARSER; +// } +// +// @java.lang.Override +// public org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean getDefaultInstanceForType() { +// return DEFAULT_INSTANCE; +// } +// +// } +// +// private static final com.google.protobuf.Descriptors.Descriptor +// internal_static_PSimpleBean_descriptor; +// private static final +// com.google.protobuf.GeneratedMessageV3.FieldAccessorTable +// internal_static_PSimpleBean_fieldAccessorTable; +// private static final com.google.protobuf.Descriptors.Descriptor +// internal_static_PSimpleBean_PSimpleEntry_descriptor; +// private static final +// com.google.protobuf.GeneratedMessageV3.FieldAccessorTable +// internal_static_PSimpleBean_PSimpleEntry_fieldAccessorTable; +// private static final com.google.protobuf.Descriptors.Descriptor +// internal_static_PSimpleBean_PTwoEntry_descriptor; +// private static final +// com.google.protobuf.GeneratedMessageV3.FieldAccessorTable +// internal_static_PSimpleBean_PTwoEntry_fieldAccessorTable; +// +// public static com.google.protobuf.Descriptors.FileDescriptor +// getDescriptor() { +// return descriptor; +// } +// private static com.google.protobuf.Descriptors.FileDescriptor +// descriptor; +// static { +// java.lang.String[] descriptorData = { +// "\n:src/test/java/org/redkalex/test/protob" + +// "uf/PSimpleBean.proto\"\330\001\n\013PSimpleBean\022)\n\006" + +// "simple\030\001 \001(\0132\031.PSimpleBean.PSimpleEntry\022" + +// "#\n\003two\030\002 \001(\0132\026.PSimpleBean.PTwoEntry\022\017\n\007" + +// "strings\030\003 \001(\t\0327\n\014PSimpleEntry\022\n\n\002id\030\001 \001(" + +// "\021\022\014\n\004name\030\002 \001(\t\022\r\n\005email\030\003 \001(\t\032/\n\tPTwoEn" + +// "try\022\016\n\006status\030\001 \001(\021\022\022\n\ncreatetime\030\002 \001(\022B" + +// "\034\n\032org.redkalex.test.protobufb\006proto3" +// }; +// descriptor = com.google.protobuf.Descriptors.FileDescriptor +// .internalBuildGeneratedFileFrom(descriptorData, +// new com.google.protobuf.Descriptors.FileDescriptor[] { +// }); +// internal_static_PSimpleBean_descriptor = +// getDescriptor().getMessageTypes().get(0); +// internal_static_PSimpleBean_fieldAccessorTable = new +// com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( +// internal_static_PSimpleBean_descriptor, +// new java.lang.String[] { "Simple", "Two", "Strings", }); +// internal_static_PSimpleBean_PSimpleEntry_descriptor = +// internal_static_PSimpleBean_descriptor.getNestedTypes().get(0); +// internal_static_PSimpleBean_PSimpleEntry_fieldAccessorTable = new +// com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( +// internal_static_PSimpleBean_PSimpleEntry_descriptor, +// new java.lang.String[] { "Id", "Name", "Email", }); +// internal_static_PSimpleBean_PTwoEntry_descriptor = +// internal_static_PSimpleBean_descriptor.getNestedTypes().get(1); +// internal_static_PSimpleBean_PTwoEntry_fieldAccessorTable = new +// com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( +// internal_static_PSimpleBean_PTwoEntry_descriptor, +// new java.lang.String[] { "Status", "Createtime", }); +// } +// +// // @@protoc_insertion_point(outer_class_scope) +//} diff --git a/src/test/java/org/redkale/test/convert/protobuf/PTestBean.proto b/src/test/java/org/redkale/test/convert/protobuf/PTestBean.proto new file mode 100644 index 000000000..6f3c6bd96 --- /dev/null +++ b/src/test/java/org/redkale/test/convert/protobuf/PTestBean.proto @@ -0,0 +1,36 @@ +syntax = "proto3"; + +// 生成类的包名 +option java_package = "org.redkalex.test.protobuf"; + +message PTestBean { + + message PTestEntry { + repeated bool bools = 1; + repeated bytes bytes = 2; + repeated sint32 chars = 3; + repeated sint32 shorts = 4; + } + + repeated bool bools = 1; + repeated bytes bytes = 2; + repeated sint32 chars = 3; + repeated PTestEntry entrys = 4; + repeated sint32 ints = 5; + repeated float floats = 6; + repeated sint64 longs = 7; + repeated double doubles = 8; + repeated string strings = 9; + sint32 id = 10; + string name = 11; + string email = 12; + Kind kind = 13; + map map = 14; + string end = 15; + + enum Kind { + ONE =0; + TWO =1; + THREE =2; + } +} diff --git a/src/test/java/org/redkale/test/convert/protobuf/PTestBeanOuterClass.java b/src/test/java/org/redkale/test/convert/protobuf/PTestBeanOuterClass.java new file mode 100644 index 000000000..7578c0954 --- /dev/null +++ b/src/test/java/org/redkale/test/convert/protobuf/PTestBeanOuterClass.java @@ -0,0 +1,4539 @@ +package org.redkale.test.convert.protobuf; + +//// Generated by the protocol buffer compiler. DO NOT EDIT! +//// source: src/test/java/org/redkalex/test/protobuf/PTestBean.proto +// +//package org.redkalex.test.protobuf; +// +//public final class PTestBeanOuterClass { +// private PTestBeanOuterClass() {} +// public static void registerAllExtensions( +// com.google.protobuf.ExtensionRegistryLite registry) { +// } +// +// public static void registerAllExtensions( +// com.google.protobuf.ExtensionRegistry registry) { +// registerAllExtensions( +// (com.google.protobuf.ExtensionRegistryLite) registry); +// } +// public interface PTestBeanOrBuilder extends +// // @@protoc_insertion_point(interface_extends:PTestBean) +// com.google.protobuf.MessageOrBuilder { +// +// /** +// * repeated bool bools = 1; +// * @return A list containing the bools. +// */ +// java.util.List getBoolsList(); +// /** +// * repeated bool bools = 1; +// * @return The count of bools. +// */ +// int getBoolsCount(); +// /** +// * repeated bool bools = 1; +// * @param index The index of the element to return. +// * @return The bools at the given index. +// */ +// boolean getBools(int index); +// +// /** +// * repeated bytes bytes = 2; +// * @return A list containing the bytes. +// */ +// java.util.List getBytesList(); +// /** +// * repeated bytes bytes = 2; +// * @return The count of bytes. +// */ +// int getBytesCount(); +// /** +// * repeated bytes bytes = 2; +// * @param index The index of the element to return. +// * @return The bytes at the given index. +// */ +// com.google.protobuf.ByteString getBytes(int index); +// +// /** +// * repeated sint32 chars = 3; +// * @return A list containing the chars. +// */ +// java.util.List getCharsList(); +// /** +// * repeated sint32 chars = 3; +// * @return The count of chars. +// */ +// int getCharsCount(); +// /** +// * repeated sint32 chars = 3; +// * @param index The index of the element to return. +// * @return The chars at the given index. +// */ +// int getChars(int index); +// +// /** +// * repeated .PTestBean.PTestEntry entrys = 4; +// */ +// java.util.List +// getEntrysList(); +// /** +// * repeated .PTestBean.PTestEntry entrys = 4; +// */ +// org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry getEntrys(int index); +// /** +// * repeated .PTestBean.PTestEntry entrys = 4; +// */ +// int getEntrysCount(); +// /** +// * repeated .PTestBean.PTestEntry entrys = 4; +// */ +// java.util.List +// getEntrysOrBuilderList(); +// /** +// * repeated .PTestBean.PTestEntry entrys = 4; +// */ +// org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntryOrBuilder getEntrysOrBuilder( +// int index); +// +// /** +// * repeated sint32 ints = 5; +// * @return A list containing the ints. +// */ +// java.util.List getIntsList(); +// /** +// * repeated sint32 ints = 5; +// * @return The count of ints. +// */ +// int getIntsCount(); +// /** +// * repeated sint32 ints = 5; +// * @param index The index of the element to return. +// * @return The ints at the given index. +// */ +// int getInts(int index); +// +// /** +// * repeated float floats = 6; +// * @return A list containing the floats. +// */ +// java.util.List getFloatsList(); +// /** +// * repeated float floats = 6; +// * @return The count of floats. +// */ +// int getFloatsCount(); +// /** +// * repeated float floats = 6; +// * @param index The index of the element to return. +// * @return The floats at the given index. +// */ +// float getFloats(int index); +// +// /** +// * repeated sint64 longs = 7; +// * @return A list containing the longs. +// */ +// java.util.List getLongsList(); +// /** +// * repeated sint64 longs = 7; +// * @return The count of longs. +// */ +// int getLongsCount(); +// /** +// * repeated sint64 longs = 7; +// * @param index The index of the element to return. +// * @return The longs at the given index. +// */ +// long getLongs(int index); +// +// /** +// * repeated double doubles = 8; +// * @return A list containing the doubles. +// */ +// java.util.List getDoublesList(); +// /** +// * repeated double doubles = 8; +// * @return The count of doubles. +// */ +// int getDoublesCount(); +// /** +// * repeated double doubles = 8; +// * @param index The index of the element to return. +// * @return The doubles at the given index. +// */ +// double getDoubles(int index); +// +// /** +// * repeated string strings = 9; +// * @return A list containing the strings. +// */ +// java.util.List +// getStringsList(); +// /** +// * repeated string strings = 9; +// * @return The count of strings. +// */ +// int getStringsCount(); +// /** +// * repeated string strings = 9; +// * @param index The index of the element to return. +// * @return The strings at the given index. +// */ +// java.lang.String getStrings(int index); +// /** +// * repeated string strings = 9; +// * @param index The index of the value to return. +// * @return The bytes of the strings at the given index. +// */ +// com.google.protobuf.ByteString +// getStringsBytes(int index); +// +// /** +// * sint32 id = 10; +// * @return The id. +// */ +// int getId(); +// +// /** +// * string name = 11; +// * @return The name. +// */ +// java.lang.String getName(); +// /** +// * string name = 11; +// * @return The bytes for name. +// */ +// com.google.protobuf.ByteString +// getNameBytes(); +// +// /** +// * string email = 12; +// * @return The email. +// */ +// java.lang.String getEmail(); +// /** +// * string email = 12; +// * @return The bytes for email. +// */ +// com.google.protobuf.ByteString +// getEmailBytes(); +// +// /** +// * .PTestBean.Kind kind = 13; +// * @return The enum numeric value on the wire for kind. +// */ +// int getKindValue(); +// /** +// * .PTestBean.Kind kind = 13; +// * @return The kind. +// */ +// org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.Kind getKind(); +// +// /** +// * map<string, sint32> map = 14; +// */ +// int getMapCount(); +// /** +// * map<string, sint32> map = 14; +// */ +// boolean containsMap( +// java.lang.String key); +// /** +// * Use {@link #getMapMap()} instead. +// */ +// @java.lang.Deprecated +// java.util.Map +// getMap(); +// /** +// * map<string, sint32> map = 14; +// */ +// java.util.Map +// getMapMap(); +// /** +// * map<string, sint32> map = 14; +// */ +// int getMapOrDefault( +// java.lang.String key, +// int defaultValue); +// /** +// * map<string, sint32> map = 14; +// */ +// int getMapOrThrow( +// java.lang.String key); +// +// /** +// * string end = 15; +// * @return The end. +// */ +// java.lang.String getEnd(); +// /** +// * string end = 15; +// * @return The bytes for end. +// */ +// com.google.protobuf.ByteString +// getEndBytes(); +// } +// /** +// * Protobuf type {@code PTestBean} +// */ +// public static final class PTestBean extends +// com.google.protobuf.GeneratedMessageV3 implements +// // @@protoc_insertion_point(message_implements:PTestBean) +// PTestBeanOrBuilder { +// private static final long serialVersionUID = 0L; +// // Use PTestBean.newBuilder() to construct. +// private PTestBean(com.google.protobuf.GeneratedMessageV3.Builder builder) { +// super(builder); +// } +// private PTestBean() { +// bools_ = emptyBooleanList(); +// bytes_ = java.util.Collections.emptyList(); +// chars_ = emptyIntList(); +// entrys_ = java.util.Collections.emptyList(); +// ints_ = emptyIntList(); +// floats_ = emptyFloatList(); +// longs_ = emptyLongList(); +// doubles_ = emptyDoubleList(); +// strings_ = +// com.google.protobuf.LazyStringArrayList.emptyList(); +// name_ = ""; +// email_ = ""; +// kind_ = 0; +// end_ = ""; +// } +// +// @java.lang.Override +// @SuppressWarnings({"unused"}) +// protected java.lang.Object newInstance( +// UnusedPrivateParameter unused) { +// return new PTestBean(); +// } +// +// public static final com.google.protobuf.Descriptors.Descriptor +// getDescriptor() { +// return org.redkalex.test.protobuf.PTestBeanOuterClass.internal_static_PTestBean_descriptor; +// } +// +// @SuppressWarnings({"rawtypes"}) +// @java.lang.Override +// protected com.google.protobuf.MapField internalGetMapField( +// int number) { +// switch (number) { +// case 14: +// return internalGetMap(); +// default: +// throw new RuntimeException( +// "Invalid map field number: " + number); +// } +// } +// @java.lang.Override +// protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable +// internalGetFieldAccessorTable() { +// return org.redkalex.test.protobuf.PTestBeanOuterClass.internal_static_PTestBean_fieldAccessorTable +// .ensureFieldAccessorsInitialized( +// org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.class, org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.Builder.class); +// } +// +// /** +// * Protobuf enum {@code PTestBean.Kind} +// */ +// public enum Kind +// implements com.google.protobuf.ProtocolMessageEnum { +// /** +// * ONE = 0; +// */ +// ONE(0), +// /** +// * TWO = 1; +// */ +// TWO(1), +// /** +// * THREE = 2; +// */ +// THREE(2), +// UNRECOGNIZED(-1), +// ; +// +// /** +// * ONE = 0; +// */ +// public static final int ONE_VALUE = 0; +// /** +// * TWO = 1; +// */ +// public static final int TWO_VALUE = 1; +// /** +// * THREE = 2; +// */ +// public static final int THREE_VALUE = 2; +// +// +// public final int getNumber() { +// if (this == UNRECOGNIZED) { +// throw new java.lang.IllegalArgumentException( +// "Can't get the number of an unknown enum value."); +// } +// return value; +// } +// +// /** +// * @param value The numeric wire value of the corresponding enum entry. +// * @return The enum associated with the given numeric wire value. +// * @deprecated Use {@link #forNumber(int)} instead. +// */ +// @java.lang.Deprecated +// public static Kind valueOf(int value) { +// return forNumber(value); +// } +// +// /** +// * @param value The numeric wire value of the corresponding enum entry. +// * @return The enum associated with the given numeric wire value. +// */ +// public static Kind forNumber(int value) { +// switch (value) { +// case 0: return ONE; +// case 1: return TWO; +// case 2: return THREE; +// default: return null; +// } +// } +// +// public static com.google.protobuf.Internal.EnumLiteMap +// internalGetValueMap() { +// return internalValueMap; +// } +// private static final com.google.protobuf.Internal.EnumLiteMap< +// Kind> internalValueMap = +// new com.google.protobuf.Internal.EnumLiteMap() { +// public Kind findValueByNumber(int number) { +// return Kind.forNumber(number); +// } +// }; +// +// public final com.google.protobuf.Descriptors.EnumValueDescriptor +// getValueDescriptor() { +// if (this == UNRECOGNIZED) { +// throw new java.lang.IllegalStateException( +// "Can't get the descriptor of an unrecognized enum value."); +// } +// return getDescriptor().getValues().get(ordinal()); +// } +// public final com.google.protobuf.Descriptors.EnumDescriptor +// getDescriptorForType() { +// return getDescriptor(); +// } +// public static final com.google.protobuf.Descriptors.EnumDescriptor +// getDescriptor() { +// return org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.getDescriptor().getEnumTypes().get(0); +// } +// +// private static final Kind[] VALUES = values(); +// +// public static Kind valueOf( +// com.google.protobuf.Descriptors.EnumValueDescriptor desc) { +// if (desc.getType() != getDescriptor()) { +// throw new java.lang.IllegalArgumentException( +// "EnumValueDescriptor is not for this type."); +// } +// if (desc.getIndex() == -1) { +// return UNRECOGNIZED; +// } +// return VALUES[desc.getIndex()]; +// } +// +// private final int value; +// +// private Kind(int value) { +// this.value = value; +// } +// +// // @@protoc_insertion_point(enum_scope:PTestBean.Kind) +// } +// +// public interface PTestEntryOrBuilder extends +// // @@protoc_insertion_point(interface_extends:PTestBean.PTestEntry) +// com.google.protobuf.MessageOrBuilder { +// +// /** +// * repeated bool bools = 1; +// * @return A list containing the bools. +// */ +// java.util.List getBoolsList(); +// /** +// * repeated bool bools = 1; +// * @return The count of bools. +// */ +// int getBoolsCount(); +// /** +// * repeated bool bools = 1; +// * @param index The index of the element to return. +// * @return The bools at the given index. +// */ +// boolean getBools(int index); +// +// /** +// * repeated bytes bytes = 2; +// * @return A list containing the bytes. +// */ +// java.util.List getBytesList(); +// /** +// * repeated bytes bytes = 2; +// * @return The count of bytes. +// */ +// int getBytesCount(); +// /** +// * repeated bytes bytes = 2; +// * @param index The index of the element to return. +// * @return The bytes at the given index. +// */ +// com.google.protobuf.ByteString getBytes(int index); +// +// /** +// * repeated sint32 chars = 3; +// * @return A list containing the chars. +// */ +// java.util.List getCharsList(); +// /** +// * repeated sint32 chars = 3; +// * @return The count of chars. +// */ +// int getCharsCount(); +// /** +// * repeated sint32 chars = 3; +// * @param index The index of the element to return. +// * @return The chars at the given index. +// */ +// int getChars(int index); +// +// /** +// * repeated sint32 shorts = 4; +// * @return A list containing the shorts. +// */ +// java.util.List getShortsList(); +// /** +// * repeated sint32 shorts = 4; +// * @return The count of shorts. +// */ +// int getShortsCount(); +// /** +// * repeated sint32 shorts = 4; +// * @param index The index of the element to return. +// * @return The shorts at the given index. +// */ +// int getShorts(int index); +// } +// /** +// * Protobuf type {@code PTestBean.PTestEntry} +// */ +// public static final class PTestEntry extends +// com.google.protobuf.GeneratedMessageV3 implements +// // @@protoc_insertion_point(message_implements:PTestBean.PTestEntry) +// PTestEntryOrBuilder { +// private static final long serialVersionUID = 0L; +// // Use PTestEntry.newBuilder() to construct. +// private PTestEntry(com.google.protobuf.GeneratedMessageV3.Builder builder) { +// super(builder); +// } +// private PTestEntry() { +// bools_ = emptyBooleanList(); +// bytes_ = java.util.Collections.emptyList(); +// chars_ = emptyIntList(); +// shorts_ = emptyIntList(); +// } +// +// @java.lang.Override +// @SuppressWarnings({"unused"}) +// protected java.lang.Object newInstance( +// UnusedPrivateParameter unused) { +// return new PTestEntry(); +// } +// +// public static final com.google.protobuf.Descriptors.Descriptor +// getDescriptor() { +// return org.redkalex.test.protobuf.PTestBeanOuterClass.internal_static_PTestBean_PTestEntry_descriptor; +// } +// +// @java.lang.Override +// protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable +// internalGetFieldAccessorTable() { +// return org.redkalex.test.protobuf.PTestBeanOuterClass.internal_static_PTestBean_PTestEntry_fieldAccessorTable +// .ensureFieldAccessorsInitialized( +// org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry.class, org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry.Builder.class); +// } +// +// public static final int BOOLS_FIELD_NUMBER = 1; +// @SuppressWarnings("serial") +// private com.google.protobuf.Internal.BooleanList bools_; +// /** +// * repeated bool bools = 1; +// * @return A list containing the bools. +// */ +// @java.lang.Override +// public java.util.List +// getBoolsList() { +// return bools_; +// } +// /** +// * repeated bool bools = 1; +// * @return The count of bools. +// */ +// public int getBoolsCount() { +// return bools_.size(); +// } +// /** +// * repeated bool bools = 1; +// * @param index The index of the element to return. +// * @return The bools at the given index. +// */ +// public boolean getBools(int index) { +// return bools_.getBoolean(index); +// } +// private int boolsMemoizedSerializedSize = -1; +// +// public static final int BYTES_FIELD_NUMBER = 2; +// @SuppressWarnings("serial") +// private java.util.List bytes_; +// /** +// * repeated bytes bytes = 2; +// * @return A list containing the bytes. +// */ +// @java.lang.Override +// public java.util.List +// getBytesList() { +// return bytes_; +// } +// /** +// * repeated bytes bytes = 2; +// * @return The count of bytes. +// */ +// public int getBytesCount() { +// return bytes_.size(); +// } +// /** +// * repeated bytes bytes = 2; +// * @param index The index of the element to return. +// * @return The bytes at the given index. +// */ +// public com.google.protobuf.ByteString getBytes(int index) { +// return bytes_.get(index); +// } +// +// public static final int CHARS_FIELD_NUMBER = 3; +// @SuppressWarnings("serial") +// private com.google.protobuf.Internal.IntList chars_; +// /** +// * repeated sint32 chars = 3; +// * @return A list containing the chars. +// */ +// @java.lang.Override +// public java.util.List +// getCharsList() { +// return chars_; +// } +// /** +// * repeated sint32 chars = 3; +// * @return The count of chars. +// */ +// public int getCharsCount() { +// return chars_.size(); +// } +// /** +// * repeated sint32 chars = 3; +// * @param index The index of the element to return. +// * @return The chars at the given index. +// */ +// public int getChars(int index) { +// return chars_.getInt(index); +// } +// private int charsMemoizedSerializedSize = -1; +// +// public static final int SHORTS_FIELD_NUMBER = 4; +// @SuppressWarnings("serial") +// private com.google.protobuf.Internal.IntList shorts_; +// /** +// * repeated sint32 shorts = 4; +// * @return A list containing the shorts. +// */ +// @java.lang.Override +// public java.util.List +// getShortsList() { +// return shorts_; +// } +// /** +// * repeated sint32 shorts = 4; +// * @return The count of shorts. +// */ +// public int getShortsCount() { +// return shorts_.size(); +// } +// /** +// * repeated sint32 shorts = 4; +// * @param index The index of the element to return. +// * @return The shorts at the given index. +// */ +// public int getShorts(int index) { +// return shorts_.getInt(index); +// } +// private int shortsMemoizedSerializedSize = -1; +// +// private byte memoizedIsInitialized = -1; +// @java.lang.Override +// public final boolean isInitialized() { +// byte isInitialized = memoizedIsInitialized; +// if (isInitialized == 1) return true; +// if (isInitialized == 0) return false; +// +// memoizedIsInitialized = 1; +// return true; +// } +// +// @java.lang.Override +// public void writeTo(com.google.protobuf.CodedOutputStream output) +// throws java.io.IOException { +// getSerializedSize(); +// if (getBoolsList().size() > 0) { +// output.writeUInt32NoTag(10); +// output.writeUInt32NoTag(boolsMemoizedSerializedSize); +// } +// for (int i = 0; i < bools_.size(); i++) { +// output.writeBoolNoTag(bools_.getBoolean(i)); +// } +// for (int i = 0; i < bytes_.size(); i++) { +// output.writeBytes(2, bytes_.get(i)); +// } +// if (getCharsList().size() > 0) { +// output.writeUInt32NoTag(26); +// output.writeUInt32NoTag(charsMemoizedSerializedSize); +// } +// for (int i = 0; i < chars_.size(); i++) { +// output.writeSInt32NoTag(chars_.getInt(i)); +// } +// if (getShortsList().size() > 0) { +// output.writeUInt32NoTag(34); +// output.writeUInt32NoTag(shortsMemoizedSerializedSize); +// } +// for (int i = 0; i < shorts_.size(); i++) { +// output.writeSInt32NoTag(shorts_.getInt(i)); +// } +// getUnknownFields().writeTo(output); +// } +// +// @java.lang.Override +// public int getSerializedSize() { +// int size = memoizedSize; +// if (size != -1) return size; +// +// size = 0; +// { +// int dataSize = 0; +// dataSize = 1 * getBoolsList().size(); +// size += dataSize; +// if (!getBoolsList().isEmpty()) { +// size += 1; +// size += com.google.protobuf.CodedOutputStream +// .computeInt32SizeNoTag(dataSize); +// } +// boolsMemoizedSerializedSize = dataSize; +// } +// { +// int dataSize = 0; +// for (int i = 0; i < bytes_.size(); i++) { +// dataSize += com.google.protobuf.CodedOutputStream +// .computeBytesSizeNoTag(bytes_.get(i)); +// } +// size += dataSize; +// size += 1 * getBytesList().size(); +// } +// { +// int dataSize = 0; +// for (int i = 0; i < chars_.size(); i++) { +// dataSize += com.google.protobuf.CodedOutputStream +// .computeSInt32SizeNoTag(chars_.getInt(i)); +// } +// size += dataSize; +// if (!getCharsList().isEmpty()) { +// size += 1; +// size += com.google.protobuf.CodedOutputStream +// .computeInt32SizeNoTag(dataSize); +// } +// charsMemoizedSerializedSize = dataSize; +// } +// { +// int dataSize = 0; +// for (int i = 0; i < shorts_.size(); i++) { +// dataSize += com.google.protobuf.CodedOutputStream +// .computeSInt32SizeNoTag(shorts_.getInt(i)); +// } +// size += dataSize; +// if (!getShortsList().isEmpty()) { +// size += 1; +// size += com.google.protobuf.CodedOutputStream +// .computeInt32SizeNoTag(dataSize); +// } +// shortsMemoizedSerializedSize = dataSize; +// } +// size += getUnknownFields().getSerializedSize(); +// memoizedSize = size; +// return size; +// } +// +// @java.lang.Override +// public boolean equals(final java.lang.Object obj) { +// if (obj == this) { +// return true; +// } +// if (!(obj instanceof org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry)) { +// return super.equals(obj); +// } +// org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry other = (org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry) obj; +// +// if (!getBoolsList() +// .equals(other.getBoolsList())) return false; +// if (!getBytesList() +// .equals(other.getBytesList())) return false; +// if (!getCharsList() +// .equals(other.getCharsList())) return false; +// if (!getShortsList() +// .equals(other.getShortsList())) return false; +// if (!getUnknownFields().equals(other.getUnknownFields())) return false; +// return true; +// } +// +// @java.lang.Override +// public int hashCode() { +// if (memoizedHashCode != 0) { +// return memoizedHashCode; +// } +// int hash = 41; +// hash = (19 * hash) + getDescriptor().hashCode(); +// if (getBoolsCount() > 0) { +// hash = (37 * hash) + BOOLS_FIELD_NUMBER; +// hash = (53 * hash) + getBoolsList().hashCode(); +// } +// if (getBytesCount() > 0) { +// hash = (37 * hash) + BYTES_FIELD_NUMBER; +// hash = (53 * hash) + getBytesList().hashCode(); +// } +// if (getCharsCount() > 0) { +// hash = (37 * hash) + CHARS_FIELD_NUMBER; +// hash = (53 * hash) + getCharsList().hashCode(); +// } +// if (getShortsCount() > 0) { +// hash = (37 * hash) + SHORTS_FIELD_NUMBER; +// hash = (53 * hash) + getShortsList().hashCode(); +// } +// hash = (29 * hash) + getUnknownFields().hashCode(); +// memoizedHashCode = hash; +// return hash; +// } +// +// public static org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry parseFrom( +// java.nio.ByteBuffer data) +// throws com.google.protobuf.InvalidProtocolBufferException { +// return PARSER.parseFrom(data); +// } +// public static org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry parseFrom( +// java.nio.ByteBuffer data, +// com.google.protobuf.ExtensionRegistryLite extensionRegistry) +// throws com.google.protobuf.InvalidProtocolBufferException { +// return PARSER.parseFrom(data, extensionRegistry); +// } +// public static org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry parseFrom( +// com.google.protobuf.ByteString data) +// throws com.google.protobuf.InvalidProtocolBufferException { +// return PARSER.parseFrom(data); +// } +// public static org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry parseFrom( +// com.google.protobuf.ByteString data, +// com.google.protobuf.ExtensionRegistryLite extensionRegistry) +// throws com.google.protobuf.InvalidProtocolBufferException { +// return PARSER.parseFrom(data, extensionRegistry); +// } +// public static org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry parseFrom(byte[] data) +// throws com.google.protobuf.InvalidProtocolBufferException { +// return PARSER.parseFrom(data); +// } +// public static org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry parseFrom( +// byte[] data, +// com.google.protobuf.ExtensionRegistryLite extensionRegistry) +// throws com.google.protobuf.InvalidProtocolBufferException { +// return PARSER.parseFrom(data, extensionRegistry); +// } +// public static org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry parseFrom(java.io.InputStream input) +// throws java.io.IOException { +// return com.google.protobuf.GeneratedMessageV3 +// .parseWithIOException(PARSER, input); +// } +// public static org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry parseFrom( +// java.io.InputStream input, +// com.google.protobuf.ExtensionRegistryLite extensionRegistry) +// throws java.io.IOException { +// return com.google.protobuf.GeneratedMessageV3 +// .parseWithIOException(PARSER, input, extensionRegistry); +// } +// +// public static org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry parseDelimitedFrom(java.io.InputStream input) +// throws java.io.IOException { +// return com.google.protobuf.GeneratedMessageV3 +// .parseDelimitedWithIOException(PARSER, input); +// } +// +// public static org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry parseDelimitedFrom( +// java.io.InputStream input, +// com.google.protobuf.ExtensionRegistryLite extensionRegistry) +// throws java.io.IOException { +// return com.google.protobuf.GeneratedMessageV3 +// .parseDelimitedWithIOException(PARSER, input, extensionRegistry); +// } +// public static org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry parseFrom( +// com.google.protobuf.CodedInputStream input) +// throws java.io.IOException { +// return com.google.protobuf.GeneratedMessageV3 +// .parseWithIOException(PARSER, input); +// } +// public static org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry parseFrom( +// com.google.protobuf.CodedInputStream input, +// com.google.protobuf.ExtensionRegistryLite extensionRegistry) +// throws java.io.IOException { +// return com.google.protobuf.GeneratedMessageV3 +// .parseWithIOException(PARSER, input, extensionRegistry); +// } +// +// @java.lang.Override +// public Builder newBuilderForType() { return newBuilder(); } +// public static Builder newBuilder() { +// return DEFAULT_INSTANCE.toBuilder(); +// } +// public static Builder newBuilder(org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry prototype) { +// return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); +// } +// @java.lang.Override +// public Builder toBuilder() { +// return this == DEFAULT_INSTANCE +// ? new Builder() : new Builder().mergeFrom(this); +// } +// +// @java.lang.Override +// protected Builder newBuilderForType( +// com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { +// Builder builder = new Builder(parent); +// return builder; +// } +// /** +// * Protobuf type {@code PTestBean.PTestEntry} +// */ +// public static final class Builder extends +// com.google.protobuf.GeneratedMessageV3.Builder implements +// // @@protoc_insertion_point(builder_implements:PTestBean.PTestEntry) +// org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntryOrBuilder { +// public static final com.google.protobuf.Descriptors.Descriptor +// getDescriptor() { +// return org.redkalex.test.protobuf.PTestBeanOuterClass.internal_static_PTestBean_PTestEntry_descriptor; +// } +// +// @java.lang.Override +// protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable +// internalGetFieldAccessorTable() { +// return org.redkalex.test.protobuf.PTestBeanOuterClass.internal_static_PTestBean_PTestEntry_fieldAccessorTable +// .ensureFieldAccessorsInitialized( +// org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry.class, org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry.Builder.class); +// } +// +// // Construct using org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry.newBuilder() +// private Builder() { +// +// } +// +// private Builder( +// com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { +// super(parent); +// +// } +// @java.lang.Override +// public Builder clear() { +// super.clear(); +// bitField0_ = 0; +// bools_ = emptyBooleanList(); +// bytes_ = java.util.Collections.emptyList(); +// chars_ = emptyIntList(); +// shorts_ = emptyIntList(); +// return this; +// } +// +// @java.lang.Override +// public com.google.protobuf.Descriptors.Descriptor +// getDescriptorForType() { +// return org.redkalex.test.protobuf.PTestBeanOuterClass.internal_static_PTestBean_PTestEntry_descriptor; +// } +// +// @java.lang.Override +// public org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry getDefaultInstanceForType() { +// return org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry.getDefaultInstance(); +// } +// +// @java.lang.Override +// public org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry build() { +// org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry result = buildPartial(); +// if (!result.isInitialized()) { +// throw newUninitializedMessageException(result); +// } +// return result; +// } +// +// @java.lang.Override +// public org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry buildPartial() { +// org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry result = new org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry(this); +// buildPartialRepeatedFields(result); +// if (bitField0_ != 0) { buildPartial0(result); } +// onBuilt(); +// return result; +// } +// +// private void buildPartialRepeatedFields(org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry result) { +// if (((bitField0_ & 0x00000001) != 0)) { +// bools_.makeImmutable(); +// bitField0_ = (bitField0_ & ~0x00000001); +// } +// result.bools_ = bools_; +// if (((bitField0_ & 0x00000002) != 0)) { +// bytes_ = java.util.Collections.unmodifiableList(bytes_); +// bitField0_ = (bitField0_ & ~0x00000002); +// } +// result.bytes_ = bytes_; +// if (((bitField0_ & 0x00000004) != 0)) { +// chars_.makeImmutable(); +// bitField0_ = (bitField0_ & ~0x00000004); +// } +// result.chars_ = chars_; +// if (((bitField0_ & 0x00000008) != 0)) { +// shorts_.makeImmutable(); +// bitField0_ = (bitField0_ & ~0x00000008); +// } +// result.shorts_ = shorts_; +// } +// +// private void buildPartial0(org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry result) { +// int from_bitField0_ = bitField0_; +// } +// +// @java.lang.Override +// public Builder clone() { +// return super.clone(); +// } +// @java.lang.Override +// public Builder setField( +// com.google.protobuf.Descriptors.FieldDescriptor field, +// java.lang.Object value) { +// return super.setField(field, value); +// } +// @java.lang.Override +// public Builder clearField( +// com.google.protobuf.Descriptors.FieldDescriptor field) { +// return super.clearField(field); +// } +// @java.lang.Override +// public Builder clearOneof( +// com.google.protobuf.Descriptors.OneofDescriptor oneof) { +// return super.clearOneof(oneof); +// } +// @java.lang.Override +// public Builder setRepeatedField( +// com.google.protobuf.Descriptors.FieldDescriptor field, +// int index, java.lang.Object value) { +// return super.setRepeatedField(field, index, value); +// } +// @java.lang.Override +// public Builder addRepeatedField( +// com.google.protobuf.Descriptors.FieldDescriptor field, +// java.lang.Object value) { +// return super.addRepeatedField(field, value); +// } +// @java.lang.Override +// public Builder mergeFrom(com.google.protobuf.Message other) { +// if (other instanceof org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry) { +// return mergeFrom((org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry)other); +// } else { +// super.mergeFrom(other); +// return this; +// } +// } +// +// public Builder mergeFrom(org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry other) { +// if (other == org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry.getDefaultInstance()) return this; +// if (!other.bools_.isEmpty()) { +// if (bools_.isEmpty()) { +// bools_ = other.bools_; +// bitField0_ = (bitField0_ & ~0x00000001); +// } else { +// ensureBoolsIsMutable(); +// bools_.addAll(other.bools_); +// } +// onChanged(); +// } +// if (!other.bytes_.isEmpty()) { +// if (bytes_.isEmpty()) { +// bytes_ = other.bytes_; +// bitField0_ = (bitField0_ & ~0x00000002); +// } else { +// ensureBytesIsMutable(); +// bytes_.addAll(other.bytes_); +// } +// onChanged(); +// } +// if (!other.chars_.isEmpty()) { +// if (chars_.isEmpty()) { +// chars_ = other.chars_; +// bitField0_ = (bitField0_ & ~0x00000004); +// } else { +// ensureCharsIsMutable(); +// chars_.addAll(other.chars_); +// } +// onChanged(); +// } +// if (!other.shorts_.isEmpty()) { +// if (shorts_.isEmpty()) { +// shorts_ = other.shorts_; +// bitField0_ = (bitField0_ & ~0x00000008); +// } else { +// ensureShortsIsMutable(); +// shorts_.addAll(other.shorts_); +// } +// onChanged(); +// } +// this.mergeUnknownFields(other.getUnknownFields()); +// onChanged(); +// return this; +// } +// +// @java.lang.Override +// public final boolean isInitialized() { +// return true; +// } +// +// @java.lang.Override +// public Builder mergeFrom( +// com.google.protobuf.CodedInputStream input, +// com.google.protobuf.ExtensionRegistryLite extensionRegistry) +// throws java.io.IOException { +// if (extensionRegistry == null) { +// throw new java.lang.NullPointerException(); +// } +// try { +// boolean done = false; +// while (!done) { +// int tag = input.readTag(); +// switch (tag) { +// case 0: +// done = true; +// break; +// case 8: { +// boolean v = input.readBool(); +// ensureBoolsIsMutable(); +// bools_.addBoolean(v); +// break; +// } // case 8 +// case 10: { +// int length = input.readRawVarint32(); +// int limit = input.pushLimit(length); +// ensureBoolsIsMutable(); +// while (input.getBytesUntilLimit() > 0) { +// bools_.addBoolean(input.readBool()); +// } +// input.popLimit(limit); +// break; +// } // case 10 +// case 18: { +// com.google.protobuf.ByteString v = input.readBytes(); +// ensureBytesIsMutable(); +// bytes_.add(v); +// break; +// } // case 18 +// case 24: { +// int v = input.readSInt32(); +// ensureCharsIsMutable(); +// chars_.addInt(v); +// break; +// } // case 24 +// case 26: { +// int length = input.readRawVarint32(); +// int limit = input.pushLimit(length); +// ensureCharsIsMutable(); +// while (input.getBytesUntilLimit() > 0) { +// chars_.addInt(input.readSInt32()); +// } +// input.popLimit(limit); +// break; +// } // case 26 +// case 32: { +// int v = input.readSInt32(); +// ensureShortsIsMutable(); +// shorts_.addInt(v); +// break; +// } // case 32 +// case 34: { +// int length = input.readRawVarint32(); +// int limit = input.pushLimit(length); +// ensureShortsIsMutable(); +// while (input.getBytesUntilLimit() > 0) { +// shorts_.addInt(input.readSInt32()); +// } +// input.popLimit(limit); +// break; +// } // case 34 +// default: { +// if (!super.parseUnknownField(input, extensionRegistry, tag)) { +// done = true; // was an endgroup tag +// } +// break; +// } // default: +// } // switch (tag) +// } // while (!done) +// } catch (com.google.protobuf.InvalidProtocolBufferException e) { +// throw e.unwrapIOException(); +// } finally { +// onChanged(); +// } // finally +// return this; +// } +// private int bitField0_; +// +// private com.google.protobuf.Internal.BooleanList bools_ = emptyBooleanList(); +// private void ensureBoolsIsMutable() { +// if (!((bitField0_ & 0x00000001) != 0)) { +// bools_ = mutableCopy(bools_); +// bitField0_ |= 0x00000001; +// } +// } +// /** +// * repeated bool bools = 1; +// * @return A list containing the bools. +// */ +// public java.util.List +// getBoolsList() { +// return ((bitField0_ & 0x00000001) != 0) ? +// java.util.Collections.unmodifiableList(bools_) : bools_; +// } +// /** +// * repeated bool bools = 1; +// * @return The count of bools. +// */ +// public int getBoolsCount() { +// return bools_.size(); +// } +// /** +// * repeated bool bools = 1; +// * @param index The index of the element to return. +// * @return The bools at the given index. +// */ +// public boolean getBools(int index) { +// return bools_.getBoolean(index); +// } +// /** +// * repeated bool bools = 1; +// * @param index The index to set the value at. +// * @param value The bools to set. +// * @return This builder for chaining. +// */ +// public Builder setBools( +// int index, boolean value) { +// +// ensureBoolsIsMutable(); +// bools_.setBoolean(index, value); +// onChanged(); +// return this; +// } +// /** +// * repeated bool bools = 1; +// * @param value The bools to add. +// * @return This builder for chaining. +// */ +// public Builder addBools(boolean value) { +// +// ensureBoolsIsMutable(); +// bools_.addBoolean(value); +// onChanged(); +// return this; +// } +// /** +// * repeated bool bools = 1; +// * @param values The bools to add. +// * @return This builder for chaining. +// */ +// public Builder addAllBools( +// java.lang.Iterable values) { +// ensureBoolsIsMutable(); +// com.google.protobuf.AbstractMessageLite.Builder.addAll( +// values, bools_); +// onChanged(); +// return this; +// } +// /** +// * repeated bool bools = 1; +// * @return This builder for chaining. +// */ +// public Builder clearBools() { +// bools_ = emptyBooleanList(); +// bitField0_ = (bitField0_ & ~0x00000001); +// onChanged(); +// return this; +// } +// +// private java.util.List bytes_ = java.util.Collections.emptyList(); +// private void ensureBytesIsMutable() { +// if (!((bitField0_ & 0x00000002) != 0)) { +// bytes_ = new java.util.ArrayList(bytes_); +// bitField0_ |= 0x00000002; +// } +// } +// /** +// * repeated bytes bytes = 2; +// * @return A list containing the bytes. +// */ +// public java.util.List +// getBytesList() { +// return ((bitField0_ & 0x00000002) != 0) ? +// java.util.Collections.unmodifiableList(bytes_) : bytes_; +// } +// /** +// * repeated bytes bytes = 2; +// * @return The count of bytes. +// */ +// public int getBytesCount() { +// return bytes_.size(); +// } +// /** +// * repeated bytes bytes = 2; +// * @param index The index of the element to return. +// * @return The bytes at the given index. +// */ +// public com.google.protobuf.ByteString getBytes(int index) { +// return bytes_.get(index); +// } +// /** +// * repeated bytes bytes = 2; +// * @param index The index to set the value at. +// * @param value The bytes to set. +// * @return This builder for chaining. +// */ +// public Builder setBytes( +// int index, com.google.protobuf.ByteString value) { +// if (value == null) { throw new NullPointerException(); } +// ensureBytesIsMutable(); +// bytes_.set(index, value); +// onChanged(); +// return this; +// } +// /** +// * repeated bytes bytes = 2; +// * @param value The bytes to add. +// * @return This builder for chaining. +// */ +// public Builder addBytes(com.google.protobuf.ByteString value) { +// if (value == null) { throw new NullPointerException(); } +// ensureBytesIsMutable(); +// bytes_.add(value); +// onChanged(); +// return this; +// } +// /** +// * repeated bytes bytes = 2; +// * @param values The bytes to add. +// * @return This builder for chaining. +// */ +// public Builder addAllBytes( +// java.lang.Iterable values) { +// ensureBytesIsMutable(); +// com.google.protobuf.AbstractMessageLite.Builder.addAll( +// values, bytes_); +// onChanged(); +// return this; +// } +// /** +// * repeated bytes bytes = 2; +// * @return This builder for chaining. +// */ +// public Builder clearBytes() { +// bytes_ = java.util.Collections.emptyList(); +// bitField0_ = (bitField0_ & ~0x00000002); +// onChanged(); +// return this; +// } +// +// private com.google.protobuf.Internal.IntList chars_ = emptyIntList(); +// private void ensureCharsIsMutable() { +// if (!((bitField0_ & 0x00000004) != 0)) { +// chars_ = mutableCopy(chars_); +// bitField0_ |= 0x00000004; +// } +// } +// /** +// * repeated sint32 chars = 3; +// * @return A list containing the chars. +// */ +// public java.util.List +// getCharsList() { +// return ((bitField0_ & 0x00000004) != 0) ? +// java.util.Collections.unmodifiableList(chars_) : chars_; +// } +// /** +// * repeated sint32 chars = 3; +// * @return The count of chars. +// */ +// public int getCharsCount() { +// return chars_.size(); +// } +// /** +// * repeated sint32 chars = 3; +// * @param index The index of the element to return. +// * @return The chars at the given index. +// */ +// public int getChars(int index) { +// return chars_.getInt(index); +// } +// /** +// * repeated sint32 chars = 3; +// * @param index The index to set the value at. +// * @param value The chars to set. +// * @return This builder for chaining. +// */ +// public Builder setChars( +// int index, int value) { +// +// ensureCharsIsMutable(); +// chars_.setInt(index, value); +// onChanged(); +// return this; +// } +// /** +// * repeated sint32 chars = 3; +// * @param value The chars to add. +// * @return This builder for chaining. +// */ +// public Builder addChars(int value) { +// +// ensureCharsIsMutable(); +// chars_.addInt(value); +// onChanged(); +// return this; +// } +// /** +// * repeated sint32 chars = 3; +// * @param values The chars to add. +// * @return This builder for chaining. +// */ +// public Builder addAllChars( +// java.lang.Iterable values) { +// ensureCharsIsMutable(); +// com.google.protobuf.AbstractMessageLite.Builder.addAll( +// values, chars_); +// onChanged(); +// return this; +// } +// /** +// * repeated sint32 chars = 3; +// * @return This builder for chaining. +// */ +// public Builder clearChars() { +// chars_ = emptyIntList(); +// bitField0_ = (bitField0_ & ~0x00000004); +// onChanged(); +// return this; +// } +// +// private com.google.protobuf.Internal.IntList shorts_ = emptyIntList(); +// private void ensureShortsIsMutable() { +// if (!((bitField0_ & 0x00000008) != 0)) { +// shorts_ = mutableCopy(shorts_); +// bitField0_ |= 0x00000008; +// } +// } +// /** +// * repeated sint32 shorts = 4; +// * @return A list containing the shorts. +// */ +// public java.util.List +// getShortsList() { +// return ((bitField0_ & 0x00000008) != 0) ? +// java.util.Collections.unmodifiableList(shorts_) : shorts_; +// } +// /** +// * repeated sint32 shorts = 4; +// * @return The count of shorts. +// */ +// public int getShortsCount() { +// return shorts_.size(); +// } +// /** +// * repeated sint32 shorts = 4; +// * @param index The index of the element to return. +// * @return The shorts at the given index. +// */ +// public int getShorts(int index) { +// return shorts_.getInt(index); +// } +// /** +// * repeated sint32 shorts = 4; +// * @param index The index to set the value at. +// * @param value The shorts to set. +// * @return This builder for chaining. +// */ +// public Builder setShorts( +// int index, int value) { +// +// ensureShortsIsMutable(); +// shorts_.setInt(index, value); +// onChanged(); +// return this; +// } +// /** +// * repeated sint32 shorts = 4; +// * @param value The shorts to add. +// * @return This builder for chaining. +// */ +// public Builder addShorts(int value) { +// +// ensureShortsIsMutable(); +// shorts_.addInt(value); +// onChanged(); +// return this; +// } +// /** +// * repeated sint32 shorts = 4; +// * @param values The shorts to add. +// * @return This builder for chaining. +// */ +// public Builder addAllShorts( +// java.lang.Iterable values) { +// ensureShortsIsMutable(); +// com.google.protobuf.AbstractMessageLite.Builder.addAll( +// values, shorts_); +// onChanged(); +// return this; +// } +// /** +// * repeated sint32 shorts = 4; +// * @return This builder for chaining. +// */ +// public Builder clearShorts() { +// shorts_ = emptyIntList(); +// bitField0_ = (bitField0_ & ~0x00000008); +// onChanged(); +// return this; +// } +// @java.lang.Override +// public final Builder setUnknownFields( +// final com.google.protobuf.UnknownFieldSet unknownFields) { +// return super.setUnknownFields(unknownFields); +// } +// +// @java.lang.Override +// public final Builder mergeUnknownFields( +// final com.google.protobuf.UnknownFieldSet unknownFields) { +// return super.mergeUnknownFields(unknownFields); +// } +// +// +// // @@protoc_insertion_point(builder_scope:PTestBean.PTestEntry) +// } +// +// // @@protoc_insertion_point(class_scope:PTestBean.PTestEntry) +// private static final org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry DEFAULT_INSTANCE; +// static { +// DEFAULT_INSTANCE = new org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry(); +// } +// +// public static org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry getDefaultInstance() { +// return DEFAULT_INSTANCE; +// } +// +// private static final com.google.protobuf.Parser +// PARSER = new com.google.protobuf.AbstractParser() { +// @java.lang.Override +// public PTestEntry parsePartialFrom( +// com.google.protobuf.CodedInputStream input, +// com.google.protobuf.ExtensionRegistryLite extensionRegistry) +// throws com.google.protobuf.InvalidProtocolBufferException { +// Builder builder = newBuilder(); +// try { +// builder.mergeFrom(input, extensionRegistry); +// } catch (com.google.protobuf.InvalidProtocolBufferException e) { +// throw e.setUnfinishedMessage(builder.buildPartial()); +// } catch (com.google.protobuf.UninitializedMessageException e) { +// throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial()); +// } catch (java.io.IOException e) { +// throw new com.google.protobuf.InvalidProtocolBufferException(e) +// .setUnfinishedMessage(builder.buildPartial()); +// } +// return builder.buildPartial(); +// } +// }; +// +// public static com.google.protobuf.Parser parser() { +// return PARSER; +// } +// +// @java.lang.Override +// public com.google.protobuf.Parser getParserForType() { +// return PARSER; +// } +// +// @java.lang.Override +// public org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry getDefaultInstanceForType() { +// return DEFAULT_INSTANCE; +// } +// +// } +// +// public static final int BOOLS_FIELD_NUMBER = 1; +// @SuppressWarnings("serial") +// private com.google.protobuf.Internal.BooleanList bools_; +// /** +// * repeated bool bools = 1; +// * @return A list containing the bools. +// */ +// @java.lang.Override +// public java.util.List +// getBoolsList() { +// return bools_; +// } +// /** +// * repeated bool bools = 1; +// * @return The count of bools. +// */ +// public int getBoolsCount() { +// return bools_.size(); +// } +// /** +// * repeated bool bools = 1; +// * @param index The index of the element to return. +// * @return The bools at the given index. +// */ +// public boolean getBools(int index) { +// return bools_.getBoolean(index); +// } +// private int boolsMemoizedSerializedSize = -1; +// +// public static final int BYTES_FIELD_NUMBER = 2; +// @SuppressWarnings("serial") +// private java.util.List bytes_; +// /** +// * repeated bytes bytes = 2; +// * @return A list containing the bytes. +// */ +// @java.lang.Override +// public java.util.List +// getBytesList() { +// return bytes_; +// } +// /** +// * repeated bytes bytes = 2; +// * @return The count of bytes. +// */ +// public int getBytesCount() { +// return bytes_.size(); +// } +// /** +// * repeated bytes bytes = 2; +// * @param index The index of the element to return. +// * @return The bytes at the given index. +// */ +// public com.google.protobuf.ByteString getBytes(int index) { +// return bytes_.get(index); +// } +// +// public static final int CHARS_FIELD_NUMBER = 3; +// @SuppressWarnings("serial") +// private com.google.protobuf.Internal.IntList chars_; +// /** +// * repeated sint32 chars = 3; +// * @return A list containing the chars. +// */ +// @java.lang.Override +// public java.util.List +// getCharsList() { +// return chars_; +// } +// /** +// * repeated sint32 chars = 3; +// * @return The count of chars. +// */ +// public int getCharsCount() { +// return chars_.size(); +// } +// /** +// * repeated sint32 chars = 3; +// * @param index The index of the element to return. +// * @return The chars at the given index. +// */ +// public int getChars(int index) { +// return chars_.getInt(index); +// } +// private int charsMemoizedSerializedSize = -1; +// +// public static final int ENTRYS_FIELD_NUMBER = 4; +// @SuppressWarnings("serial") +// private java.util.List entrys_; +// /** +// * repeated .PTestBean.PTestEntry entrys = 4; +// */ +// @java.lang.Override +// public java.util.List getEntrysList() { +// return entrys_; +// } +// /** +// * repeated .PTestBean.PTestEntry entrys = 4; +// */ +// @java.lang.Override +// public java.util.List +// getEntrysOrBuilderList() { +// return entrys_; +// } +// /** +// * repeated .PTestBean.PTestEntry entrys = 4; +// */ +// @java.lang.Override +// public int getEntrysCount() { +// return entrys_.size(); +// } +// /** +// * repeated .PTestBean.PTestEntry entrys = 4; +// */ +// @java.lang.Override +// public org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry getEntrys(int index) { +// return entrys_.get(index); +// } +// /** +// * repeated .PTestBean.PTestEntry entrys = 4; +// */ +// @java.lang.Override +// public org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntryOrBuilder getEntrysOrBuilder( +// int index) { +// return entrys_.get(index); +// } +// +// public static final int INTS_FIELD_NUMBER = 5; +// @SuppressWarnings("serial") +// private com.google.protobuf.Internal.IntList ints_; +// /** +// * repeated sint32 ints = 5; +// * @return A list containing the ints. +// */ +// @java.lang.Override +// public java.util.List +// getIntsList() { +// return ints_; +// } +// /** +// * repeated sint32 ints = 5; +// * @return The count of ints. +// */ +// public int getIntsCount() { +// return ints_.size(); +// } +// /** +// * repeated sint32 ints = 5; +// * @param index The index of the element to return. +// * @return The ints at the given index. +// */ +// public int getInts(int index) { +// return ints_.getInt(index); +// } +// private int intsMemoizedSerializedSize = -1; +// +// public static final int FLOATS_FIELD_NUMBER = 6; +// @SuppressWarnings("serial") +// private com.google.protobuf.Internal.FloatList floats_; +// /** +// * repeated float floats = 6; +// * @return A list containing the floats. +// */ +// @java.lang.Override +// public java.util.List +// getFloatsList() { +// return floats_; +// } +// /** +// * repeated float floats = 6; +// * @return The count of floats. +// */ +// public int getFloatsCount() { +// return floats_.size(); +// } +// /** +// * repeated float floats = 6; +// * @param index The index of the element to return. +// * @return The floats at the given index. +// */ +// public float getFloats(int index) { +// return floats_.getFloat(index); +// } +// private int floatsMemoizedSerializedSize = -1; +// +// public static final int LONGS_FIELD_NUMBER = 7; +// @SuppressWarnings("serial") +// private com.google.protobuf.Internal.LongList longs_; +// /** +// * repeated sint64 longs = 7; +// * @return A list containing the longs. +// */ +// @java.lang.Override +// public java.util.List +// getLongsList() { +// return longs_; +// } +// /** +// * repeated sint64 longs = 7; +// * @return The count of longs. +// */ +// public int getLongsCount() { +// return longs_.size(); +// } +// /** +// * repeated sint64 longs = 7; +// * @param index The index of the element to return. +// * @return The longs at the given index. +// */ +// public long getLongs(int index) { +// return longs_.getLong(index); +// } +// private int longsMemoizedSerializedSize = -1; +// +// public static final int DOUBLES_FIELD_NUMBER = 8; +// @SuppressWarnings("serial") +// private com.google.protobuf.Internal.DoubleList doubles_; +// /** +// * repeated double doubles = 8; +// * @return A list containing the doubles. +// */ +// @java.lang.Override +// public java.util.List +// getDoublesList() { +// return doubles_; +// } +// /** +// * repeated double doubles = 8; +// * @return The count of doubles. +// */ +// public int getDoublesCount() { +// return doubles_.size(); +// } +// /** +// * repeated double doubles = 8; +// * @param index The index of the element to return. +// * @return The doubles at the given index. +// */ +// public double getDoubles(int index) { +// return doubles_.getDouble(index); +// } +// private int doublesMemoizedSerializedSize = -1; +// +// public static final int STRINGS_FIELD_NUMBER = 9; +// @SuppressWarnings("serial") +// private com.google.protobuf.LazyStringArrayList strings_ = +// com.google.protobuf.LazyStringArrayList.emptyList(); +// /** +// * repeated string strings = 9; +// * @return A list containing the strings. +// */ +// public com.google.protobuf.ProtocolStringList +// getStringsList() { +// return strings_; +// } +// /** +// * repeated string strings = 9; +// * @return The count of strings. +// */ +// public int getStringsCount() { +// return strings_.size(); +// } +// /** +// * repeated string strings = 9; +// * @param index The index of the element to return. +// * @return The strings at the given index. +// */ +// public java.lang.String getStrings(int index) { +// return strings_.get(index); +// } +// /** +// * repeated string strings = 9; +// * @param index The index of the value to return. +// * @return The bytes of the strings at the given index. +// */ +// public com.google.protobuf.ByteString +// getStringsBytes(int index) { +// return strings_.getByteString(index); +// } +// +// public static final int ID_FIELD_NUMBER = 10; +// private int id_ = 0; +// /** +// * sint32 id = 10; +// * @return The id. +// */ +// @java.lang.Override +// public int getId() { +// return id_; +// } +// +// public static final int NAME_FIELD_NUMBER = 11; +// @SuppressWarnings("serial") +// private volatile java.lang.Object name_ = ""; +// /** +// * string name = 11; +// * @return The name. +// */ +// @java.lang.Override +// public java.lang.String getName() { +// java.lang.Object ref = name_; +// if (ref instanceof java.lang.String) { +// return (java.lang.String) ref; +// } else { +// com.google.protobuf.ByteString bs = +// (com.google.protobuf.ByteString) ref; +// java.lang.String s = bs.toStringUtf8(); +// name_ = s; +// return s; +// } +// } +// /** +// * string name = 11; +// * @return The bytes for name. +// */ +// @java.lang.Override +// public com.google.protobuf.ByteString +// getNameBytes() { +// java.lang.Object ref = name_; +// if (ref instanceof java.lang.String) { +// com.google.protobuf.ByteString b = +// com.google.protobuf.ByteString.copyFromUtf8( +// (java.lang.String) ref); +// name_ = b; +// return b; +// } else { +// return (com.google.protobuf.ByteString) ref; +// } +// } +// +// public static final int EMAIL_FIELD_NUMBER = 12; +// @SuppressWarnings("serial") +// private volatile java.lang.Object email_ = ""; +// /** +// * string email = 12; +// * @return The email. +// */ +// @java.lang.Override +// public java.lang.String getEmail() { +// java.lang.Object ref = email_; +// if (ref instanceof java.lang.String) { +// return (java.lang.String) ref; +// } else { +// com.google.protobuf.ByteString bs = +// (com.google.protobuf.ByteString) ref; +// java.lang.String s = bs.toStringUtf8(); +// email_ = s; +// return s; +// } +// } +// /** +// * string email = 12; +// * @return The bytes for email. +// */ +// @java.lang.Override +// public com.google.protobuf.ByteString +// getEmailBytes() { +// java.lang.Object ref = email_; +// if (ref instanceof java.lang.String) { +// com.google.protobuf.ByteString b = +// com.google.protobuf.ByteString.copyFromUtf8( +// (java.lang.String) ref); +// email_ = b; +// return b; +// } else { +// return (com.google.protobuf.ByteString) ref; +// } +// } +// +// public static final int KIND_FIELD_NUMBER = 13; +// private int kind_ = 0; +// /** +// * .PTestBean.Kind kind = 13; +// * @return The enum numeric value on the wire for kind. +// */ +// @java.lang.Override public int getKindValue() { +// return kind_; +// } +// /** +// * .PTestBean.Kind kind = 13; +// * @return The kind. +// */ +// @java.lang.Override public org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.Kind getKind() { +// org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.Kind result = org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.Kind.forNumber(kind_); +// return result == null ? org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.Kind.UNRECOGNIZED : result; +// } +// +// public static final int MAP_FIELD_NUMBER = 14; +// private static final class MapDefaultEntryHolder { +// static final com.google.protobuf.MapEntry< +// java.lang.String, java.lang.Integer> defaultEntry = +// com.google.protobuf.MapEntry +// .newDefaultInstance( +// org.redkalex.test.protobuf.PTestBeanOuterClass.internal_static_PTestBean_MapEntry_descriptor, +// com.google.protobuf.WireFormat.FieldType.STRING, +// "", +// com.google.protobuf.WireFormat.FieldType.SINT32, +// 0); +// } +// @SuppressWarnings("serial") +// private com.google.protobuf.MapField< +// java.lang.String, java.lang.Integer> map_; +// private com.google.protobuf.MapField +// internalGetMap() { +// if (map_ == null) { +// return com.google.protobuf.MapField.emptyMapField( +// MapDefaultEntryHolder.defaultEntry); +// } +// return map_; +// } +// public int getMapCount() { +// return internalGetMap().getMap().size(); +// } +// /** +// * map<string, sint32> map = 14; +// */ +// @java.lang.Override +// public boolean containsMap( +// java.lang.String key) { +// if (key == null) { throw new NullPointerException("map key"); } +// return internalGetMap().getMap().containsKey(key); +// } +// /** +// * Use {@link #getMapMap()} instead. +// */ +// @java.lang.Override +// @java.lang.Deprecated +// public java.util.Map getMap() { +// return getMapMap(); +// } +// /** +// * map<string, sint32> map = 14; +// */ +// @java.lang.Override +// public java.util.Map getMapMap() { +// return internalGetMap().getMap(); +// } +// /** +// * map<string, sint32> map = 14; +// */ +// @java.lang.Override +// public int getMapOrDefault( +// java.lang.String key, +// int defaultValue) { +// if (key == null) { throw new NullPointerException("map key"); } +// java.util.Map map = +// internalGetMap().getMap(); +// return map.containsKey(key) ? map.get(key) : defaultValue; +// } +// /** +// * map<string, sint32> map = 14; +// */ +// @java.lang.Override +// public int getMapOrThrow( +// java.lang.String key) { +// if (key == null) { throw new NullPointerException("map key"); } +// java.util.Map map = +// internalGetMap().getMap(); +// if (!map.containsKey(key)) { +// throw new java.lang.IllegalArgumentException(); +// } +// return map.get(key); +// } +// +// public static final int END_FIELD_NUMBER = 15; +// @SuppressWarnings("serial") +// private volatile java.lang.Object end_ = ""; +// /** +// * string end = 15; +// * @return The end. +// */ +// @java.lang.Override +// public java.lang.String getEnd() { +// java.lang.Object ref = end_; +// if (ref instanceof java.lang.String) { +// return (java.lang.String) ref; +// } else { +// com.google.protobuf.ByteString bs = +// (com.google.protobuf.ByteString) ref; +// java.lang.String s = bs.toStringUtf8(); +// end_ = s; +// return s; +// } +// } +// /** +// * string end = 15; +// * @return The bytes for end. +// */ +// @java.lang.Override +// public com.google.protobuf.ByteString +// getEndBytes() { +// java.lang.Object ref = end_; +// if (ref instanceof java.lang.String) { +// com.google.protobuf.ByteString b = +// com.google.protobuf.ByteString.copyFromUtf8( +// (java.lang.String) ref); +// end_ = b; +// return b; +// } else { +// return (com.google.protobuf.ByteString) ref; +// } +// } +// +// private byte memoizedIsInitialized = -1; +// @java.lang.Override +// public final boolean isInitialized() { +// byte isInitialized = memoizedIsInitialized; +// if (isInitialized == 1) return true; +// if (isInitialized == 0) return false; +// +// memoizedIsInitialized = 1; +// return true; +// } +// +// @java.lang.Override +// public void writeTo(com.google.protobuf.CodedOutputStream output) +// throws java.io.IOException { +// getSerializedSize(); +// if (getBoolsList().size() > 0) { +// output.writeUInt32NoTag(10); +// output.writeUInt32NoTag(boolsMemoizedSerializedSize); +// } +// for (int i = 0; i < bools_.size(); i++) { +// output.writeBoolNoTag(bools_.getBoolean(i)); +// } +// for (int i = 0; i < bytes_.size(); i++) { +// output.writeBytes(2, bytes_.get(i)); +// } +// if (getCharsList().size() > 0) { +// output.writeUInt32NoTag(26); +// output.writeUInt32NoTag(charsMemoizedSerializedSize); +// } +// for (int i = 0; i < chars_.size(); i++) { +// output.writeSInt32NoTag(chars_.getInt(i)); +// } +// for (int i = 0; i < entrys_.size(); i++) { +// output.writeMessage(4, entrys_.get(i)); +// } +// if (getIntsList().size() > 0) { +// output.writeUInt32NoTag(42); +// output.writeUInt32NoTag(intsMemoizedSerializedSize); +// } +// for (int i = 0; i < ints_.size(); i++) { +// output.writeSInt32NoTag(ints_.getInt(i)); +// } +// if (getFloatsList().size() > 0) { +// output.writeUInt32NoTag(50); +// output.writeUInt32NoTag(floatsMemoizedSerializedSize); +// } +// for (int i = 0; i < floats_.size(); i++) { +// output.writeFloatNoTag(floats_.getFloat(i)); +// } +// if (getLongsList().size() > 0) { +// output.writeUInt32NoTag(58); +// output.writeUInt32NoTag(longsMemoizedSerializedSize); +// } +// for (int i = 0; i < longs_.size(); i++) { +// output.writeSInt64NoTag(longs_.getLong(i)); +// } +// if (getDoublesList().size() > 0) { +// output.writeUInt32NoTag(66); +// output.writeUInt32NoTag(doublesMemoizedSerializedSize); +// } +// for (int i = 0; i < doubles_.size(); i++) { +// output.writeDoubleNoTag(doubles_.getDouble(i)); +// } +// for (int i = 0; i < strings_.size(); i++) { +// com.google.protobuf.GeneratedMessageV3.writeString(output, 9, strings_.getRaw(i)); +// } +// if (id_ != 0) { +// output.writeSInt32(10, id_); +// } +// if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(name_)) { +// com.google.protobuf.GeneratedMessageV3.writeString(output, 11, name_); +// } +// if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(email_)) { +// com.google.protobuf.GeneratedMessageV3.writeString(output, 12, email_); +// } +// if (kind_ != org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.Kind.ONE.getNumber()) { +// output.writeEnum(13, kind_); +// } +// com.google.protobuf.GeneratedMessageV3 +// .serializeStringMapTo( +// output, +// internalGetMap(), +// MapDefaultEntryHolder.defaultEntry, +// 14); +// if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(end_)) { +// com.google.protobuf.GeneratedMessageV3.writeString(output, 15, end_); +// } +// getUnknownFields().writeTo(output); +// } +// +// @java.lang.Override +// public int getSerializedSize() { +// int size = memoizedSize; +// if (size != -1) return size; +// +// size = 0; +// { +// int dataSize = 0; +// dataSize = 1 * getBoolsList().size(); +// size += dataSize; +// if (!getBoolsList().isEmpty()) { +// size += 1; +// size += com.google.protobuf.CodedOutputStream +// .computeInt32SizeNoTag(dataSize); +// } +// boolsMemoizedSerializedSize = dataSize; +// } +// { +// int dataSize = 0; +// for (int i = 0; i < bytes_.size(); i++) { +// dataSize += com.google.protobuf.CodedOutputStream +// .computeBytesSizeNoTag(bytes_.get(i)); +// } +// size += dataSize; +// size += 1 * getBytesList().size(); +// } +// { +// int dataSize = 0; +// for (int i = 0; i < chars_.size(); i++) { +// dataSize += com.google.protobuf.CodedOutputStream +// .computeSInt32SizeNoTag(chars_.getInt(i)); +// } +// size += dataSize; +// if (!getCharsList().isEmpty()) { +// size += 1; +// size += com.google.protobuf.CodedOutputStream +// .computeInt32SizeNoTag(dataSize); +// } +// charsMemoizedSerializedSize = dataSize; +// } +// for (int i = 0; i < entrys_.size(); i++) { +// size += com.google.protobuf.CodedOutputStream +// .computeMessageSize(4, entrys_.get(i)); +// } +// { +// int dataSize = 0; +// for (int i = 0; i < ints_.size(); i++) { +// dataSize += com.google.protobuf.CodedOutputStream +// .computeSInt32SizeNoTag(ints_.getInt(i)); +// } +// size += dataSize; +// if (!getIntsList().isEmpty()) { +// size += 1; +// size += com.google.protobuf.CodedOutputStream +// .computeInt32SizeNoTag(dataSize); +// } +// intsMemoizedSerializedSize = dataSize; +// } +// { +// int dataSize = 0; +// dataSize = 4 * getFloatsList().size(); +// size += dataSize; +// if (!getFloatsList().isEmpty()) { +// size += 1; +// size += com.google.protobuf.CodedOutputStream +// .computeInt32SizeNoTag(dataSize); +// } +// floatsMemoizedSerializedSize = dataSize; +// } +// { +// int dataSize = 0; +// for (int i = 0; i < longs_.size(); i++) { +// dataSize += com.google.protobuf.CodedOutputStream +// .computeSInt64SizeNoTag(longs_.getLong(i)); +// } +// size += dataSize; +// if (!getLongsList().isEmpty()) { +// size += 1; +// size += com.google.protobuf.CodedOutputStream +// .computeInt32SizeNoTag(dataSize); +// } +// longsMemoizedSerializedSize = dataSize; +// } +// { +// int dataSize = 0; +// dataSize = 8 * getDoublesList().size(); +// size += dataSize; +// if (!getDoublesList().isEmpty()) { +// size += 1; +// size += com.google.protobuf.CodedOutputStream +// .computeInt32SizeNoTag(dataSize); +// } +// doublesMemoizedSerializedSize = dataSize; +// } +// { +// int dataSize = 0; +// for (int i = 0; i < strings_.size(); i++) { +// dataSize += computeStringSizeNoTag(strings_.getRaw(i)); +// } +// size += dataSize; +// size += 1 * getStringsList().size(); +// } +// if (id_ != 0) { +// size += com.google.protobuf.CodedOutputStream +// .computeSInt32Size(10, id_); +// } +// if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(name_)) { +// size += com.google.protobuf.GeneratedMessageV3.computeStringSize(11, name_); +// } +// if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(email_)) { +// size += com.google.protobuf.GeneratedMessageV3.computeStringSize(12, email_); +// } +// if (kind_ != org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.Kind.ONE.getNumber()) { +// size += com.google.protobuf.CodedOutputStream +// .computeEnumSize(13, kind_); +// } +// for (java.util.Map.Entry entry +// : internalGetMap().getMap().entrySet()) { +// com.google.protobuf.MapEntry +// map__ = MapDefaultEntryHolder.defaultEntry.newBuilderForType() +// .setKey(entry.getKey()) +// .setValue(entry.getValue()) +// .build(); +// size += com.google.protobuf.CodedOutputStream +// .computeMessageSize(14, map__); +// } +// if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(end_)) { +// size += com.google.protobuf.GeneratedMessageV3.computeStringSize(15, end_); +// } +// size += getUnknownFields().getSerializedSize(); +// memoizedSize = size; +// return size; +// } +// +// @java.lang.Override +// public boolean equals(final java.lang.Object obj) { +// if (obj == this) { +// return true; +// } +// if (!(obj instanceof org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean)) { +// return super.equals(obj); +// } +// org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean other = (org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean) obj; +// +// if (!getBoolsList() +// .equals(other.getBoolsList())) return false; +// if (!getBytesList() +// .equals(other.getBytesList())) return false; +// if (!getCharsList() +// .equals(other.getCharsList())) return false; +// if (!getEntrysList() +// .equals(other.getEntrysList())) return false; +// if (!getIntsList() +// .equals(other.getIntsList())) return false; +// if (!getFloatsList() +// .equals(other.getFloatsList())) return false; +// if (!getLongsList() +// .equals(other.getLongsList())) return false; +// if (!getDoublesList() +// .equals(other.getDoublesList())) return false; +// if (!getStringsList() +// .equals(other.getStringsList())) return false; +// if (getId() +// != other.getId()) return false; +// if (!getName() +// .equals(other.getName())) return false; +// if (!getEmail() +// .equals(other.getEmail())) return false; +// if (kind_ != other.kind_) return false; +// if (!internalGetMap().equals( +// other.internalGetMap())) return false; +// if (!getEnd() +// .equals(other.getEnd())) return false; +// if (!getUnknownFields().equals(other.getUnknownFields())) return false; +// return true; +// } +// +// @java.lang.Override +// public int hashCode() { +// if (memoizedHashCode != 0) { +// return memoizedHashCode; +// } +// int hash = 41; +// hash = (19 * hash) + getDescriptor().hashCode(); +// if (getBoolsCount() > 0) { +// hash = (37 * hash) + BOOLS_FIELD_NUMBER; +// hash = (53 * hash) + getBoolsList().hashCode(); +// } +// if (getBytesCount() > 0) { +// hash = (37 * hash) + BYTES_FIELD_NUMBER; +// hash = (53 * hash) + getBytesList().hashCode(); +// } +// if (getCharsCount() > 0) { +// hash = (37 * hash) + CHARS_FIELD_NUMBER; +// hash = (53 * hash) + getCharsList().hashCode(); +// } +// if (getEntrysCount() > 0) { +// hash = (37 * hash) + ENTRYS_FIELD_NUMBER; +// hash = (53 * hash) + getEntrysList().hashCode(); +// } +// if (getIntsCount() > 0) { +// hash = (37 * hash) + INTS_FIELD_NUMBER; +// hash = (53 * hash) + getIntsList().hashCode(); +// } +// if (getFloatsCount() > 0) { +// hash = (37 * hash) + FLOATS_FIELD_NUMBER; +// hash = (53 * hash) + getFloatsList().hashCode(); +// } +// if (getLongsCount() > 0) { +// hash = (37 * hash) + LONGS_FIELD_NUMBER; +// hash = (53 * hash) + getLongsList().hashCode(); +// } +// if (getDoublesCount() > 0) { +// hash = (37 * hash) + DOUBLES_FIELD_NUMBER; +// hash = (53 * hash) + getDoublesList().hashCode(); +// } +// if (getStringsCount() > 0) { +// hash = (37 * hash) + STRINGS_FIELD_NUMBER; +// hash = (53 * hash) + getStringsList().hashCode(); +// } +// hash = (37 * hash) + ID_FIELD_NUMBER; +// hash = (53 * hash) + getId(); +// hash = (37 * hash) + NAME_FIELD_NUMBER; +// hash = (53 * hash) + getName().hashCode(); +// hash = (37 * hash) + EMAIL_FIELD_NUMBER; +// hash = (53 * hash) + getEmail().hashCode(); +// hash = (37 * hash) + KIND_FIELD_NUMBER; +// hash = (53 * hash) + kind_; +// if (!internalGetMap().getMap().isEmpty()) { +// hash = (37 * hash) + MAP_FIELD_NUMBER; +// hash = (53 * hash) + internalGetMap().hashCode(); +// } +// hash = (37 * hash) + END_FIELD_NUMBER; +// hash = (53 * hash) + getEnd().hashCode(); +// hash = (29 * hash) + getUnknownFields().hashCode(); +// memoizedHashCode = hash; +// return hash; +// } +// +// public static org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean parseFrom( +// java.nio.ByteBuffer data) +// throws com.google.protobuf.InvalidProtocolBufferException { +// return PARSER.parseFrom(data); +// } +// public static org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean parseFrom( +// java.nio.ByteBuffer data, +// com.google.protobuf.ExtensionRegistryLite extensionRegistry) +// throws com.google.protobuf.InvalidProtocolBufferException { +// return PARSER.parseFrom(data, extensionRegistry); +// } +// public static org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean parseFrom( +// com.google.protobuf.ByteString data) +// throws com.google.protobuf.InvalidProtocolBufferException { +// return PARSER.parseFrom(data); +// } +// public static org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean parseFrom( +// com.google.protobuf.ByteString data, +// com.google.protobuf.ExtensionRegistryLite extensionRegistry) +// throws com.google.protobuf.InvalidProtocolBufferException { +// return PARSER.parseFrom(data, extensionRegistry); +// } +// public static org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean parseFrom(byte[] data) +// throws com.google.protobuf.InvalidProtocolBufferException { +// return PARSER.parseFrom(data); +// } +// public static org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean parseFrom( +// byte[] data, +// com.google.protobuf.ExtensionRegistryLite extensionRegistry) +// throws com.google.protobuf.InvalidProtocolBufferException { +// return PARSER.parseFrom(data, extensionRegistry); +// } +// public static org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean parseFrom(java.io.InputStream input) +// throws java.io.IOException { +// return com.google.protobuf.GeneratedMessageV3 +// .parseWithIOException(PARSER, input); +// } +// public static org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean parseFrom( +// java.io.InputStream input, +// com.google.protobuf.ExtensionRegistryLite extensionRegistry) +// throws java.io.IOException { +// return com.google.protobuf.GeneratedMessageV3 +// .parseWithIOException(PARSER, input, extensionRegistry); +// } +// +// public static org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean parseDelimitedFrom(java.io.InputStream input) +// throws java.io.IOException { +// return com.google.protobuf.GeneratedMessageV3 +// .parseDelimitedWithIOException(PARSER, input); +// } +// +// public static org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean parseDelimitedFrom( +// java.io.InputStream input, +// com.google.protobuf.ExtensionRegistryLite extensionRegistry) +// throws java.io.IOException { +// return com.google.protobuf.GeneratedMessageV3 +// .parseDelimitedWithIOException(PARSER, input, extensionRegistry); +// } +// public static org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean parseFrom( +// com.google.protobuf.CodedInputStream input) +// throws java.io.IOException { +// return com.google.protobuf.GeneratedMessageV3 +// .parseWithIOException(PARSER, input); +// } +// public static org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean parseFrom( +// com.google.protobuf.CodedInputStream input, +// com.google.protobuf.ExtensionRegistryLite extensionRegistry) +// throws java.io.IOException { +// return com.google.protobuf.GeneratedMessageV3 +// .parseWithIOException(PARSER, input, extensionRegistry); +// } +// +// @java.lang.Override +// public Builder newBuilderForType() { return newBuilder(); } +// public static Builder newBuilder() { +// return DEFAULT_INSTANCE.toBuilder(); +// } +// public static Builder newBuilder(org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean prototype) { +// return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); +// } +// @java.lang.Override +// public Builder toBuilder() { +// return this == DEFAULT_INSTANCE +// ? new Builder() : new Builder().mergeFrom(this); +// } +// +// @java.lang.Override +// protected Builder newBuilderForType( +// com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { +// Builder builder = new Builder(parent); +// return builder; +// } +// /** +// * Protobuf type {@code PTestBean} +// */ +// public static final class Builder extends +// com.google.protobuf.GeneratedMessageV3.Builder implements +// // @@protoc_insertion_point(builder_implements:PTestBean) +// org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBeanOrBuilder { +// public static final com.google.protobuf.Descriptors.Descriptor +// getDescriptor() { +// return org.redkalex.test.protobuf.PTestBeanOuterClass.internal_static_PTestBean_descriptor; +// } +// +// @SuppressWarnings({"rawtypes"}) +// protected com.google.protobuf.MapField internalGetMapField( +// int number) { +// switch (number) { +// case 14: +// return internalGetMap(); +// default: +// throw new RuntimeException( +// "Invalid map field number: " + number); +// } +// } +// @SuppressWarnings({"rawtypes"}) +// protected com.google.protobuf.MapField internalGetMutableMapField( +// int number) { +// switch (number) { +// case 14: +// return internalGetMutableMap(); +// default: +// throw new RuntimeException( +// "Invalid map field number: " + number); +// } +// } +// @java.lang.Override +// protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable +// internalGetFieldAccessorTable() { +// return org.redkalex.test.protobuf.PTestBeanOuterClass.internal_static_PTestBean_fieldAccessorTable +// .ensureFieldAccessorsInitialized( +// org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.class, org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.Builder.class); +// } +// +// // Construct using org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.newBuilder() +// private Builder() { +// +// } +// +// private Builder( +// com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { +// super(parent); +// +// } +// @java.lang.Override +// public Builder clear() { +// super.clear(); +// bitField0_ = 0; +// bools_ = emptyBooleanList(); +// bytes_ = java.util.Collections.emptyList(); +// chars_ = emptyIntList(); +// if (entrysBuilder_ == null) { +// entrys_ = java.util.Collections.emptyList(); +// } else { +// entrys_ = null; +// entrysBuilder_.clear(); +// } +// bitField0_ = (bitField0_ & ~0x00000008); +// ints_ = emptyIntList(); +// floats_ = emptyFloatList(); +// longs_ = emptyLongList(); +// doubles_ = emptyDoubleList(); +// strings_ = +// com.google.protobuf.LazyStringArrayList.emptyList(); +// id_ = 0; +// name_ = ""; +// email_ = ""; +// kind_ = 0; +// internalGetMutableMap().clear(); +// end_ = ""; +// return this; +// } +// +// @java.lang.Override +// public com.google.protobuf.Descriptors.Descriptor +// getDescriptorForType() { +// return org.redkalex.test.protobuf.PTestBeanOuterClass.internal_static_PTestBean_descriptor; +// } +// +// @java.lang.Override +// public org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean getDefaultInstanceForType() { +// return org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.getDefaultInstance(); +// } +// +// @java.lang.Override +// public org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean build() { +// org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean result = buildPartial(); +// if (!result.isInitialized()) { +// throw newUninitializedMessageException(result); +// } +// return result; +// } +// +// @java.lang.Override +// public org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean buildPartial() { +// org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean result = new org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean(this); +// buildPartialRepeatedFields(result); +// if (bitField0_ != 0) { buildPartial0(result); } +// onBuilt(); +// return result; +// } +// +// private void buildPartialRepeatedFields(org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean result) { +// if (((bitField0_ & 0x00000001) != 0)) { +// bools_.makeImmutable(); +// bitField0_ = (bitField0_ & ~0x00000001); +// } +// result.bools_ = bools_; +// if (((bitField0_ & 0x00000002) != 0)) { +// bytes_ = java.util.Collections.unmodifiableList(bytes_); +// bitField0_ = (bitField0_ & ~0x00000002); +// } +// result.bytes_ = bytes_; +// if (((bitField0_ & 0x00000004) != 0)) { +// chars_.makeImmutable(); +// bitField0_ = (bitField0_ & ~0x00000004); +// } +// result.chars_ = chars_; +// if (entrysBuilder_ == null) { +// if (((bitField0_ & 0x00000008) != 0)) { +// entrys_ = java.util.Collections.unmodifiableList(entrys_); +// bitField0_ = (bitField0_ & ~0x00000008); +// } +// result.entrys_ = entrys_; +// } else { +// result.entrys_ = entrysBuilder_.build(); +// } +// if (((bitField0_ & 0x00000010) != 0)) { +// ints_.makeImmutable(); +// bitField0_ = (bitField0_ & ~0x00000010); +// } +// result.ints_ = ints_; +// if (((bitField0_ & 0x00000020) != 0)) { +// floats_.makeImmutable(); +// bitField0_ = (bitField0_ & ~0x00000020); +// } +// result.floats_ = floats_; +// if (((bitField0_ & 0x00000040) != 0)) { +// longs_.makeImmutable(); +// bitField0_ = (bitField0_ & ~0x00000040); +// } +// result.longs_ = longs_; +// if (((bitField0_ & 0x00000080) != 0)) { +// doubles_.makeImmutable(); +// bitField0_ = (bitField0_ & ~0x00000080); +// } +// result.doubles_ = doubles_; +// } +// +// private void buildPartial0(org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean result) { +// int from_bitField0_ = bitField0_; +// if (((from_bitField0_ & 0x00000100) != 0)) { +// strings_.makeImmutable(); +// result.strings_ = strings_; +// } +// if (((from_bitField0_ & 0x00000200) != 0)) { +// result.id_ = id_; +// } +// if (((from_bitField0_ & 0x00000400) != 0)) { +// result.name_ = name_; +// } +// if (((from_bitField0_ & 0x00000800) != 0)) { +// result.email_ = email_; +// } +// if (((from_bitField0_ & 0x00001000) != 0)) { +// result.kind_ = kind_; +// } +// if (((from_bitField0_ & 0x00002000) != 0)) { +// result.map_ = internalGetMap(); +// result.map_.makeImmutable(); +// } +// if (((from_bitField0_ & 0x00004000) != 0)) { +// result.end_ = end_; +// } +// } +// +// @java.lang.Override +// public Builder clone() { +// return super.clone(); +// } +// @java.lang.Override +// public Builder setField( +// com.google.protobuf.Descriptors.FieldDescriptor field, +// java.lang.Object value) { +// return super.setField(field, value); +// } +// @java.lang.Override +// public Builder clearField( +// com.google.protobuf.Descriptors.FieldDescriptor field) { +// return super.clearField(field); +// } +// @java.lang.Override +// public Builder clearOneof( +// com.google.protobuf.Descriptors.OneofDescriptor oneof) { +// return super.clearOneof(oneof); +// } +// @java.lang.Override +// public Builder setRepeatedField( +// com.google.protobuf.Descriptors.FieldDescriptor field, +// int index, java.lang.Object value) { +// return super.setRepeatedField(field, index, value); +// } +// @java.lang.Override +// public Builder addRepeatedField( +// com.google.protobuf.Descriptors.FieldDescriptor field, +// java.lang.Object value) { +// return super.addRepeatedField(field, value); +// } +// @java.lang.Override +// public Builder mergeFrom(com.google.protobuf.Message other) { +// if (other instanceof org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean) { +// return mergeFrom((org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean)other); +// } else { +// super.mergeFrom(other); +// return this; +// } +// } +// +// public Builder mergeFrom(org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean other) { +// if (other == org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.getDefaultInstance()) return this; +// if (!other.bools_.isEmpty()) { +// if (bools_.isEmpty()) { +// bools_ = other.bools_; +// bitField0_ = (bitField0_ & ~0x00000001); +// } else { +// ensureBoolsIsMutable(); +// bools_.addAll(other.bools_); +// } +// onChanged(); +// } +// if (!other.bytes_.isEmpty()) { +// if (bytes_.isEmpty()) { +// bytes_ = other.bytes_; +// bitField0_ = (bitField0_ & ~0x00000002); +// } else { +// ensureBytesIsMutable(); +// bytes_.addAll(other.bytes_); +// } +// onChanged(); +// } +// if (!other.chars_.isEmpty()) { +// if (chars_.isEmpty()) { +// chars_ = other.chars_; +// bitField0_ = (bitField0_ & ~0x00000004); +// } else { +// ensureCharsIsMutable(); +// chars_.addAll(other.chars_); +// } +// onChanged(); +// } +// if (entrysBuilder_ == null) { +// if (!other.entrys_.isEmpty()) { +// if (entrys_.isEmpty()) { +// entrys_ = other.entrys_; +// bitField0_ = (bitField0_ & ~0x00000008); +// } else { +// ensureEntrysIsMutable(); +// entrys_.addAll(other.entrys_); +// } +// onChanged(); +// } +// } else { +// if (!other.entrys_.isEmpty()) { +// if (entrysBuilder_.isEmpty()) { +// entrysBuilder_.dispose(); +// entrysBuilder_ = null; +// entrys_ = other.entrys_; +// bitField0_ = (bitField0_ & ~0x00000008); +// entrysBuilder_ = +// com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders ? +// getEntrysFieldBuilder() : null; +// } else { +// entrysBuilder_.addAllMessages(other.entrys_); +// } +// } +// } +// if (!other.ints_.isEmpty()) { +// if (ints_.isEmpty()) { +// ints_ = other.ints_; +// bitField0_ = (bitField0_ & ~0x00000010); +// } else { +// ensureIntsIsMutable(); +// ints_.addAll(other.ints_); +// } +// onChanged(); +// } +// if (!other.floats_.isEmpty()) { +// if (floats_.isEmpty()) { +// floats_ = other.floats_; +// bitField0_ = (bitField0_ & ~0x00000020); +// } else { +// ensureFloatsIsMutable(); +// floats_.addAll(other.floats_); +// } +// onChanged(); +// } +// if (!other.longs_.isEmpty()) { +// if (longs_.isEmpty()) { +// longs_ = other.longs_; +// bitField0_ = (bitField0_ & ~0x00000040); +// } else { +// ensureLongsIsMutable(); +// longs_.addAll(other.longs_); +// } +// onChanged(); +// } +// if (!other.doubles_.isEmpty()) { +// if (doubles_.isEmpty()) { +// doubles_ = other.doubles_; +// bitField0_ = (bitField0_ & ~0x00000080); +// } else { +// ensureDoublesIsMutable(); +// doubles_.addAll(other.doubles_); +// } +// onChanged(); +// } +// if (!other.strings_.isEmpty()) { +// if (strings_.isEmpty()) { +// strings_ = other.strings_; +// bitField0_ |= 0x00000100; +// } else { +// ensureStringsIsMutable(); +// strings_.addAll(other.strings_); +// } +// onChanged(); +// } +// if (other.getId() != 0) { +// setId(other.getId()); +// } +// if (!other.getName().isEmpty()) { +// name_ = other.name_; +// bitField0_ |= 0x00000400; +// onChanged(); +// } +// if (!other.getEmail().isEmpty()) { +// email_ = other.email_; +// bitField0_ |= 0x00000800; +// onChanged(); +// } +// if (other.kind_ != 0) { +// setKindValue(other.getKindValue()); +// } +// internalGetMutableMap().mergeFrom( +// other.internalGetMap()); +// bitField0_ |= 0x00002000; +// if (!other.getEnd().isEmpty()) { +// end_ = other.end_; +// bitField0_ |= 0x00004000; +// onChanged(); +// } +// this.mergeUnknownFields(other.getUnknownFields()); +// onChanged(); +// return this; +// } +// +// @java.lang.Override +// public final boolean isInitialized() { +// return true; +// } +// +// @java.lang.Override +// public Builder mergeFrom( +// com.google.protobuf.CodedInputStream input, +// com.google.protobuf.ExtensionRegistryLite extensionRegistry) +// throws java.io.IOException { +// if (extensionRegistry == null) { +// throw new java.lang.NullPointerException(); +// } +// try { +// boolean done = false; +// while (!done) { +// int tag = input.readTag(); +// switch (tag) { +// case 0: +// done = true; +// break; +// case 8: { +// boolean v = input.readBool(); +// ensureBoolsIsMutable(); +// bools_.addBoolean(v); +// break; +// } // case 8 +// case 10: { +// int length = input.readRawVarint32(); +// int limit = input.pushLimit(length); +// ensureBoolsIsMutable(); +// while (input.getBytesUntilLimit() > 0) { +// bools_.addBoolean(input.readBool()); +// } +// input.popLimit(limit); +// break; +// } // case 10 +// case 18: { +// com.google.protobuf.ByteString v = input.readBytes(); +// ensureBytesIsMutable(); +// bytes_.add(v); +// break; +// } // case 18 +// case 24: { +// int v = input.readSInt32(); +// ensureCharsIsMutable(); +// chars_.addInt(v); +// break; +// } // case 24 +// case 26: { +// int length = input.readRawVarint32(); +// int limit = input.pushLimit(length); +// ensureCharsIsMutable(); +// while (input.getBytesUntilLimit() > 0) { +// chars_.addInt(input.readSInt32()); +// } +// input.popLimit(limit); +// break; +// } // case 26 +// case 34: { +// org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry m = +// input.readMessage( +// org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry.parser(), +// extensionRegistry); +// if (entrysBuilder_ == null) { +// ensureEntrysIsMutable(); +// entrys_.add(m); +// } else { +// entrysBuilder_.addMessage(m); +// } +// break; +// } // case 34 +// case 40: { +// int v = input.readSInt32(); +// ensureIntsIsMutable(); +// ints_.addInt(v); +// break; +// } // case 40 +// case 42: { +// int length = input.readRawVarint32(); +// int limit = input.pushLimit(length); +// ensureIntsIsMutable(); +// while (input.getBytesUntilLimit() > 0) { +// ints_.addInt(input.readSInt32()); +// } +// input.popLimit(limit); +// break; +// } // case 42 +// case 53: { +// float v = input.readFloat(); +// ensureFloatsIsMutable(); +// floats_.addFloat(v); +// break; +// } // case 53 +// case 50: { +// int length = input.readRawVarint32(); +// int limit = input.pushLimit(length); +// ensureFloatsIsMutable(); +// while (input.getBytesUntilLimit() > 0) { +// floats_.addFloat(input.readFloat()); +// } +// input.popLimit(limit); +// break; +// } // case 50 +// case 56: { +// long v = input.readSInt64(); +// ensureLongsIsMutable(); +// longs_.addLong(v); +// break; +// } // case 56 +// case 58: { +// int length = input.readRawVarint32(); +// int limit = input.pushLimit(length); +// ensureLongsIsMutable(); +// while (input.getBytesUntilLimit() > 0) { +// longs_.addLong(input.readSInt64()); +// } +// input.popLimit(limit); +// break; +// } // case 58 +// case 65: { +// double v = input.readDouble(); +// ensureDoublesIsMutable(); +// doubles_.addDouble(v); +// break; +// } // case 65 +// case 66: { +// int length = input.readRawVarint32(); +// int limit = input.pushLimit(length); +// ensureDoublesIsMutable(); +// while (input.getBytesUntilLimit() > 0) { +// doubles_.addDouble(input.readDouble()); +// } +// input.popLimit(limit); +// break; +// } // case 66 +// case 74: { +// java.lang.String s = input.readStringRequireUtf8(); +// ensureStringsIsMutable(); +// strings_.add(s); +// break; +// } // case 74 +// case 80: { +// id_ = input.readSInt32(); +// bitField0_ |= 0x00000200; +// break; +// } // case 80 +// case 90: { +// name_ = input.readStringRequireUtf8(); +// bitField0_ |= 0x00000400; +// break; +// } // case 90 +// case 98: { +// email_ = input.readStringRequireUtf8(); +// bitField0_ |= 0x00000800; +// break; +// } // case 98 +// case 104: { +// kind_ = input.readEnum(); +// bitField0_ |= 0x00001000; +// break; +// } // case 104 +// case 114: { +// com.google.protobuf.MapEntry +// map__ = input.readMessage( +// MapDefaultEntryHolder.defaultEntry.getParserForType(), extensionRegistry); +// internalGetMutableMap().getMutableMap().put( +// map__.getKey(), map__.getValue()); +// bitField0_ |= 0x00002000; +// break; +// } // case 114 +// case 122: { +// end_ = input.readStringRequireUtf8(); +// bitField0_ |= 0x00004000; +// break; +// } // case 122 +// default: { +// if (!super.parseUnknownField(input, extensionRegistry, tag)) { +// done = true; // was an endgroup tag +// } +// break; +// } // default: +// } // switch (tag) +// } // while (!done) +// } catch (com.google.protobuf.InvalidProtocolBufferException e) { +// throw e.unwrapIOException(); +// } finally { +// onChanged(); +// } // finally +// return this; +// } +// private int bitField0_; +// +// private com.google.protobuf.Internal.BooleanList bools_ = emptyBooleanList(); +// private void ensureBoolsIsMutable() { +// if (!((bitField0_ & 0x00000001) != 0)) { +// bools_ = mutableCopy(bools_); +// bitField0_ |= 0x00000001; +// } +// } +// /** +// * repeated bool bools = 1; +// * @return A list containing the bools. +// */ +// public java.util.List +// getBoolsList() { +// return ((bitField0_ & 0x00000001) != 0) ? +// java.util.Collections.unmodifiableList(bools_) : bools_; +// } +// /** +// * repeated bool bools = 1; +// * @return The count of bools. +// */ +// public int getBoolsCount() { +// return bools_.size(); +// } +// /** +// * repeated bool bools = 1; +// * @param index The index of the element to return. +// * @return The bools at the given index. +// */ +// public boolean getBools(int index) { +// return bools_.getBoolean(index); +// } +// /** +// * repeated bool bools = 1; +// * @param index The index to set the value at. +// * @param value The bools to set. +// * @return This builder for chaining. +// */ +// public Builder setBools( +// int index, boolean value) { +// +// ensureBoolsIsMutable(); +// bools_.setBoolean(index, value); +// onChanged(); +// return this; +// } +// /** +// * repeated bool bools = 1; +// * @param value The bools to add. +// * @return This builder for chaining. +// */ +// public Builder addBools(boolean value) { +// +// ensureBoolsIsMutable(); +// bools_.addBoolean(value); +// onChanged(); +// return this; +// } +// /** +// * repeated bool bools = 1; +// * @param values The bools to add. +// * @return This builder for chaining. +// */ +// public Builder addAllBools( +// java.lang.Iterable values) { +// ensureBoolsIsMutable(); +// com.google.protobuf.AbstractMessageLite.Builder.addAll( +// values, bools_); +// onChanged(); +// return this; +// } +// /** +// * repeated bool bools = 1; +// * @return This builder for chaining. +// */ +// public Builder clearBools() { +// bools_ = emptyBooleanList(); +// bitField0_ = (bitField0_ & ~0x00000001); +// onChanged(); +// return this; +// } +// +// private java.util.List bytes_ = java.util.Collections.emptyList(); +// private void ensureBytesIsMutable() { +// if (!((bitField0_ & 0x00000002) != 0)) { +// bytes_ = new java.util.ArrayList(bytes_); +// bitField0_ |= 0x00000002; +// } +// } +// /** +// * repeated bytes bytes = 2; +// * @return A list containing the bytes. +// */ +// public java.util.List +// getBytesList() { +// return ((bitField0_ & 0x00000002) != 0) ? +// java.util.Collections.unmodifiableList(bytes_) : bytes_; +// } +// /** +// * repeated bytes bytes = 2; +// * @return The count of bytes. +// */ +// public int getBytesCount() { +// return bytes_.size(); +// } +// /** +// * repeated bytes bytes = 2; +// * @param index The index of the element to return. +// * @return The bytes at the given index. +// */ +// public com.google.protobuf.ByteString getBytes(int index) { +// return bytes_.get(index); +// } +// /** +// * repeated bytes bytes = 2; +// * @param index The index to set the value at. +// * @param value The bytes to set. +// * @return This builder for chaining. +// */ +// public Builder setBytes( +// int index, com.google.protobuf.ByteString value) { +// if (value == null) { throw new NullPointerException(); } +// ensureBytesIsMutable(); +// bytes_.set(index, value); +// onChanged(); +// return this; +// } +// /** +// * repeated bytes bytes = 2; +// * @param value The bytes to add. +// * @return This builder for chaining. +// */ +// public Builder addBytes(com.google.protobuf.ByteString value) { +// if (value == null) { throw new NullPointerException(); } +// ensureBytesIsMutable(); +// bytes_.add(value); +// onChanged(); +// return this; +// } +// /** +// * repeated bytes bytes = 2; +// * @param values The bytes to add. +// * @return This builder for chaining. +// */ +// public Builder addAllBytes( +// java.lang.Iterable values) { +// ensureBytesIsMutable(); +// com.google.protobuf.AbstractMessageLite.Builder.addAll( +// values, bytes_); +// onChanged(); +// return this; +// } +// /** +// * repeated bytes bytes = 2; +// * @return This builder for chaining. +// */ +// public Builder clearBytes() { +// bytes_ = java.util.Collections.emptyList(); +// bitField0_ = (bitField0_ & ~0x00000002); +// onChanged(); +// return this; +// } +// +// private com.google.protobuf.Internal.IntList chars_ = emptyIntList(); +// private void ensureCharsIsMutable() { +// if (!((bitField0_ & 0x00000004) != 0)) { +// chars_ = mutableCopy(chars_); +// bitField0_ |= 0x00000004; +// } +// } +// /** +// * repeated sint32 chars = 3; +// * @return A list containing the chars. +// */ +// public java.util.List +// getCharsList() { +// return ((bitField0_ & 0x00000004) != 0) ? +// java.util.Collections.unmodifiableList(chars_) : chars_; +// } +// /** +// * repeated sint32 chars = 3; +// * @return The count of chars. +// */ +// public int getCharsCount() { +// return chars_.size(); +// } +// /** +// * repeated sint32 chars = 3; +// * @param index The index of the element to return. +// * @return The chars at the given index. +// */ +// public int getChars(int index) { +// return chars_.getInt(index); +// } +// /** +// * repeated sint32 chars = 3; +// * @param index The index to set the value at. +// * @param value The chars to set. +// * @return This builder for chaining. +// */ +// public Builder setChars( +// int index, int value) { +// +// ensureCharsIsMutable(); +// chars_.setInt(index, value); +// onChanged(); +// return this; +// } +// /** +// * repeated sint32 chars = 3; +// * @param value The chars to add. +// * @return This builder for chaining. +// */ +// public Builder addChars(int value) { +// +// ensureCharsIsMutable(); +// chars_.addInt(value); +// onChanged(); +// return this; +// } +// /** +// * repeated sint32 chars = 3; +// * @param values The chars to add. +// * @return This builder for chaining. +// */ +// public Builder addAllChars( +// java.lang.Iterable values) { +// ensureCharsIsMutable(); +// com.google.protobuf.AbstractMessageLite.Builder.addAll( +// values, chars_); +// onChanged(); +// return this; +// } +// /** +// * repeated sint32 chars = 3; +// * @return This builder for chaining. +// */ +// public Builder clearChars() { +// chars_ = emptyIntList(); +// bitField0_ = (bitField0_ & ~0x00000004); +// onChanged(); +// return this; +// } +// +// private java.util.List entrys_ = +// java.util.Collections.emptyList(); +// private void ensureEntrysIsMutable() { +// if (!((bitField0_ & 0x00000008) != 0)) { +// entrys_ = new java.util.ArrayList(entrys_); +// bitField0_ |= 0x00000008; +// } +// } +// +// private com.google.protobuf.RepeatedFieldBuilderV3< +// org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry, org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry.Builder, org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntryOrBuilder> entrysBuilder_; +// +// /** +// * repeated .PTestBean.PTestEntry entrys = 4; +// */ +// public java.util.List getEntrysList() { +// if (entrysBuilder_ == null) { +// return java.util.Collections.unmodifiableList(entrys_); +// } else { +// return entrysBuilder_.getMessageList(); +// } +// } +// /** +// * repeated .PTestBean.PTestEntry entrys = 4; +// */ +// public int getEntrysCount() { +// if (entrysBuilder_ == null) { +// return entrys_.size(); +// } else { +// return entrysBuilder_.getCount(); +// } +// } +// /** +// * repeated .PTestBean.PTestEntry entrys = 4; +// */ +// public org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry getEntrys(int index) { +// if (entrysBuilder_ == null) { +// return entrys_.get(index); +// } else { +// return entrysBuilder_.getMessage(index); +// } +// } +// /** +// * repeated .PTestBean.PTestEntry entrys = 4; +// */ +// public Builder setEntrys( +// int index, org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry value) { +// if (entrysBuilder_ == null) { +// if (value == null) { +// throw new NullPointerException(); +// } +// ensureEntrysIsMutable(); +// entrys_.set(index, value); +// onChanged(); +// } else { +// entrysBuilder_.setMessage(index, value); +// } +// return this; +// } +// /** +// * repeated .PTestBean.PTestEntry entrys = 4; +// */ +// public Builder setEntrys( +// int index, org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry.Builder builderForValue) { +// if (entrysBuilder_ == null) { +// ensureEntrysIsMutable(); +// entrys_.set(index, builderForValue.build()); +// onChanged(); +// } else { +// entrysBuilder_.setMessage(index, builderForValue.build()); +// } +// return this; +// } +// /** +// * repeated .PTestBean.PTestEntry entrys = 4; +// */ +// public Builder addEntrys(org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry value) { +// if (entrysBuilder_ == null) { +// if (value == null) { +// throw new NullPointerException(); +// } +// ensureEntrysIsMutable(); +// entrys_.add(value); +// onChanged(); +// } else { +// entrysBuilder_.addMessage(value); +// } +// return this; +// } +// /** +// * repeated .PTestBean.PTestEntry entrys = 4; +// */ +// public Builder addEntrys( +// int index, org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry value) { +// if (entrysBuilder_ == null) { +// if (value == null) { +// throw new NullPointerException(); +// } +// ensureEntrysIsMutable(); +// entrys_.add(index, value); +// onChanged(); +// } else { +// entrysBuilder_.addMessage(index, value); +// } +// return this; +// } +// /** +// * repeated .PTestBean.PTestEntry entrys = 4; +// */ +// public Builder addEntrys( +// org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry.Builder builderForValue) { +// if (entrysBuilder_ == null) { +// ensureEntrysIsMutable(); +// entrys_.add(builderForValue.build()); +// onChanged(); +// } else { +// entrysBuilder_.addMessage(builderForValue.build()); +// } +// return this; +// } +// /** +// * repeated .PTestBean.PTestEntry entrys = 4; +// */ +// public Builder addEntrys( +// int index, org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry.Builder builderForValue) { +// if (entrysBuilder_ == null) { +// ensureEntrysIsMutable(); +// entrys_.add(index, builderForValue.build()); +// onChanged(); +// } else { +// entrysBuilder_.addMessage(index, builderForValue.build()); +// } +// return this; +// } +// /** +// * repeated .PTestBean.PTestEntry entrys = 4; +// */ +// public Builder addAllEntrys( +// java.lang.Iterable values) { +// if (entrysBuilder_ == null) { +// ensureEntrysIsMutable(); +// com.google.protobuf.AbstractMessageLite.Builder.addAll( +// values, entrys_); +// onChanged(); +// } else { +// entrysBuilder_.addAllMessages(values); +// } +// return this; +// } +// /** +// * repeated .PTestBean.PTestEntry entrys = 4; +// */ +// public Builder clearEntrys() { +// if (entrysBuilder_ == null) { +// entrys_ = java.util.Collections.emptyList(); +// bitField0_ = (bitField0_ & ~0x00000008); +// onChanged(); +// } else { +// entrysBuilder_.clear(); +// } +// return this; +// } +// /** +// * repeated .PTestBean.PTestEntry entrys = 4; +// */ +// public Builder removeEntrys(int index) { +// if (entrysBuilder_ == null) { +// ensureEntrysIsMutable(); +// entrys_.remove(index); +// onChanged(); +// } else { +// entrysBuilder_.remove(index); +// } +// return this; +// } +// /** +// * repeated .PTestBean.PTestEntry entrys = 4; +// */ +// public org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry.Builder getEntrysBuilder( +// int index) { +// return getEntrysFieldBuilder().getBuilder(index); +// } +// /** +// * repeated .PTestBean.PTestEntry entrys = 4; +// */ +// public org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntryOrBuilder getEntrysOrBuilder( +// int index) { +// if (entrysBuilder_ == null) { +// return entrys_.get(index); } else { +// return entrysBuilder_.getMessageOrBuilder(index); +// } +// } +// /** +// * repeated .PTestBean.PTestEntry entrys = 4; +// */ +// public java.util.List +// getEntrysOrBuilderList() { +// if (entrysBuilder_ != null) { +// return entrysBuilder_.getMessageOrBuilderList(); +// } else { +// return java.util.Collections.unmodifiableList(entrys_); +// } +// } +// /** +// * repeated .PTestBean.PTestEntry entrys = 4; +// */ +// public org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry.Builder addEntrysBuilder() { +// return getEntrysFieldBuilder().addBuilder( +// org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry.getDefaultInstance()); +// } +// /** +// * repeated .PTestBean.PTestEntry entrys = 4; +// */ +// public org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry.Builder addEntrysBuilder( +// int index) { +// return getEntrysFieldBuilder().addBuilder( +// index, org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry.getDefaultInstance()); +// } +// /** +// * repeated .PTestBean.PTestEntry entrys = 4; +// */ +// public java.util.List +// getEntrysBuilderList() { +// return getEntrysFieldBuilder().getBuilderList(); +// } +// private com.google.protobuf.RepeatedFieldBuilderV3< +// org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry, org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry.Builder, org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntryOrBuilder> +// getEntrysFieldBuilder() { +// if (entrysBuilder_ == null) { +// entrysBuilder_ = new com.google.protobuf.RepeatedFieldBuilderV3< +// org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry, org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry.Builder, org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntryOrBuilder>( +// entrys_, +// ((bitField0_ & 0x00000008) != 0), +// getParentForChildren(), +// isClean()); +// entrys_ = null; +// } +// return entrysBuilder_; +// } +// +// private com.google.protobuf.Internal.IntList ints_ = emptyIntList(); +// private void ensureIntsIsMutable() { +// if (!((bitField0_ & 0x00000010) != 0)) { +// ints_ = mutableCopy(ints_); +// bitField0_ |= 0x00000010; +// } +// } +// /** +// * repeated sint32 ints = 5; +// * @return A list containing the ints. +// */ +// public java.util.List +// getIntsList() { +// return ((bitField0_ & 0x00000010) != 0) ? +// java.util.Collections.unmodifiableList(ints_) : ints_; +// } +// /** +// * repeated sint32 ints = 5; +// * @return The count of ints. +// */ +// public int getIntsCount() { +// return ints_.size(); +// } +// /** +// * repeated sint32 ints = 5; +// * @param index The index of the element to return. +// * @return The ints at the given index. +// */ +// public int getInts(int index) { +// return ints_.getInt(index); +// } +// /** +// * repeated sint32 ints = 5; +// * @param index The index to set the value at. +// * @param value The ints to set. +// * @return This builder for chaining. +// */ +// public Builder setInts( +// int index, int value) { +// +// ensureIntsIsMutable(); +// ints_.setInt(index, value); +// onChanged(); +// return this; +// } +// /** +// * repeated sint32 ints = 5; +// * @param value The ints to add. +// * @return This builder for chaining. +// */ +// public Builder addInts(int value) { +// +// ensureIntsIsMutable(); +// ints_.addInt(value); +// onChanged(); +// return this; +// } +// /** +// * repeated sint32 ints = 5; +// * @param values The ints to add. +// * @return This builder for chaining. +// */ +// public Builder addAllInts( +// java.lang.Iterable values) { +// ensureIntsIsMutable(); +// com.google.protobuf.AbstractMessageLite.Builder.addAll( +// values, ints_); +// onChanged(); +// return this; +// } +// /** +// * repeated sint32 ints = 5; +// * @return This builder for chaining. +// */ +// public Builder clearInts() { +// ints_ = emptyIntList(); +// bitField0_ = (bitField0_ & ~0x00000010); +// onChanged(); +// return this; +// } +// +// private com.google.protobuf.Internal.FloatList floats_ = emptyFloatList(); +// private void ensureFloatsIsMutable() { +// if (!((bitField0_ & 0x00000020) != 0)) { +// floats_ = mutableCopy(floats_); +// bitField0_ |= 0x00000020; +// } +// } +// /** +// * repeated float floats = 6; +// * @return A list containing the floats. +// */ +// public java.util.List +// getFloatsList() { +// return ((bitField0_ & 0x00000020) != 0) ? +// java.util.Collections.unmodifiableList(floats_) : floats_; +// } +// /** +// * repeated float floats = 6; +// * @return The count of floats. +// */ +// public int getFloatsCount() { +// return floats_.size(); +// } +// /** +// * repeated float floats = 6; +// * @param index The index of the element to return. +// * @return The floats at the given index. +// */ +// public float getFloats(int index) { +// return floats_.getFloat(index); +// } +// /** +// * repeated float floats = 6; +// * @param index The index to set the value at. +// * @param value The floats to set. +// * @return This builder for chaining. +// */ +// public Builder setFloats( +// int index, float value) { +// +// ensureFloatsIsMutable(); +// floats_.setFloat(index, value); +// onChanged(); +// return this; +// } +// /** +// * repeated float floats = 6; +// * @param value The floats to add. +// * @return This builder for chaining. +// */ +// public Builder addFloats(float value) { +// +// ensureFloatsIsMutable(); +// floats_.addFloat(value); +// onChanged(); +// return this; +// } +// /** +// * repeated float floats = 6; +// * @param values The floats to add. +// * @return This builder for chaining. +// */ +// public Builder addAllFloats( +// java.lang.Iterable values) { +// ensureFloatsIsMutable(); +// com.google.protobuf.AbstractMessageLite.Builder.addAll( +// values, floats_); +// onChanged(); +// return this; +// } +// /** +// * repeated float floats = 6; +// * @return This builder for chaining. +// */ +// public Builder clearFloats() { +// floats_ = emptyFloatList(); +// bitField0_ = (bitField0_ & ~0x00000020); +// onChanged(); +// return this; +// } +// +// private com.google.protobuf.Internal.LongList longs_ = emptyLongList(); +// private void ensureLongsIsMutable() { +// if (!((bitField0_ & 0x00000040) != 0)) { +// longs_ = mutableCopy(longs_); +// bitField0_ |= 0x00000040; +// } +// } +// /** +// * repeated sint64 longs = 7; +// * @return A list containing the longs. +// */ +// public java.util.List +// getLongsList() { +// return ((bitField0_ & 0x00000040) != 0) ? +// java.util.Collections.unmodifiableList(longs_) : longs_; +// } +// /** +// * repeated sint64 longs = 7; +// * @return The count of longs. +// */ +// public int getLongsCount() { +// return longs_.size(); +// } +// /** +// * repeated sint64 longs = 7; +// * @param index The index of the element to return. +// * @return The longs at the given index. +// */ +// public long getLongs(int index) { +// return longs_.getLong(index); +// } +// /** +// * repeated sint64 longs = 7; +// * @param index The index to set the value at. +// * @param value The longs to set. +// * @return This builder for chaining. +// */ +// public Builder setLongs( +// int index, long value) { +// +// ensureLongsIsMutable(); +// longs_.setLong(index, value); +// onChanged(); +// return this; +// } +// /** +// * repeated sint64 longs = 7; +// * @param value The longs to add. +// * @return This builder for chaining. +// */ +// public Builder addLongs(long value) { +// +// ensureLongsIsMutable(); +// longs_.addLong(value); +// onChanged(); +// return this; +// } +// /** +// * repeated sint64 longs = 7; +// * @param values The longs to add. +// * @return This builder for chaining. +// */ +// public Builder addAllLongs( +// java.lang.Iterable values) { +// ensureLongsIsMutable(); +// com.google.protobuf.AbstractMessageLite.Builder.addAll( +// values, longs_); +// onChanged(); +// return this; +// } +// /** +// * repeated sint64 longs = 7; +// * @return This builder for chaining. +// */ +// public Builder clearLongs() { +// longs_ = emptyLongList(); +// bitField0_ = (bitField0_ & ~0x00000040); +// onChanged(); +// return this; +// } +// +// private com.google.protobuf.Internal.DoubleList doubles_ = emptyDoubleList(); +// private void ensureDoublesIsMutable() { +// if (!((bitField0_ & 0x00000080) != 0)) { +// doubles_ = mutableCopy(doubles_); +// bitField0_ |= 0x00000080; +// } +// } +// /** +// * repeated double doubles = 8; +// * @return A list containing the doubles. +// */ +// public java.util.List +// getDoublesList() { +// return ((bitField0_ & 0x00000080) != 0) ? +// java.util.Collections.unmodifiableList(doubles_) : doubles_; +// } +// /** +// * repeated double doubles = 8; +// * @return The count of doubles. +// */ +// public int getDoublesCount() { +// return doubles_.size(); +// } +// /** +// * repeated double doubles = 8; +// * @param index The index of the element to return. +// * @return The doubles at the given index. +// */ +// public double getDoubles(int index) { +// return doubles_.getDouble(index); +// } +// /** +// * repeated double doubles = 8; +// * @param index The index to set the value at. +// * @param value The doubles to set. +// * @return This builder for chaining. +// */ +// public Builder setDoubles( +// int index, double value) { +// +// ensureDoublesIsMutable(); +// doubles_.setDouble(index, value); +// onChanged(); +// return this; +// } +// /** +// * repeated double doubles = 8; +// * @param value The doubles to add. +// * @return This builder for chaining. +// */ +// public Builder addDoubles(double value) { +// +// ensureDoublesIsMutable(); +// doubles_.addDouble(value); +// onChanged(); +// return this; +// } +// /** +// * repeated double doubles = 8; +// * @param values The doubles to add. +// * @return This builder for chaining. +// */ +// public Builder addAllDoubles( +// java.lang.Iterable values) { +// ensureDoublesIsMutable(); +// com.google.protobuf.AbstractMessageLite.Builder.addAll( +// values, doubles_); +// onChanged(); +// return this; +// } +// /** +// * repeated double doubles = 8; +// * @return This builder for chaining. +// */ +// public Builder clearDoubles() { +// doubles_ = emptyDoubleList(); +// bitField0_ = (bitField0_ & ~0x00000080); +// onChanged(); +// return this; +// } +// +// private com.google.protobuf.LazyStringArrayList strings_ = +// com.google.protobuf.LazyStringArrayList.emptyList(); +// private void ensureStringsIsMutable() { +// if (!strings_.isModifiable()) { +// strings_ = new com.google.protobuf.LazyStringArrayList(strings_); +// } +// bitField0_ |= 0x00000100; +// } +// /** +// * repeated string strings = 9; +// * @return A list containing the strings. +// */ +// public com.google.protobuf.ProtocolStringList +// getStringsList() { +// strings_.makeImmutable(); +// return strings_; +// } +// /** +// * repeated string strings = 9; +// * @return The count of strings. +// */ +// public int getStringsCount() { +// return strings_.size(); +// } +// /** +// * repeated string strings = 9; +// * @param index The index of the element to return. +// * @return The strings at the given index. +// */ +// public java.lang.String getStrings(int index) { +// return strings_.get(index); +// } +// /** +// * repeated string strings = 9; +// * @param index The index of the value to return. +// * @return The bytes of the strings at the given index. +// */ +// public com.google.protobuf.ByteString +// getStringsBytes(int index) { +// return strings_.getByteString(index); +// } +// /** +// * repeated string strings = 9; +// * @param index The index to set the value at. +// * @param value The strings to set. +// * @return This builder for chaining. +// */ +// public Builder setStrings( +// int index, java.lang.String value) { +// if (value == null) { throw new NullPointerException(); } +// ensureStringsIsMutable(); +// strings_.set(index, value); +// bitField0_ |= 0x00000100; +// onChanged(); +// return this; +// } +// /** +// * repeated string strings = 9; +// * @param value The strings to add. +// * @return This builder for chaining. +// */ +// public Builder addStrings( +// java.lang.String value) { +// if (value == null) { throw new NullPointerException(); } +// ensureStringsIsMutable(); +// strings_.add(value); +// bitField0_ |= 0x00000100; +// onChanged(); +// return this; +// } +// /** +// * repeated string strings = 9; +// * @param values The strings to add. +// * @return This builder for chaining. +// */ +// public Builder addAllStrings( +// java.lang.Iterable values) { +// ensureStringsIsMutable(); +// com.google.protobuf.AbstractMessageLite.Builder.addAll( +// values, strings_); +// bitField0_ |= 0x00000100; +// onChanged(); +// return this; +// } +// /** +// * repeated string strings = 9; +// * @return This builder for chaining. +// */ +// public Builder clearStrings() { +// strings_ = +// com.google.protobuf.LazyStringArrayList.emptyList(); +// bitField0_ = (bitField0_ & ~0x00000100);; +// onChanged(); +// return this; +// } +// /** +// * repeated string strings = 9; +// * @param value The bytes of the strings to add. +// * @return This builder for chaining. +// */ +// public Builder addStringsBytes( +// com.google.protobuf.ByteString value) { +// if (value == null) { throw new NullPointerException(); } +// checkByteStringIsUtf8(value); +// ensureStringsIsMutable(); +// strings_.add(value); +// bitField0_ |= 0x00000100; +// onChanged(); +// return this; +// } +// +// private int id_ ; +// /** +// * sint32 id = 10; +// * @return The id. +// */ +// @java.lang.Override +// public int getId() { +// return id_; +// } +// /** +// * sint32 id = 10; +// * @param value The id to set. +// * @return This builder for chaining. +// */ +// public Builder setId(int value) { +// +// id_ = value; +// bitField0_ |= 0x00000200; +// onChanged(); +// return this; +// } +// /** +// * sint32 id = 10; +// * @return This builder for chaining. +// */ +// public Builder clearId() { +// bitField0_ = (bitField0_ & ~0x00000200); +// id_ = 0; +// onChanged(); +// return this; +// } +// +// private java.lang.Object name_ = ""; +// /** +// * string name = 11; +// * @return The name. +// */ +// public java.lang.String getName() { +// java.lang.Object ref = name_; +// if (!(ref instanceof java.lang.String)) { +// com.google.protobuf.ByteString bs = +// (com.google.protobuf.ByteString) ref; +// java.lang.String s = bs.toStringUtf8(); +// name_ = s; +// return s; +// } else { +// return (java.lang.String) ref; +// } +// } +// /** +// * string name = 11; +// * @return The bytes for name. +// */ +// public com.google.protobuf.ByteString +// getNameBytes() { +// java.lang.Object ref = name_; +// if (ref instanceof String) { +// com.google.protobuf.ByteString b = +// com.google.protobuf.ByteString.copyFromUtf8( +// (java.lang.String) ref); +// name_ = b; +// return b; +// } else { +// return (com.google.protobuf.ByteString) ref; +// } +// } +// /** +// * string name = 11; +// * @param value The name to set. +// * @return This builder for chaining. +// */ +// public Builder setName( +// java.lang.String value) { +// if (value == null) { throw new NullPointerException(); } +// name_ = value; +// bitField0_ |= 0x00000400; +// onChanged(); +// return this; +// } +// /** +// * string name = 11; +// * @return This builder for chaining. +// */ +// public Builder clearName() { +// name_ = getDefaultInstance().getName(); +// bitField0_ = (bitField0_ & ~0x00000400); +// onChanged(); +// return this; +// } +// /** +// * string name = 11; +// * @param value The bytes for name to set. +// * @return This builder for chaining. +// */ +// public Builder setNameBytes( +// com.google.protobuf.ByteString value) { +// if (value == null) { throw new NullPointerException(); } +// checkByteStringIsUtf8(value); +// name_ = value; +// bitField0_ |= 0x00000400; +// onChanged(); +// return this; +// } +// +// private java.lang.Object email_ = ""; +// /** +// * string email = 12; +// * @return The email. +// */ +// public java.lang.String getEmail() { +// java.lang.Object ref = email_; +// if (!(ref instanceof java.lang.String)) { +// com.google.protobuf.ByteString bs = +// (com.google.protobuf.ByteString) ref; +// java.lang.String s = bs.toStringUtf8(); +// email_ = s; +// return s; +// } else { +// return (java.lang.String) ref; +// } +// } +// /** +// * string email = 12; +// * @return The bytes for email. +// */ +// public com.google.protobuf.ByteString +// getEmailBytes() { +// java.lang.Object ref = email_; +// if (ref instanceof String) { +// com.google.protobuf.ByteString b = +// com.google.protobuf.ByteString.copyFromUtf8( +// (java.lang.String) ref); +// email_ = b; +// return b; +// } else { +// return (com.google.protobuf.ByteString) ref; +// } +// } +// /** +// * string email = 12; +// * @param value The email to set. +// * @return This builder for chaining. +// */ +// public Builder setEmail( +// java.lang.String value) { +// if (value == null) { throw new NullPointerException(); } +// email_ = value; +// bitField0_ |= 0x00000800; +// onChanged(); +// return this; +// } +// /** +// * string email = 12; +// * @return This builder for chaining. +// */ +// public Builder clearEmail() { +// email_ = getDefaultInstance().getEmail(); +// bitField0_ = (bitField0_ & ~0x00000800); +// onChanged(); +// return this; +// } +// /** +// * string email = 12; +// * @param value The bytes for email to set. +// * @return This builder for chaining. +// */ +// public Builder setEmailBytes( +// com.google.protobuf.ByteString value) { +// if (value == null) { throw new NullPointerException(); } +// checkByteStringIsUtf8(value); +// email_ = value; +// bitField0_ |= 0x00000800; +// onChanged(); +// return this; +// } +// +// private int kind_ = 0; +// /** +// * .PTestBean.Kind kind = 13; +// * @return The enum numeric value on the wire for kind. +// */ +// @java.lang.Override public int getKindValue() { +// return kind_; +// } +// /** +// * .PTestBean.Kind kind = 13; +// * @param value The enum numeric value on the wire for kind to set. +// * @return This builder for chaining. +// */ +// public Builder setKindValue(int value) { +// kind_ = value; +// bitField0_ |= 0x00001000; +// onChanged(); +// return this; +// } +// /** +// * .PTestBean.Kind kind = 13; +// * @return The kind. +// */ +// @java.lang.Override +// public org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.Kind getKind() { +// org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.Kind result = org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.Kind.forNumber(kind_); +// return result == null ? org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.Kind.UNRECOGNIZED : result; +// } +// /** +// * .PTestBean.Kind kind = 13; +// * @param value The kind to set. +// * @return This builder for chaining. +// */ +// public Builder setKind(org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.Kind value) { +// if (value == null) { +// throw new NullPointerException(); +// } +// bitField0_ |= 0x00001000; +// kind_ = value.getNumber(); +// onChanged(); +// return this; +// } +// /** +// * .PTestBean.Kind kind = 13; +// * @return This builder for chaining. +// */ +// public Builder clearKind() { +// bitField0_ = (bitField0_ & ~0x00001000); +// kind_ = 0; +// onChanged(); +// return this; +// } +// +// private com.google.protobuf.MapField< +// java.lang.String, java.lang.Integer> map_; +// private com.google.protobuf.MapField +// internalGetMap() { +// if (map_ == null) { +// return com.google.protobuf.MapField.emptyMapField( +// MapDefaultEntryHolder.defaultEntry); +// } +// return map_; +// } +// private com.google.protobuf.MapField +// internalGetMutableMap() { +// if (map_ == null) { +// map_ = com.google.protobuf.MapField.newMapField( +// MapDefaultEntryHolder.defaultEntry); +// } +// if (!map_.isMutable()) { +// map_ = map_.copy(); +// } +// bitField0_ |= 0x00002000; +// onChanged(); +// return map_; +// } +// public int getMapCount() { +// return internalGetMap().getMap().size(); +// } +// /** +// * map<string, sint32> map = 14; +// */ +// @java.lang.Override +// public boolean containsMap( +// java.lang.String key) { +// if (key == null) { throw new NullPointerException("map key"); } +// return internalGetMap().getMap().containsKey(key); +// } +// /** +// * Use {@link #getMapMap()} instead. +// */ +// @java.lang.Override +// @java.lang.Deprecated +// public java.util.Map getMap() { +// return getMapMap(); +// } +// /** +// * map<string, sint32> map = 14; +// */ +// @java.lang.Override +// public java.util.Map getMapMap() { +// return internalGetMap().getMap(); +// } +// /** +// * map<string, sint32> map = 14; +// */ +// @java.lang.Override +// public int getMapOrDefault( +// java.lang.String key, +// int defaultValue) { +// if (key == null) { throw new NullPointerException("map key"); } +// java.util.Map map = +// internalGetMap().getMap(); +// return map.containsKey(key) ? map.get(key) : defaultValue; +// } +// /** +// * map<string, sint32> map = 14; +// */ +// @java.lang.Override +// public int getMapOrThrow( +// java.lang.String key) { +// if (key == null) { throw new NullPointerException("map key"); } +// java.util.Map map = +// internalGetMap().getMap(); +// if (!map.containsKey(key)) { +// throw new java.lang.IllegalArgumentException(); +// } +// return map.get(key); +// } +// public Builder clearMap() { +// bitField0_ = (bitField0_ & ~0x00002000); +// internalGetMutableMap().getMutableMap() +// .clear(); +// return this; +// } +// /** +// * map<string, sint32> map = 14; +// */ +// public Builder removeMap( +// java.lang.String key) { +// if (key == null) { throw new NullPointerException("map key"); } +// internalGetMutableMap().getMutableMap() +// .remove(key); +// return this; +// } +// /** +// * Use alternate mutation accessors instead. +// */ +// @java.lang.Deprecated +// public java.util.Map +// getMutableMap() { +// bitField0_ |= 0x00002000; +// return internalGetMutableMap().getMutableMap(); +// } +// /** +// * map<string, sint32> map = 14; +// */ +// public Builder putMap( +// java.lang.String key, +// int value) { +// if (key == null) { throw new NullPointerException("map key"); } +// +// internalGetMutableMap().getMutableMap() +// .put(key, value); +// bitField0_ |= 0x00002000; +// return this; +// } +// /** +// * map<string, sint32> map = 14; +// */ +// public Builder putAllMap( +// java.util.Map values) { +// internalGetMutableMap().getMutableMap() +// .putAll(values); +// bitField0_ |= 0x00002000; +// return this; +// } +// +// private java.lang.Object end_ = ""; +// /** +// * string end = 15; +// * @return The end. +// */ +// public java.lang.String getEnd() { +// java.lang.Object ref = end_; +// if (!(ref instanceof java.lang.String)) { +// com.google.protobuf.ByteString bs = +// (com.google.protobuf.ByteString) ref; +// java.lang.String s = bs.toStringUtf8(); +// end_ = s; +// return s; +// } else { +// return (java.lang.String) ref; +// } +// } +// /** +// * string end = 15; +// * @return The bytes for end. +// */ +// public com.google.protobuf.ByteString +// getEndBytes() { +// java.lang.Object ref = end_; +// if (ref instanceof String) { +// com.google.protobuf.ByteString b = +// com.google.protobuf.ByteString.copyFromUtf8( +// (java.lang.String) ref); +// end_ = b; +// return b; +// } else { +// return (com.google.protobuf.ByteString) ref; +// } +// } +// /** +// * string end = 15; +// * @param value The end to set. +// * @return This builder for chaining. +// */ +// public Builder setEnd( +// java.lang.String value) { +// if (value == null) { throw new NullPointerException(); } +// end_ = value; +// bitField0_ |= 0x00004000; +// onChanged(); +// return this; +// } +// /** +// * string end = 15; +// * @return This builder for chaining. +// */ +// public Builder clearEnd() { +// end_ = getDefaultInstance().getEnd(); +// bitField0_ = (bitField0_ & ~0x00004000); +// onChanged(); +// return this; +// } +// /** +// * string end = 15; +// * @param value The bytes for end to set. +// * @return This builder for chaining. +// */ +// public Builder setEndBytes( +// com.google.protobuf.ByteString value) { +// if (value == null) { throw new NullPointerException(); } +// checkByteStringIsUtf8(value); +// end_ = value; +// bitField0_ |= 0x00004000; +// onChanged(); +// return this; +// } +// @java.lang.Override +// public final Builder setUnknownFields( +// final com.google.protobuf.UnknownFieldSet unknownFields) { +// return super.setUnknownFields(unknownFields); +// } +// +// @java.lang.Override +// public final Builder mergeUnknownFields( +// final com.google.protobuf.UnknownFieldSet unknownFields) { +// return super.mergeUnknownFields(unknownFields); +// } +// +// +// // @@protoc_insertion_point(builder_scope:PTestBean) +// } +// +// // @@protoc_insertion_point(class_scope:PTestBean) +// private static final org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean DEFAULT_INSTANCE; +// static { +// DEFAULT_INSTANCE = new org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean(); +// } +// +// public static org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean getDefaultInstance() { +// return DEFAULT_INSTANCE; +// } +// +// private static final com.google.protobuf.Parser +// PARSER = new com.google.protobuf.AbstractParser() { +// @java.lang.Override +// public PTestBean parsePartialFrom( +// com.google.protobuf.CodedInputStream input, +// com.google.protobuf.ExtensionRegistryLite extensionRegistry) +// throws com.google.protobuf.InvalidProtocolBufferException { +// Builder builder = newBuilder(); +// try { +// builder.mergeFrom(input, extensionRegistry); +// } catch (com.google.protobuf.InvalidProtocolBufferException e) { +// throw e.setUnfinishedMessage(builder.buildPartial()); +// } catch (com.google.protobuf.UninitializedMessageException e) { +// throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial()); +// } catch (java.io.IOException e) { +// throw new com.google.protobuf.InvalidProtocolBufferException(e) +// .setUnfinishedMessage(builder.buildPartial()); +// } +// return builder.buildPartial(); +// } +// }; +// +// public static com.google.protobuf.Parser parser() { +// return PARSER; +// } +// +// @java.lang.Override +// public com.google.protobuf.Parser getParserForType() { +// return PARSER; +// } +// +// @java.lang.Override +// public org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean getDefaultInstanceForType() { +// return DEFAULT_INSTANCE; +// } +// +// } +// +// private static final com.google.protobuf.Descriptors.Descriptor +// internal_static_PTestBean_descriptor; +// private static final +// com.google.protobuf.GeneratedMessageV3.FieldAccessorTable +// internal_static_PTestBean_fieldAccessorTable; +// private static final com.google.protobuf.Descriptors.Descriptor +// internal_static_PTestBean_PTestEntry_descriptor; +// private static final +// com.google.protobuf.GeneratedMessageV3.FieldAccessorTable +// internal_static_PTestBean_PTestEntry_fieldAccessorTable; +// private static final com.google.protobuf.Descriptors.Descriptor +// internal_static_PTestBean_MapEntry_descriptor; +// private static final +// com.google.protobuf.GeneratedMessageV3.FieldAccessorTable +// internal_static_PTestBean_MapEntry_fieldAccessorTable; +// +// public static com.google.protobuf.Descriptors.FileDescriptor +// getDescriptor() { +// return descriptor; +// } +// private static com.google.protobuf.Descriptors.FileDescriptor +// descriptor; +// static { +// java.lang.String[] descriptorData = { +// "\n8src/test/java/org/redkalex/test/protob" + +// "uf/PTestBean.proto\"\301\003\n\tPTestBean\022\r\n\005bool" + +// "s\030\001 \003(\010\022\r\n\005bytes\030\002 \003(\014\022\r\n\005chars\030\003 \003(\021\022%\n" + +// "\006entrys\030\004 \003(\0132\025.PTestBean.PTestEntry\022\014\n\004" + +// "ints\030\005 \003(\021\022\016\n\006floats\030\006 \003(\002\022\r\n\005longs\030\007 \003(" + +// "\022\022\017\n\007doubles\030\010 \003(\001\022\017\n\007strings\030\t \003(\t\022\n\n\002i" + +// "d\030\n \001(\021\022\014\n\004name\030\013 \001(\t\022\r\n\005email\030\014 \001(\t\022\035\n\004" + +// "kind\030\r \001(\0162\017.PTestBean.Kind\022 \n\003map\030\016 \003(\013" + +// "2\023.PTestBean.MapEntry\022\013\n\003end\030\017 \001(\t\032I\n\nPT" + +// "estEntry\022\r\n\005bools\030\001 \003(\010\022\r\n\005bytes\030\002 \003(\014\022\r" + +// "\n\005chars\030\003 \003(\021\022\016\n\006shorts\030\004 \003(\021\032*\n\010MapEntr" + +// "y\022\013\n\003key\030\001 \001(\t\022\r\n\005value\030\002 \001(\021:\0028\001\"#\n\004Kin" + +// "d\022\007\n\003ONE\020\000\022\007\n\003TWO\020\001\022\t\n\005THREE\020\002B\034\n\032org.re" + +// "dkalex.test.protobufb\006proto3" +// }; +// descriptor = com.google.protobuf.Descriptors.FileDescriptor +// .internalBuildGeneratedFileFrom(descriptorData, +// new com.google.protobuf.Descriptors.FileDescriptor[] { +// }); +// internal_static_PTestBean_descriptor = +// getDescriptor().getMessageTypes().get(0); +// internal_static_PTestBean_fieldAccessorTable = new +// com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( +// internal_static_PTestBean_descriptor, +// new java.lang.String[] { "Bools", "Bytes", "Chars", "Entrys", "Ints", "Floats", "Longs", "Doubles", "Strings", "Id", "Name", "Email", "Kind", "Map", "End", }); +// internal_static_PTestBean_PTestEntry_descriptor = +// internal_static_PTestBean_descriptor.getNestedTypes().get(0); +// internal_static_PTestBean_PTestEntry_fieldAccessorTable = new +// com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( +// internal_static_PTestBean_PTestEntry_descriptor, +// new java.lang.String[] { "Bools", "Bytes", "Chars", "Shorts", }); +// internal_static_PTestBean_MapEntry_descriptor = +// internal_static_PTestBean_descriptor.getNestedTypes().get(1); +// internal_static_PTestBean_MapEntry_fieldAccessorTable = new +// com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( +// internal_static_PTestBean_MapEntry_descriptor, +// new java.lang.String[] { "Key", "Value", }); +// } +// +// // @@protoc_insertion_point(outer_class_scope) +//} diff --git a/src/test/java/org/redkale/test/convert/protobuf/SimpleBean.java b/src/test/java/org/redkale/test/convert/protobuf/SimpleBean.java new file mode 100644 index 000000000..3386fc521 --- /dev/null +++ b/src/test/java/org/redkale/test/convert/protobuf/SimpleBean.java @@ -0,0 +1,105 @@ +package org.redkale.test.convert.protobuf; + +///* +// * 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.test.protobuf; +// +//import java.util.Arrays; +//import org.redkale.convert.ConvertColumn; +//import org.redkale.convert.json.JsonConvert; +//import org.redkale.util.Utility; +//import org.redkalex.convert.protobuf.ProtobufConvert; +// +///** +// * +// * @author zhangjx +// */ +//public class SimpleBean { +// +// public static class PSimpleEntry { +// +// @ConvertColumn(index = 1) +// public int id = 66; +// +// @ConvertColumn(index = 2) +// public String name = "哈哈"; +// +// @ConvertColumn(index = 3) +// public String email = "redkale@redkale.org"; +// } +// +// public static class PTwoEntry { +// +// @ConvertColumn(index = 1) +// public int status = 2; +// +// @ConvertColumn(index = 2) +// public long createtime = System.currentTimeMillis(); +// +// } +// +// @ConvertColumn(index = 1) +// public PSimpleEntry simple; +// +// @ConvertColumn(index = 2) +// public PTwoEntry two; +// +// @ConvertColumn(index = 3) +// public String strings = "abcd"; +// +// @Override +// public String toString() { +// return JsonConvert.root().convertTo(this); +// } +// +// public static void main(String[] args) throws Throwable { +// //System.out.println(ProtobufConvert.root().getProtoDescriptor(SimpleBean.class)); +// SimpleBean bean = new SimpleBean(); +// bean.simple = new PSimpleEntry(); +// bean.two = new PTwoEntry(); +// bean.strings = "abcde"; +// +// //------------------------------- +// byte[] jsonbs = JsonConvert.root().convertToBytes(bean); +// byte[] bs = ProtobufConvert.root().convertTo(bean); +// Utility.println("predkale ", bs); +// PSimpleBeanOuterClass.PSimpleBean.Builder builder = PSimpleBeanOuterClass.PSimpleBean.newBuilder(); +// +// PSimpleBeanOuterClass.PSimpleBean bean2 = createPSimpleBean(bean, builder); +// byte[] bs2 = bean2.toByteArray(); +// Utility.println("protobuf ", bs2); +// Thread.sleep(10); +// if (!Arrays.equals(bs, bs2)) throw new RuntimeException("两者序列化出来的byte[]不一致"); +// +// System.out.println(bean); +// System.out.println(ProtobufConvert.root().convertFrom(SimpleBean.class, bs).toString()); +// System.out.println(JsonConvert.root().convertFrom(SimpleBean.class, jsonbs).toString()); +// +// } +// +// private static PSimpleBeanOuterClass.PSimpleBean createPSimpleBean(SimpleBean bean, PSimpleBeanOuterClass.PSimpleBean.Builder builder) { +// if (builder == null) { +// builder = PSimpleBeanOuterClass.PSimpleBean.newBuilder(); +// } else { +// builder.clear(); +// } +// PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry.Builder sentry = PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry.newBuilder(); +// sentry.setId(bean.simple.id); +// sentry.setName(bean.simple.name); +// sentry.setEmail(bean.simple.email); +// builder.setSimple(sentry.build()); +// +// PSimpleBeanOuterClass.PSimpleBean.PTwoEntry.Builder tentry = PSimpleBeanOuterClass.PSimpleBean.PTwoEntry.newBuilder(); +// tentry.setStatus(bean.two.status); +// tentry.setCreatetime(bean.two.createtime); +// builder.setTwo(tentry.build()); +// +// builder.setStrings(bean.strings); +// +// PSimpleBeanOuterClass.PSimpleBean bean2 = builder.build(); +// return bean2; +// } +//} diff --git a/src/test/java/org/redkale/test/convert/protobuf/TestBean.java b/src/test/java/org/redkale/test/convert/protobuf/TestBean.java new file mode 100644 index 000000000..8bcf7701e --- /dev/null +++ b/src/test/java/org/redkale/test/convert/protobuf/TestBean.java @@ -0,0 +1,241 @@ +package org.redkale.test.convert.protobuf; + +///* +// * 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.test.protobuf; +// +//import org.redkalex.convert.protobuf.ProtobufReader; +//import org.redkalex.convert.protobuf.ProtobufConvert; +//import com.google.protobuf.*; +//import java.util.*; +//import org.redkale.convert.ConvertColumn; +//import org.redkale.convert.json.JsonConvert; +//import org.redkale.service.RetResult; +//import org.redkale.util.*; +// +///** +// * +// * @author zhangjx +// */ +//public class TestBean { +// +// public static class PTestEntry { +// +// @ConvertColumn(index = 1) +// public boolean[] bools = new boolean[]{true, false, true}; +// +// @ConvertColumn(index = 2) +// public byte[] bytes = new byte[]{1, 2, 3, 4}; +// +// @ConvertColumn(index = 3) +// public char[] chars = new char[]{'A', 'B', 'C'}; +// +// @ConvertColumn(index = 4) +// public short[] shorts = new short[]{10, 20, 30}; +// +// @Override +// public String toString() { +// return JsonConvert.root().convertTo(this); +// } +// } +// +// public static enum Kind { +// ONE, +// TWO, +// THREE +// } +// +// @ConvertColumn(index = 1) +// public boolean[] bools; +// +// @ConvertColumn(index = 2) +// public byte[] bytes; +// +// @ConvertColumn(index = 3) +// public char[] chars; +// +// @ConvertColumn(index = 4) +// public PTestEntry[] entrys; +// +// @ConvertColumn(index = 5) +// public int[] ints; +// +// @ConvertColumn(index = 6) +// public float[] floats; +// +// @ConvertColumn(index = 7) +// public long[] longs; +// +// @ConvertColumn(index = 8) +// public double[] doubles; //8 +// +// @ConvertColumn(index = 9) +// public String[] strings; //9 +// +// @ConvertColumn(index = 10) +// public int id = 0x7788; //10 +// +// @ConvertColumn(index = 11) +// public String name; //11 +// +// @ConvertColumn(index = 12) +// public String email; //12 +// +// @ConvertColumn(index = 13) +// public Kind kind; //13 +// +// @ConvertColumn(index = 14) +// public Map map; //14 +// +// @ConvertColumn(index = 15) +// public String end; //15 +// +// @Override +// public String toString() { +// return JsonConvert.root().convertTo(this); +// } +// +// public static void main3(String[] args) throws Throwable { +// byte[] src = new byte[]{(byte) 0x82, (byte) 0x01, (byte) 0x84, (byte) 0x01, (byte) 0x86, (byte) 0x01}; +// src = new byte[]{(byte) 0x01, (byte) 0x00, (byte) 0x01, (byte) 0x01}; +// CodedInputStream input = CodedInputStream.newInstance(src); +// System.out.println("结果1: " + input.readSInt32()); +// System.out.println("结果1: " + input.readSInt32()); +// System.out.println("结果1: " + input.readSInt32()); +// ProtobufReader reader = new ProtobufReader(src); +// System.out.println("结果2: " + reader.readInt()); +// System.out.println("结果2: " + reader.readInt()); +// System.out.println("结果2: " + reader.readInt()); +// } +// +// private static java.lang.reflect.Type retstring = new TypeToken>>() { +// }.getType(); +// +// public static void main2(String[] args) throws Throwable { +// System.out.println(ProtobufConvert.root().getProtoDescriptor(retstring)); +// } +// +// public static void main(String[] args) throws Throwable { +// System.setProperty("convert.protobuf.enumtostring", "false"); //禁用枚举按字符串类型出来 +// //System.out.println(ProtobufConvert.root().getProtoDescriptor(TestBean.class)); +// //System.out.println(Integer.toHexString(14<<3|2)); +// TestBean bean = new TestBean(); +// +// bean.bools = new boolean[]{true, false, true}; +// bean.bytes = new byte[]{1, 2, 3, 4}; +// bean.chars = new char[]{'A', 'B', 'C'}; +// bean.ints = new int[]{100, 200, 300}; +// bean.floats = new float[]{10.12f, 20.34f}; +// bean.longs = new long[]{111, 222, 333}; +// bean.doubles = new double[]{65.65, 78.78}; +// bean.name = "redkale"; +// bean.email = "redkale@qq.org"; +// bean.kind = Kind.TWO; +// bean.strings = new String[]{"str1", "str2", "str3"}; +// bean.entrys = new PTestEntry[]{new PTestEntry(), null, new PTestEntry()}; +// bean.map = Utility.ofMap("aa", 0x55, "bb", 0x66); +// bean.end = "over"; +// +// //------------------------------- +// byte[] jsonbs = JsonConvert.root().convertToBytes(bean); +// byte[] bs = ProtobufConvert.root().convertTo(bean); +// Utility.println("pconvert ", bs); +// PTestBeanOuterClass.PTestBean.Builder builder = PTestBeanOuterClass.PTestBean.newBuilder(); +// +// PTestBeanOuterClass.PTestBean bean2 = createPTestBean(bean, builder); +// byte[] bs2 = bean2.toByteArray(); +// Utility.println("protobuf ", bs2); +// Thread.sleep(10); +// if (!Arrays.equals(bs, bs2)) throw new RuntimeException("两者序列化出来的byte[]不一致"); +// +// System.out.println(bean); +// String frombean = ProtobufConvert.root().convertFrom(TestBean.class, bs).toString(); +// System.out.println(frombean); +// if (!bean.toString().equals(frombean)) throw new RuntimeException("ProtobufConvert反解析后的结果不正确"); +// System.out.println(JsonConvert.root().convertFrom(TestBean.class, jsonbs).toString()); +// +// int count = 100000; +// long s, e; +// s = System.currentTimeMillis(); +// for (int z = 0; z < count; z++) { +// ProtobufConvert.root().convertTo(bean); +// } +// e = System.currentTimeMillis() - s; +// System.out.println("redkale-protobuf耗时-------" + e); +// +// s = System.currentTimeMillis(); +// for (int z = 0; z < count; z++) { +// JsonConvert.root().convertToBytes(bean); +// } +// e = System.currentTimeMillis() - s; +// System.out.println("redkale-json文本耗时-------" + e); +// +// s = System.currentTimeMillis(); +// for (int z = 0; z < count; z++) { +// createPTestBean(bean, builder).toByteArray(); +// } +// e = System.currentTimeMillis() - s; +// System.out.println("原生编译protobuf耗时-------" + e); +// } +// +// private static PTestBeanOuterClass.PTestBean createPTestBean(TestBean bean, PTestBeanOuterClass.PTestBean.Builder builder) { +// if (builder == null) { +// builder = PTestBeanOuterClass.PTestBean.newBuilder(); +// } else { +// builder.clear(); +// } +// for (int i = 0; bean.bools != null && i < bean.bools.length; i++) { +// builder.addBools(bean.bools[i]); +// } +// if (bean.bytes != null) builder.addBytes(ByteString.copyFrom(bean.bytes)); +// for (int i = 0; bean.chars != null && i < bean.chars.length; i++) { +// builder.addChars(bean.chars[i]); +// } +// for (int i = 0; bean.entrys != null && i < bean.entrys.length; i++) { +// PTestBeanOuterClass.PTestBean.PTestEntry.Builder entry = PTestBeanOuterClass.PTestBean.PTestEntry.newBuilder(); +// if (bean.entrys[i] == null) { +// builder.addEntrys(entry.build()); +// continue; +// } +// for (int j = 0; bean.entrys[i].bools != null && j < bean.entrys[i].bools.length; j++) { +// entry.addBools(bean.entrys[i].bools[j]); +// } +// if (bean.entrys[i].bytes != null) entry.addBytes(ByteString.copyFrom(bean.entrys[i].bytes)); +// for (int j = 0; bean.entrys[i].chars != null && j < bean.entrys[i].chars.length; j++) { +// entry.addChars(bean.entrys[i].chars[j]); +// } +// for (int j = 0; bean.entrys[i].shorts != null && j < bean.entrys[i].shorts.length; j++) { +// entry.addShorts(bean.entrys[i].shorts[j]); +// } +// builder.addEntrys(entry.build()); +// } +// for (int i = 0; bean.ints != null && i < bean.ints.length; i++) { +// builder.addInts(bean.ints[i]); +// } +// for (int i = 0; bean.floats != null && i < bean.floats.length; i++) { +// builder.addFloats(bean.floats[i]); +// } +// for (int i = 0; bean.longs != null && i < bean.longs.length; i++) { +// builder.addLongs(bean.longs[i]); +// } +// for (int i = 0; bean.doubles != null && i < bean.doubles.length; i++) { +// builder.addDoubles(bean.doubles[i]); +// } +// for (int i = 0; bean.strings != null && i < bean.strings.length; i++) { +// builder.addStrings(bean.strings[i]); +// } +// builder.setId(bean.id); +// if (bean.name != null) builder.setName(bean.name); +// if (bean.email != null) builder.setEmail(bean.email); +// if (bean.kind != null) builder.setKind(PTestBeanOuterClass.PTestBean.Kind.TWO); +// if (bean.map != null) builder.putAllMap(bean.map); +// if (bean.end != null) builder.setEnd(bean.end); +// PTestBeanOuterClass.PTestBean bean2 = builder.build(); +// return bean2; +// } +//} +// +////protoc --java_out=D:\Java-Projects\RedkalePluginsProject\test\ --proto_path=D:\Java-Projects\RedkalePluginsProject\test\org\redkalex\test\protobuf\ PTestBean.proto