Exemplo n.º 1
0
		public BDB43(string file, string table, bool create, DBFormat format, bool allowDuplicates, Env environment) {
			this.env = environment;
			
			db_create(out dbp, environment.envptr, 0);
			funcs = (dbstruct)Marshal.PtrToStructure((IntPtr)((int)dbp+268), typeof(dbstruct));
			
			uint dbflags = DB_DIRECT_DB;
			if (allowDuplicates)
				dbflags |= DB_DUP; // DB_DUPSORT; 
			
			funcs.set_flags(dbp, dbflags);
			
			int type = (int)format;
			uint flags = DB_DIRTY_READ; // | DB_AUTO_COMMIT;
			int chmod_mode = 0;
			
			if (create)
				flags |= DB_CREATE;
			
			// if file & database are null, db is held in-memory
			// on file is taken as UTF8 (is this call right?)
			int ret = funcs.open(dbp, env.Txn, file, table, type, flags, chmod_mode);
			CheckError(ret);
			
			binfmt = new Serializer();
		}
Exemplo n.º 2
0
			public object GetObject(Serializer binfmt, DataType datatype) {
				if (Size == 0) return null;
	        	if (datatype == DataType.UInt) {
					staticalloc((int)Size);
		        	Marshal.Copy(Ptr, staticdata, 0, (int)Size);
	        		byte[] d = staticdata;
	        		uint val = (uint)d[0] + ((uint)d[1] << 8) + ((uint)d[2] << 16) + ((uint)d[3] << 24);
					return val;
				} else if (datatype == DataType.IntArray) {
					int[] data = new int[(int)Size/4];
		        	Marshal.Copy(Ptr, data, 0, data.Length);
					return data;
				/*} else if (datatype == DataType.String && false) {
					char[] data = new char[(int)Size/2];
		        	Marshal.Copy(Ptr, data, 0, data.Length);
					return new String(data);*/
	        	} else {
					staticalloc((int)Size);
		        	Marshal.Copy(Ptr, staticdata, 0, (int)Size);
	        		return binfmt.Deserialize(staticdata);
	        	}
			}
Exemplo n.º 3
0
	        public static Data New(object data, Serializer binfmt, DataType datatype) {
				Data ret = new Data();

       			if (data == null) {
					ret.Ptr = IntPtr.Zero;
					ret.Size = 0;
				} else if (datatype == DataType.UInt) {
					staticalloc(4);
					uint value = (uint)data;
					byte[] d = staticdata;
					d[0] = (byte)((value) & 0xFF);
					d[1] = (byte)((value >> 8) & 0xFF);
					d[2] = (byte)((value >> 16) & 0xFF);
					d[3] = (byte)((value >> 24) & 0xFF);
					ret.Ptr = BytesToAlloc(d, 4, 1);
					ret.Size = (uint)4;
				} else if (datatype == DataType.IntArray) {
					int[] values = (int[])data;
					ret.Size = (uint)(4*values.Length);
					ret.Ptr = BytesToAlloc(values, values.Length, 4);
				/*} else if (datatype == DataType.String && false) {
					// Somehow this is slower than the below path.
					char[] values = ((string)data).ToCharArray();
					ret.Size = (uint)(2*values.Length);
					ret.Ptr = BytesToAlloc(values, values.Length, 2);*/
       			} else {
       				MemoryStream binary = binfmt.Serialize(data);
		       		if (binary.Length > uint.MaxValue)
		       			throw new ArgumentException("data is too large");
					ret.Ptr = BytesToAlloc(binary.GetBuffer(), (int)binary.Length, 1);
					ret.Size = (uint)binary.Length;
				}
				return ret;
			}