1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.handler.codec.redis;
17
18 import io.netty.util.CharsetUtil;
19 import io.netty.util.internal.PlatformDependent;
20
21
22
23
24 final class RedisCodecUtil {
25
26 private RedisCodecUtil() {
27 }
28
29 static byte[] longToAsciiBytes(long value) {
30 return Long.toString(value).getBytes(CharsetUtil.US_ASCII);
31 }
32
33
34
35
36 static short makeShort(char first, char second) {
37 return PlatformDependent.BIG_ENDIAN_NATIVE_ORDER ?
38 (short) ((second << 8) | first) : (short) ((first << 8) | second);
39 }
40
41
42
43
44 static byte[] shortToBytes(short value) {
45 byte[] bytes = new byte[2];
46 if (PlatformDependent.BIG_ENDIAN_NATIVE_ORDER) {
47 bytes[1] = (byte) ((value >> 8) & 0xff);
48 bytes[0] = (byte) (value & 0xff);
49 } else {
50 bytes[0] = (byte) ((value >> 8) & 0xff);
51 bytes[1] = (byte) (value & 0xff);
52 }
53 return bytes;
54 }
55 }