public static void FromBytes(byte[] buf, int byteCount, bool replaceCache) { if (byteCount > 4) { int varsCount = Entry.BytesToInt(buf, 0); if (varsCount > 0) { int offset = 4; for (; ;) { string key = null; string value = null; offset += DGlobals.BytesToKeyValue(buf, offset, ref key, ref value); DGlobals._add(key, value); if (offset >= byteCount) { break; } } if (replaceCache) { sbuf = Convert.ToBase64String(buf, 0, byteCount); } return; } } if (replaceCache) { sbuf = null; } }
public Int32 GetInt32() { int x = Entry.BytesToInt(Buffer, CurrentGetPos); CurrentGetPos += 4; return(x); }
public override void Reduce(ByteSlice key, RandomAccessEntries values, RandomAccessOutput output) { // Value to string and trim spaces. for (int i = 0; i != values.Length; i++) { lbuf.Clear(); values[i].Value.AppendTo(lbuf); string str = Entry.BytesToAscii(lbuf); str = str.Trim(); lbuf.Clear(); Entry.AsciiToBytesAppend(str, lbuf); output.Add(key, ByteSlice.Create(lbuf, 0, lbuf.Count)); } // First 4 bytes of value to integer and increment. for (int i = 0; i != values.Length; i++) { lbuf.Clear(); for (int bi = 0; bi != 4; bi++) { lbuf.Add(values[i].Value[bi]); } int x = Entry.BytesToInt(lbuf); x++; lbuf.Clear(); Entry.ToBytesAppend(x, lbuf); output.Add(key, ByteSlice.Create(lbuf)); } }
internal static int BytesToKeyValue(byte[] buf, int offset, ref string key, ref string value) { int keyLen = Entry.BytesToInt(buf, offset); int valueLen = Entry.BytesToInt(buf, offset + 4); key = System.Text.Encoding.Unicode.GetString(buf, offset + 8, keyLen); value = null; if (valueLen > 0) { value = System.Text.Encoding.Unicode.GetString(buf, offset + 8 + keyLen, valueLen); } else if (valueLen == 0) { value = ""; } return(4 + 4 + keyLen + (valueLen > 0 ? valueLen : 0)); }
public override void OnRemote(IEnumerator <ByteSlice> input, System.IO.Stream output) { string TableName = DSpace_ExecArgs[0]; string DfsOutputName = DSpace_ExecArgs[1]; // Actually the input of this job. string RowInfo = Qa.QlArgsUnescape(DSpace_ExecArgs[2]); string DisplayInfo = DSpace_ExecArgs[3]; long TopCount = long.Parse(DSpace_ExecArgs[4]); string sOptions = (DSpace_ExecArgs.Length > 5) ? DSpace_ExecArgs[5] : ""; bool joined = -1 != sOptions.IndexOf("JOINED"); InitColInfos(RowInfo, DisplayInfo); StringBuilder sb = new StringBuilder(); sb.Length = 0; bool ShouldCleanName = !joined; foreach (ColInfo ci in cols) { string name = ci.Name; if (ShouldCleanName) { name = CleanColumnName(ci.Name); } sb.AppendFormat("{0,-" + ci.DisplayWidth.ToString() + "} ", name); } string hsep = new string('-', sb.Length); DSpace_Log(sb.ToString()); DSpace_Log(hsep); for (ByteSlice rowbuf; (TopCount == -1 || TopCount > 0) && input.MoveNext(); ) { rowbuf = input.Current; sb.Length = 0; foreach (ColInfo ci in cols) { ByteSlice cval = ByteSlice.Prepare(rowbuf, ci.StartOffset, ci.Size); if (0 != cval[0]) { sb.AppendFormat("{0,-" + ci.DisplayWidth.ToString() + "} ", "NULL"); } else { if (ci.Type.StartsWith("char")) { string charsvalue = System.Text.Encoding.Unicode.GetString(ByteSlice.Prepare(cval, 1, cval.Length - 1).ToBytes()); charsvalue = charsvalue.TrimEnd('\0'); sb.AppendFormat("{0,-" + ci.DisplayWidth.ToString() + "} ", charsvalue); } else if ("int" == ci.Type) { Int32 x = Entry.BytesToInt(ByteSlice.Prepare(cval, 1, cval.Length - 1).ToBytes()); x = Entry.ToInt32((UInt32)x); sb.AppendFormat("{0,-" + ci.DisplayWidth.ToString() + "} ", x); } else if ("long" == ci.Type) { Int64 x = Entry.BytesToLong(ByteSlice.Prepare(cval, 1, cval.Length - 1).ToBytes()); x = Entry.ToInt64((UInt64)x); sb.AppendFormat("{0,-" + ci.DisplayWidth.ToString() + "} ", x); } else if ("double" == ci.Type) { recordset rs = recordset.Prepare(ByteSlice.Prepare(cval, 1, cval.Length - 1)); double x = rs.GetDouble(); sb.AppendFormat("{0,-" + ci.DisplayWidth.ToString() + "} ", x); } else if ("DateTime" == ci.Type) { Int64 x = Entry.BytesToLong(ByteSlice.Prepare(cval, 1, cval.Length - 1).ToBytes()); DateTime dt = new DateTime(x); sb.AppendFormat("{0,-" + ci.DisplayWidth.ToString() + "} ", dt); } else { sb.AppendFormat("{0,-" + ci.DisplayWidth.ToString() + "} ", "?"); // Not supported yet. } } } DSpace_Log(sb.ToString()); if (TopCount != -1) { TopCount--; } } DSpace_Log(hsep); }
protected override void ProcessCommand(System.Net.Sockets.NetworkStream nstm, char tag) { int len; switch (tag) { case 'R': // Remote! { string classname = XContent.ReceiveXString(nstm, buf); string xlibfn = CreateXlibFileName("remote"); { buf = XContent.ReceiveXBytes(nstm, out len, buf); if (0 != len) { System.IO.FileStream stm = System.IO.File.Create(xlibfn); stm.Write(buf, 0, len); stm.Close(); } } string dllfn = CreateDllFileName("remote"); { buf = XContent.ReceiveXBytes(nstm, out len, buf); System.IO.FileStream stm = System.IO.File.Create(dllfn); stm.Write(buf, 0, len); stm.Close(); } if (XLog.logging) { string xclassname = classname; if (null == xclassname) { xclassname = "<null>"; } XLog.log("Loading IRemote plugin named " + xclassname + " for remote: " + dllfn); } rem = LoadRemotePlugin(dllfn, classname); #if DEBUG try { rem.OnRemote(); } catch (Exception e) { throw new UserException(e); } #else rem.OnRemote(); #endif } break; case 'O': //Query DGlobals { int byteCount = DGlobalsM.ToBytes(ref buf); XContent.SendXContent(nstm, buf, byteCount); } break; case 'r': { buf = XContent.ReceiveXBytes(nstm, out len, buf); int n = Entry.BytesToInt(buf); int count = 0; if (null != rem) { List <long> appendsizes = new List <long>(); try { count = rem.GetOutputFileCount(n, appendsizes); } catch (Exception e) { throw new DistributedObjectsSlave.DistObjectAbortException(e); } if (buf.Length < 4 + 8 * appendsizes.Count) { buf = new byte[Entry.Round2Power(4 + 8 * appendsizes.Count)]; } Entry.ToBytes(count, buf, 0); int offset = 4; for (int i = 0; i < appendsizes.Count; i++, offset += 8) { Entry.LongToBytes(appendsizes[i], buf, offset); } XContent.SendXContent(nstm, buf, 4 + 8 * appendsizes.Count); break; // ! } Entry.ToBytes(count, buf, 0); XContent.SendXContent(nstm, buf, 4); } break; default: base.ProcessCommand(nstm, tag); break; } }