//2021.01.19 cwj protected internal BasicStringVector(DATA_FORM df, ExtendedDataInput @in, bool symbol, bool blob) : base(df) { isBlob = blob; isSymbol = symbol; int rows = @in.readInt(); int columns = @in.readInt(); int size = rows * columns; values = new List <string>(size); values.AddRange(new string[size]); if (!blob) { for (int i = 0; i < size; ++i) { values[i] = @in.readString(); } } else { for (int i = 0; i < size; ++i) { values[i] = @in.readBlob(); } } }
public BasicChunkMeta(ExtendedDataInput @in) { @in.readShort(); //skip the length of the data path = @in.readString(); id = new sbyte[16]; @in.readFully(id); version = @in.readInt(); size_Renamed = @in.readInt(); flag = @in.readByte(); sites = new List <>(); int copyCount = @in.readByte(); for (int i = 0; i < copyCount; ++i) { sites.Add(@in.readString()); } }
public BasicSystemEntity(ExtendedDataInput @in, DATA_TYPE type) : base("") { this.type = type; if (type == DATA_TYPE.DT_FUNCTIONDEF) { @in.readByte(); } base.setValue(@in.readString()); }
public SymbolBase(int id, ExtendedDataInput @in) { this.id = id; int size = @in.readInt(); for (int i = 0; i < size; ++i) { syms.Add(@in.readString()); } }
protected internal override void readMatrixFromInputStream(int rows, int columns, ExtendedDataInput @in) { int size = rows * columns; values = new string[size]; for (int i = 0; i < size; ++i) { values[i] = @in.readString(); } }
//2021.01.19 cwj public BasicString(ExtendedDataInput @in, bool blob) { if (blob) { value = @in.readBlob(); } else { value = @in.readString(); } }
protected internal BasicStringVector(DATA_FORM df, ExtendedDataInput @in) : base(df) { int rows = @in.readInt(); int columns = @in.readInt(); int size = rows * columns; values = new string[size]; for (int i = 0; i < size; ++i) { values[i] = @in.readString(); } }
public BasicTable(ExtendedDataInput @in) { int rows = @in.readInt(); int cols = @in.readInt(); _tableName = @in.readString(); //read column names for (int i = 0; i < cols; ++i) { string name = @in.readString(); name2index_[name] = name2index_.Count; names_.Add(name); } BasicEntityFactory factory = new BasicEntityFactory(); //read columns for (int i = 0; i < cols; ++i) { short flag = @in.readShort(); int form = flag >> 8; int type = flag & 0xff; DATA_FORM df = (DATA_FORM)form; DATA_TYPE dt = (DATA_TYPE)type; if (df != DATA_FORM.DF_VECTOR) { throw new IOException("Invalid form for column [" + names_[i] + "] for table " + _tableName); } Console.WriteLine("vector create " + i + ":" + DateTime.Now); IVector vector = (IVector)factory.createEntity(df, dt, @in); Console.WriteLine("vector end create " + i + ":" + DateTime.Now); if (vector.rows() != rows && vector.rows() != 1) { throw new IOException("The number of rows for column " + names_[i] + " is not consistent with other columns"); } columns_.Add(vector); } }
public BasicString(ExtendedDataInput @in) { value = @in.readString(); }
public virtual IEntity run(string script, ProgressListener listener) { lock (threadLock) { bool reconnect = false; if (socket == null || !socket.Connected) { if (sessionID.Length == 0) { throw new IOException("Database connection is not established yet."); } else { socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); socket.Connect(hostName, port); @out = new LittleEndianDataOutputStream(new BufferedStream(new NetworkStream(socket))); } } string body = "script\n" + script; ExtendedDataInput @in = null; string header = null; try { @out.writeBytes((listener != null ? "API2 " : "API ") + sessionID + " "); @out.writeBytes(AbstractExtendedDataOutputStream.getUTFlength(body, 0, 0).ToString()); @out.writeByte('\n'); @out.writeBytes(body); @out.flush(); @in = remoteLittleEndian ? (ExtendedDataInput) new LittleEndianDataInputStream(new BufferedStream(new NetworkStream(socket))) : (ExtendedDataInput) new BigEndianDataInputStream(new BufferedStream(new NetworkStream(socket))); header = @in.readLine(); } catch (IOException ex) { if (reconnect) { socket = null; throw ex; } try { tryReconnect(); @out.writeBytes((listener != null ? "API2 " : "API ") + sessionID + " "); @out.writeBytes(AbstractExtendedDataOutputStream.getUTFlength(body, 0, 0).ToString()); @out.writeByte('\n'); @out.writeBytes(body); @out.flush(); @in = remoteLittleEndian ? (ExtendedDataInput) new LittleEndianDataInputStream(new BufferedStream(new NetworkStream(socket))) : (ExtendedDataInput) new BigEndianDataInputStream(new BufferedStream(new NetworkStream(socket))); header = @in.readLine(); reconnect = true; } catch (Exception e) { socket = null; throw e; } } string msg; while (header.Equals("MSG")) { //read intermediate message to indicate the progress msg = @in.readString(); if (listener != null) { listener.progress(msg); } header = @in.readLine(); } string[] headers = header.Split(' '); if (headers.Length != 3) { socket = null; throw new IOException("Received invalid header: " + header); } if (reconnect) { sessionID = headers[0]; if (this.userId.Length > 0 && this.password.Length > 0) { login(); } if (this.initialScript != "") { run(initialScript); } } int numObject = int.Parse(headers[1]); msg = @in.readLine(); if (!msg.Equals("OK")) { throw new IOException(msg); } if (numObject == 0) { return(new data.Void()); } try { short flag = @in.readShort(); int form = flag >> 8; int type = flag & 0xff; if (form < 0 || form > MAX_FORM_VALUE) { throw new IOException("Invalid form value: " + form); } if (type < 0 || type > MAX_TYPE_VALUE) { throw new IOException("Invalid type value: " + type); } DATA_FORM df = (DATA_FORM)Enum.GetValues(typeof(DATA_FORM)).GetValue(form); DATA_TYPE dt = (DATA_TYPE)Enum.GetValues(typeof(DATA_TYPE)).GetValue(type); return(factory.createEntity(df, dt, @in)); } catch (IOException ex) { socket = null; throw ex; } } }
public BasicTable(ExtendedDataInput @in) { int rows = @in.readInt(); int cols = @in.readInt(); _tableName = @in.readString(); //read column names for (int i = 0; i < cols; ++i) { string name = @in.readString(); name2index_[name] = name2index_.Count; names_.Add(name); } BasicEntityFactory factory = new BasicEntityFactory(); VectorDecompressor decompressor = null; SymbolBaseCollection collection = null; //read columns for (int i = 0; i < cols; ++i) { short flag = @in.readShort(); int form = flag >> 8; int type = flag & 0xff; bool extended = type >= 128; if (type >= 128) { type -= 128; } DATA_FORM df = (DATA_FORM)form; DATA_TYPE dt = (DATA_TYPE)type; if (df != DATA_FORM.DF_VECTOR) { throw new IOException("Invalid form for column [" + names_[i] + "] for table " + _tableName); } IVector vector; if (dt == DATA_TYPE.DT_SYMBOL && extended) { if (collection == null) { collection = new SymbolBaseCollection(); } vector = new BasicSymbolVector(df, @in, collection); } else if (dt == DATA_TYPE.DT_COMPRESS) { if (decompressor == null) { decompressor = new VectorDecompressor(); } vector = decompressor.Decompress(factory, @in, false, true); } else { vector = (IVector)factory.createEntity(df, dt, @in, extended); } if (vector.rows() != rows && vector.rows() != 1) { int tmp = vector.rows(); throw new IOException("The number of rows for column " + names_[i] + " is not consistent with other columns"); } columns_.Add(vector); } }