Skip to content

Commit d91033e

Browse files
authored
Parse RESP3 Boolean (#3407)
1 parent 63141ec commit d91033e

File tree

3 files changed

+26
-30
lines changed

3 files changed

+26
-30
lines changed

src/main/java/redis/clients/jedis/BuilderFactory.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ public String toString() {
137137
@Override
138138
public Boolean build(Object data) {
139139
if (data == null) return null;
140+
else if (data instanceof Boolean) return (Boolean) data;
140141
return ((Long) data) == 1L;
141142
}
142143

@@ -150,15 +151,8 @@ public String toString() {
150151
@Override
151152
@SuppressWarnings("unchecked")
152153
public List<Boolean> build(Object data) {
153-
if (null == data) {
154-
return null;
155-
}
156-
List<Long> longs = (List<Long>) data;
157-
List<Boolean> booleans = new ArrayList<>(longs.size());
158-
for (Long value : longs) {
159-
booleans.add(value == null ? null : value == 1L);
160-
}
161-
return booleans;
154+
if (null == data) return null;
155+
return ((List<Object>) data).stream().map(BOOLEAN::build).collect(Collectors.toList());
162156
}
163157

164158
@Override

src/main/java/redis/clients/jedis/Protocol.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,12 @@ private static Object process(final RedisInputStream is) {
144144
num = is.readIntCrLf();
145145
if (num == -1) return null;
146146
return processMultiBulkReply(num, is);
147-
case COLON_BYTE:
148-
return is.readLongCrLf();
149147
case UNDERSCORE_BYTE:
150148
return is.readNullCrLf();
149+
case HASH_BYTE:
150+
return is.readBooleanCrLf();
151+
case COLON_BYTE:
152+
return is.readLongCrLf();
151153
case COMMA_BYTE:
152154
return is.readDoubleCrLf();
153155
case LEFT_BRACE_BYTE:

src/main/java/redis/clients/jedis/util/RedisInputStream.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -63,25 +63,6 @@ private void ensureCrLf() {
6363
throw new JedisConnectionException("Unexpected character!");
6464
}
6565

66-
public Object readNullCrLf() {
67-
ensureCrLf();
68-
return null;
69-
}
70-
71-
public boolean readBooleanCrLf() {
72-
final byte[] buf = this.buf;
73-
74-
ensureFill();
75-
final byte b = buf[count++];
76-
77-
ensureCrLf();
78-
switch (b) {
79-
case 't': return true;
80-
case 'f': return false;
81-
default: throw new JedisConnectionException("Unexpected character!");
82-
}
83-
}
84-
8566
public String readLine() {
8667
final StringBuilder sb = new StringBuilder();
8768
while (true) {
@@ -182,6 +163,25 @@ private byte[] readLineBytesSlowly() {
182163
return bout == null ? new byte[0] : bout.toByteArray();
183164
}
184165

166+
public Object readNullCrLf() {
167+
ensureCrLf();
168+
return null;
169+
}
170+
171+
public boolean readBooleanCrLf() {
172+
final byte[] buf = this.buf;
173+
174+
ensureFill();
175+
final byte b = buf[count++];
176+
177+
ensureCrLf();
178+
switch (b) {
179+
case 't': return true;
180+
case 'f': return false;
181+
default: throw new JedisConnectionException("Unexpected character!");
182+
}
183+
}
184+
185185
public int readIntCrLf() {
186186
return (int) readLongCrLf();
187187
}

0 commit comments

Comments
 (0)