From 40000ae02640a4cbc9619539b9fb951f99171753 Mon Sep 17 00:00:00 2001 From: redkale Date: Mon, 30 Sep 2024 10:11:40 +0800 Subject: [PATCH] protobuf --- .../redkale/convert/json/JsonByteBufferReader.java | 12 ++++++------ .../org/redkale/convert/pb/ProtobufReader.java | 14 ++++---------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/main/java/org/redkale/convert/json/JsonByteBufferReader.java b/src/main/java/org/redkale/convert/json/JsonByteBufferReader.java index b09efef25..170822353 100644 --- a/src/main/java/org/redkale/convert/json/JsonByteBufferReader.java +++ b/src/main/java/org/redkale/convert/json/JsonByteBufferReader.java @@ -20,7 +20,7 @@ import static org.redkale.convert.Reader.*; */ public class JsonByteBufferReader extends JsonReader { - private char currentChar; + private char cacheChar; private ByteBuffer[] buffers; @@ -38,7 +38,7 @@ public class JsonByteBufferReader extends JsonReader { @Override protected boolean recycle() { super.recycle(); // this.position 初始化值为-1 - this.currentChar = 0; + this.cacheChar = 0; this.buffers = null; this.currBufIndex = 0; this.currentBuffer = null; @@ -70,9 +70,9 @@ public class JsonByteBufferReader extends JsonReader { } protected final char nextChar(CharArray sb) { - if (currentChar != 0) { - char ch = currentChar; - this.currentChar = 0; + if (cacheChar != 0) { + char ch = cacheChar; + this.cacheChar = 0; return ch; } if (this.currentBuffer != null) { @@ -155,7 +155,7 @@ public class JsonByteBufferReader extends JsonReader { */ @Override protected final void backChar(char ch) { - this.currentChar = ch; + this.cacheChar = ch; } /** diff --git a/src/main/java/org/redkale/convert/pb/ProtobufReader.java b/src/main/java/org/redkale/convert/pb/ProtobufReader.java index d3a87b96b..a5b784ea1 100644 --- a/src/main/java/org/redkale/convert/pb/ProtobufReader.java +++ b/src/main/java/org/redkale/convert/pb/ProtobufReader.java @@ -20,9 +20,7 @@ public class ProtobufReader extends Reader { protected int limit = -1; - protected int cacheTag = Integer.MIN_VALUE; - - protected boolean enumtostring; + protected Integer cacheTag; private byte[] content; @@ -38,11 +36,6 @@ public class ProtobufReader extends Reader { setBytes(bytes, start, len); } - public ProtobufReader enumtostring(boolean enumtostring) { - this.enumtostring = enumtostring; - return this; - } - @Override public void prepare(byte[] bytes) { setBytes(bytes); @@ -80,6 +73,7 @@ public class ProtobufReader extends Reader { this.position = -1; this.limit = -1; this.content = null; + this.cacheTag = null; return true; } @@ -468,9 +462,9 @@ public class ProtobufReader extends Reader { } protected final int readTag() { - if (cacheTag != Integer.MIN_VALUE) { + if (cacheTag != null) { int tag = cacheTag; - cacheTag = Integer.MIN_VALUE; + cacheTag = null; return tag; } return readRawVarint32();