summaryrefslogtreecommitdiffstats
path: root/container-search/src/main/java/com/yahoo/fs4/FS4Properties.java
blob: 9dec31785c325f0d2f94fc21d873cdc848c96be2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.fs4;

import com.yahoo.text.Utf8;

import java.nio.ByteBuffer;

public class FS4Properties {
    private String name;

    static public class Entry {
        public final String key;
        public final String val;
        public Entry(byte[] k, byte[] v) {
            key = Utf8.toString(k);
            val = Utf8.toString(v);
        }
    };

    private Entry[] entries;

    void decode(ByteBuffer buffer) {
        int nameLen = buffer.getInt();
        byte[] utf8name = new byte[nameLen];
        buffer.get(utf8name);
        this.setName(Utf8.toString(utf8name));

        int n = buffer.getInt();
        setEntries(new Entry[n]);
        for (int j = 0; j < n; j++) {
            int keyLen = buffer.getInt();
            byte[] key = new byte[keyLen];
            buffer.get(key);

            int valLen = buffer.getInt();
            byte[] value = new byte[valLen];
            buffer.get(value);

            getEntries()[j] = new Entry(key, value);
        }
    }

    public Entry[] getEntries() {
        return entries;
    }

    public void setEntries(Entry[] entries) {
        this.entries = entries;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

}