1/*-
2 * See the file LICENSE for redistribution information.
3 *
4 * Copyright (c) 2002,2008 Oracle.  All rights reserved.
5 *
6 * $Id: TestDataBinding.java,v 12.6 2008/01/08 20:58:57 bostic Exp $
7 */
8
9package com.sleepycat.collections.test;
10
11import com.sleepycat.bind.EntryBinding;
12import com.sleepycat.db.DatabaseEntry;
13
14/**
15 * @author Mark Hayes
16 */
17class TestDataBinding implements EntryBinding {
18
19    public Object entryToObject(DatabaseEntry data) {
20
21        if (data.getSize() != 1) {
22            throw new IllegalStateException("size=" + data.getSize());
23        }
24        byte val = data.getData()[data.getOffset()];
25        return new Long(val);
26    }
27
28    public void objectToEntry(Object object, DatabaseEntry data) {
29
30        byte val = ((Number) object).byteValue();
31        data.setData(new byte[] { val }, 0, 1);
32    }
33}
34