Beispiel #1
0
        public override Object readObj(bool isUnique, BSerializer ser)
        {
            Object obj = null;

            if (ser != null && ser.inlineInstance)
            {
                currentId = 0;
                obj       = ser.read(null, this, header.version);
                return(obj);
            }

            Dictionary <int, Object> idMap = isUnique ? null : this.idMap;

            int id = bbuf.getPointer();

            if (id > 0)
            {
                // Read type and size from stream
                int typeId = bbuf.getTypeId();
                if (typeId < 0)
                {
                    throw new BException(BExceptionC.CORRUPT, "Invalid type ID at stream position " + bbuf.position());
                }

                // If the serializer is not supplied, lookup
                // the serializer from the registry
                if (ser == null)
                {
                    ser = registry.getSerializer(typeId);
                }

                // Create and read
                currentId = id;
                obj       = ser.read(null, this, header.version);
            }
            else if (id < 0)
            {
                if (idMap == null)
                {
                    throw new BException(BExceptionC.INTERNAL, "Reference map must not be null.");
                }

                if (!idMap.TryGetValue(-id, out obj))
                {
                    string errorMessage    = "Corrupt read buffer at position=" + (bbuf.position() - 4) + ", expected reference to existing object, reference-id=" + id;
                    string messageAsString = bbuf.toDetailString();
                    string fileName        = System.IO.Path.GetTempPath() + "eloixclientcs-error.txt";
                    System.IO.File.WriteAllText(fileName, errorMessage + "\r\n" + messageAsString);
                    Console.WriteLine();
                    Console.WriteLine(messageAsString);
                    throw new BException(BExceptionC.INTERNAL, "Corrupt read buffer at position " + (bbuf.position() - 4) + ".");
                }
            }
            else
            {
                // NULL reference
            }

            return(obj);
        }
Beispiel #2
0
        public override Object readObj(bool isUnique, BSerializer ser)
        {
            Object obj = null;

            if (ser != null && ser.inlineInstance)
            {
                currentId = 0;
                obj       = ser.read(null, this, header.version);
                return(obj);
            }

            Dictionary <int, Object> idMap = isUnique ? null : this.idMap;

            int id = bbuf.getPointer();

            if (id > 0)
            {
                // Read type and size from stream
                int typeId = bbuf.getTypeId();
                if (typeId < 0)
                {
                    throw new BException(BExceptionC.CORRUPT, "Invalid type ID at stream position " + bbuf.position());
                }

                // If the serializer is not supplied, lookup
                // the serializer from the registry
                if (ser == null)
                {
                    ser = registry.getSerializer(typeId);
                }

                // Create and read
                currentId = id;
                obj       = ser.read(null, this, header.version);
            }
            else if (id < 0)
            {
                if (idMap == null)
                {
                    throw new BException(BExceptionC.INTERNAL, "Reference map must not be null.");
                }
                if (!idMap.TryGetValue(-id, out obj))
                {
                    throw new BException(BExceptionC.INTERNAL, "Null values must not be mapped.");
                }
            }
            else
            {
                // NULL reference
            }

            return(obj);
        }
Beispiel #3
0
	    public override Object readObj(bool isUnique, BSerializer ser) {
		    Object obj = null;
		
		    if (ser != null && ser.inlineInstance) {
                currentId = 0;
			    obj = ser.read(null, this, header.version);
			    return obj;
		    }

		    Dictionary<int, Object> idMap = isUnique ? null : this.idMap;
		
		    int id = bbuf.getPointer();
		    if (id > 0) {
			
			    // Read type and size from stream
			    int typeId = bbuf.getTypeId();
			    if (typeId < 0) throw new BException(BExceptionC.CORRUPT, "Invalid type ID at stream position " + bbuf.position());
			
			    // If the serializer is not supplied, lookup
			    // the serializer from the registry
			    if (ser == null) {
				    ser = registry.getSerializer(typeId);
			    }
			
			    // Create and read
                currentId = id;
			    obj = ser.read(null, this, header.version);
			
		    }
		    else if (id < 0) {
			    if (idMap == null) throw new BException(BExceptionC.INTERNAL, "Reference map must not be null.");
			    if (!idMap.TryGetValue(-id, out obj)) throw new BException(BExceptionC.INTERNAL, "Null values must not be mapped.");
		    }
		    else {
			    // NULL reference
		    }
		
		    return obj;

	    }
Beispiel #4
0
        public override void writeObj(object obj, bool isUnique, BSerializer ser)
        {
            if (ser != null && ser.inlineInstance)
            {
                // Inline objects must not be null
                if (obj == null)
                {
                    obj = ser.read(null, null, 0);
                }

                ser.write(obj, this, header.version);
                return;
            }

            if (obj != null)
            {
                BObjMap objMap = isUnique ? null : this.objMap;

                int id_o = objMap != null?objMap.get(obj) : 0;

                if (id_o != 0)
                {
                    bbuf.putPointer(-id_o);
                }
                else
                {
                    id_o = ++nextObjId;

                    bbuf.putPointer(nextObjId);

                    if (objMap != null)
                    {
                        objMap.put(obj, id_o);
                    }

                    if (ser == null)
                    {
                        ser = registry.getSerializer(obj, true);
                    }

                    bbuf.putTypeId(ser.typeId);

                    ser.write(obj, this, header.version);
                }
            }
            else
            {
                // NULL-Referenz
                bbuf.putPointer(0);
            }
        }
Beispiel #5
0
        public override void writeObj(object obj, bool isUnique, BSerializer ser)
        {
            if (ser != null && ser.inlineInstance)
            {

                // Inline objects must not be null
                if (obj == null)
                {
                    obj = ser.read(null, null, 0);
                }

                ser.write(obj, this, header.version);
                return;
            }

            if (obj != null)
            {

                BObjMap objMap = isUnique ? null : this.objMap;

                int id_o = objMap != null ? objMap.get(obj) : 0;
                if (id_o != 0)
                {
                    bbuf.putPointer(-id_o);
                }
                else
                {
                    id_o = ++nextObjId;

                    bbuf.putPointer(nextObjId);

                    if (objMap != null) objMap.put(obj, id_o);

                    if (ser == null)
                    {
                        ser = registry.getSerializer(obj, true);
                    }

                    bbuf.putTypeId(ser.typeId);

                    ser.write(obj, this, header.version);
                }
            }
            else
            {
                // NULL-Referenz
                bbuf.putPointer(0);
            }
        }