• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

alibaba / jetcache / #405

16 Apr 2024 05:58AM UTC coverage: 0.0% (-88.9%) from 88.866%
#405

push

areyouok
add encoding to fix coverage report

0 of 5353 relevant lines covered (0.0%)

0.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/jetcache-core/src/main/java/com/alicp/jetcache/support/AbstractJsonDecoder.java
1
/**
2
 * Created on 2022/07/27.
3
 */
4
package com.alicp.jetcache.support;
5

6
import com.alicp.jetcache.CacheValueHolder;
7

8
import java.nio.charset.StandardCharsets;
9

10
/**
11
 * @author huangli
12
 */
13
public abstract class AbstractJsonDecoder extends AbstractValueDecoder {
14

15
    public AbstractJsonDecoder(boolean useIdentityNumber) {
16
        super(useIdentityNumber);
×
17
    }
×
18

19
    @Override
20
    protected Object doApply(byte[] buffer) throws Exception {
21
        int[] indexHolder = new int[1];
×
22
        indexHolder[0] = isUseIdentityNumber() ? 4 : 0;
×
23
        short objCount = readShort(buffer, indexHolder[0]);
×
24
        indexHolder[0] = indexHolder[0] + 2;
×
25
        if (objCount < 0) {
×
26
            return null;
×
27
        }
28
        Object obj = readObject(buffer, indexHolder);
×
29
        if (obj == null) {
×
30
            return null;
×
31
        }
32
        if (obj instanceof CacheValueHolder) {
×
33
            CacheValueHolder h = (CacheValueHolder) obj;
×
34
            h.setValue(readObject(buffer, indexHolder));
×
35
            return h;
×
36
        } else if (obj instanceof CacheMessage) {
×
37
            CacheMessage cm = (CacheMessage) obj;
×
38
            if (objCount > 1) {
×
39
                Object[] keys = new Object[objCount - 1];
×
40
                for (int i = 0; i < objCount - 1; i++) {
×
41
                    keys[i] = readObject(buffer, indexHolder);
×
42
                }
43
                cm.setKeys(keys);
×
44
            }
45
            return cm;
×
46
        } else {
47
            return obj;
×
48
        }
49
    }
50

51
    private int readInt(byte[] buf, int index) {
52
        int x = buf[index] & 0xFF;
×
53
        x = (x << 8) | (buf[index + 1] & 0xFF);
×
54
        x = (x << 8) | (buf[index + 2] & 0xFF);
×
55
        x = (x << 8) | (buf[index + 3] & 0xFF);
×
56
        return x;
×
57
    }
58

59
    private short readShort(byte[] buf, int index) {
60
        int x = buf[index] & 0xFF;
×
61
        x = (x << 8) | (buf[index + 1] & 0xFF);
×
62
        return (short) x;
×
63
    }
64

65
    private Object readObject(byte[] buf, int[] indexHolder) throws Exception {
66
        int index = indexHolder[0];
×
67
        short classNameLen = readShort(buf, index);
×
68
        index += 2;
×
69
        if (classNameLen < 0) {
×
70
            indexHolder[0] = index;
×
71
            return null;
×
72
        } else {
73
            String className = new String(buf, index, classNameLen, StandardCharsets.UTF_8);
×
74
            index += classNameLen;
×
75
            Class<?> clazz = Class.forName(className);
×
76
            int size = readInt(buf, index);
×
77
            index += 4;
×
78
            Object obj = parseObject(buf, index, size, clazz);
×
79
            index += size;
×
80
            indexHolder[0] = index;
×
81
            return obj;
×
82
        }
83
    }
84

85
    protected abstract Object parseObject(byte[] buffer, int index, int len, Class clazz);
86
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc