001: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
002:
003: This file is part of the db4o open source object database.
004:
005: db4o is free software; you can redistribute it and/or modify it under
006: the terms of version 2 of the GNU General Public License as published
007: by the Free Software Foundation and as clarified by db4objects' GPL
008: interpretation policy, available at
009: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
010: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
011: Suite 350, San Mateo, CA 94403, USA.
012:
013: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
014: WARRANTY; without even the implied warranty of MERCHANTABILITY or
015: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
016: for more details.
017:
018: You should have received a copy of the GNU General Public License along
019: with this program; if not, write to the Free Software Foundation, Inc.,
020: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
021: package com.db4o.internal.marshall;
022:
023: import java.util.Date;
024:
025: import com.db4o.Deploy;
026: import com.db4o.internal.*;
027:
028: public class PrimitiveMarshaller0 extends PrimitiveMarshaller {
029:
030: public boolean useNormalClassRead() {
031: return true;
032: }
033:
034: public Date readDate(Buffer bytes) {
035: final long value = bytes.readLong();
036: if (value == Long.MAX_VALUE) {
037: return MarshallingConstants0.NULL_DATE;
038: }
039: return new Date(value);
040: }
041:
042: public Object readInteger(Buffer bytes) {
043: final int value = bytes.readInt();
044: if (value == Integer.MAX_VALUE) {
045: return null;
046: }
047: return new Integer(value);
048: }
049:
050: public Object readFloat(Buffer bytes) {
051: Float value = unmarshallFloat(bytes);
052: if (value.isNaN()) {
053: return null;
054: }
055: return value;
056: }
057:
058: public Object readDouble(Buffer buffer) {
059: Double value = unmarshalDouble(buffer);
060: if (value.isNaN()) {
061: return null;
062: }
063: return value;
064: }
065:
066: public Object readLong(Buffer buffer) {
067: long value = buffer.readLong();
068: if (value == Long.MAX_VALUE) {
069: return null;
070: }
071: return new Long(value);
072: }
073:
074: public Object readShort(Buffer buffer) {
075: short value = unmarshallShort(buffer);
076: if (value == Short.MAX_VALUE) {
077: return null;
078: }
079: return new Short(value);
080: }
081:
082: public static Double unmarshalDouble(Buffer buffer) {
083: return new Double(Platform4.longToDouble(buffer.readLong()));
084: }
085:
086: public static Float unmarshallFloat(Buffer buffer) {
087: return new Float(Float.intBitsToFloat(buffer.readInt()));
088: }
089:
090: public static short unmarshallShort(Buffer buffer) {
091: int ret = 0;
092: if (Deploy.debug) {
093: buffer.readBegin(Const4.YAPSHORT);
094: }
095: for (int i = 0; i < Const4.SHORT_BYTES; i++) {
096: ret = (ret << 8)
097: + (buffer._buffer[buffer._offset++] & 0xff);
098: }
099: if (Deploy.debug) {
100: buffer.readEnd();
101: }
102: return (short) ret;
103: }
104: }
|