1 21 package com.db4o.cs.messages; 22 23 import com.db4o.*; 24 25 26 public class MsgObject extends MsgD { 27 28 private static final int LENGTH_FOR_ALL = YapConst.ID_LENGTH + (YapConst.INT_LENGTH * 3); 29 private static final int LENGTH_FOR_FIRST = LENGTH_FOR_ALL; 30 31 private int _id; 32 private int _address; 33 34 MsgD getWriter(YapWriter bytes, int[] prependInts) { 35 int lengthNeeded = bytes.getLength() + LENGTH_FOR_FIRST; 36 if(prependInts != null){ 37 lengthNeeded += (prependInts.length * YapConst.INT_LENGTH); 38 } 39 int embeddedCount = bytes.embeddedCount(); 40 if(embeddedCount > 0){ 41 lengthNeeded += (LENGTH_FOR_ALL * embeddedCount) + bytes.embeddedLength(); 42 } 43 MsgD message = getWriterForLength(bytes.getTransaction(), lengthNeeded); 44 if(prependInts != null){ 45 for (int i = 0; i < prependInts.length; i++) { 46 message._payLoad.writeInt(prependInts[i]); 47 } 48 } 49 message._payLoad.writeInt(embeddedCount); 50 bytes.appendTo(message._payLoad, -1); 51 return message; 52 } 53 54 public MsgD getWriter(YapWriter bytes) { 55 return getWriter(bytes, null); 56 } 57 58 public MsgD getWriter(YapClass a_yapClass, YapWriter bytes) { 59 if(a_yapClass == null){ 60 return getWriter(bytes, new int[]{0}); 61 } 62 return getWriter(bytes, new int[]{ a_yapClass.getID()}); 63 } 64 65 public MsgD getWriter(YapClass a_yapClass, int a_param, YapWriter bytes) { 66 return getWriter(bytes, new int[]{ a_yapClass.getID(), a_param}); 67 } 68 69 public final YapWriter unmarshall() { 70 return unmarshall(0); 71 } 72 73 public final YapWriter unmarshall(int addLengthBeforeFirst) { 74 _payLoad.setTransaction(transaction()); 75 int embeddedCount = _payLoad.readInt(); 76 int length = _payLoad.readInt(); 77 if (length == 0) { 78 return null; } 80 _id = _payLoad.readInt(); 81 _address = _payLoad.readInt(); 82 if(embeddedCount == 0){ 83 _payLoad.removeFirstBytes(LENGTH_FOR_FIRST + addLengthBeforeFirst); 84 }else{ 85 _payLoad._offset += length; 86 YapWriter[] embedded = new YapWriter[embeddedCount + 1]; 87 embedded[0] = _payLoad; 88 new YapWriter(_payLoad, embedded, 1); _payLoad.trim4(LENGTH_FOR_FIRST + addLengthBeforeFirst, length); 90 } 91 _payLoad.useSlot(_id, _address, length); 92 return _payLoad; 93 } 94 95 public void payLoad(YapWriter writer) { 96 _payLoad = writer; 97 } 98 99 public int getId() { 100 return _id; 101 } 102 } 103 | Popular Tags |