public unsafe int WriteValue(string str, out BlittableJsonToken token, UsageMode mode = UsageMode.None) { if (_intBuffer == null) { _intBuffer = new FastList <int>(); } var escapePositionsMaxSize = JsonParserState.FindEscapePositionsMaxSize(str); int size = Encodings.Utf8.GetMaxByteCount(str.Length) + escapePositionsMaxSize; AllocatedMemoryData buffer = null; try { buffer = _context.GetMemory(size); fixed(char *pChars = str) { var stringSize = Encodings.Utf8.GetBytes(pChars, str.Length, buffer.Address, size); JsonParserState.FindEscapePositionsIn(_intBuffer, buffer.Address, stringSize, escapePositionsMaxSize); return(WriteValue(buffer.Address, stringSize, _intBuffer, out token, mode, null)); } } finally { if (buffer != null) { _context.ReturnMemory(buffer); } } }
public void Renew(string debugTag, UsageMode mode) { Reset(); _debugTag = debugTag; _mode = mode; _writer.Renew(); }
public void Reset() { _debugTag = null; _mode = UsageMode.None; _continuationState.Clear(); _writeToken = default(WriteToken); _writer.Reset(); }
public BlittableJsonDocumentBuilder( JsonOperationContext context, UsageMode mode, string debugTag, IJsonParser reader, JsonParserState state, BlittableWriter <UnmanagedWriteBuffer> writer = null, IBlittableDocumentModifier modifier = null) : this(context, state, reader, writer, modifier) { Renew(debugTag, mode); }
/// <summary> /// Allows incrementally building json document /// </summary> /// <param name="context"></param> /// <param name="mode"></param> /// <param name="writer"></param> public ManualBlittableJsonDocumentBuilder( JsonOperationContext context, UsageMode?mode = null, BlittableWriter <TWriter> writer = null) { _context = context; _mode = mode ?? UsageMode.None; _writer = writer ?? new BlittableWriter <TWriter>(_context); }
public BlittableJsonDocumentBuilder(JsonOperationContext context, UsageMode mode, string debugTag, IJsonParser reader, JsonParserState state) { _reader = reader; _debugTag = debugTag; _stream = context.GetStream(); _context = context; _mode = mode; _state = state; }
public void Renew(string debugTag, UsageMode mode) { Reset(); _debugTag = debugTag; _mode = mode; _writer.ResetAndRenew(); _modifier?.Reset(_context); _fakeFieldName = _context.GetLazyStringForFieldWithCaching(UnderscoreSegment); }
public void Reset() { _debugTag = null; _mode = UsageMode.None; ClearState(); _writeToken = default; _writer.Reset(); }
public void Renew(string debugTag, UsageMode mode) { _writeToken = default(WriteToken); _debugTag = debugTag; _mode = mode; _continuationState.Clear(); _cacheItem.Reset(); _writer.ResetAndRenew(); _modifier?.Reset(_context); _fakeFieldName = _context.GetLazyStringForFieldWithCaching(UnderscoreSegment); }
public unsafe int WriteValue(LazyCompressedStringValue str, out BlittableJsonToken token, UsageMode mode) { var startPos = _position; token = BlittableJsonToken.CompressedString; _position += WriteVariableSizeInt(str.UncompressedSize); _position += WriteVariableSizeInt(str.CompressedSize); // compressed size include escape positions _unmanagedWriteBuffer.Write(str.Buffer, str.CompressedSize); _position += str.CompressedSize; return(startPos); }
public unsafe int WriteValue(LazyCompressedStringValue str, out BlittableJsonToken token, UsageMode mode) { var startPos = _position; token = BlittableJsonToken.CompressedString; _position += WriteVariableSizeInt(str.UncompressedSize); _position += WriteVariableSizeInt(str.CompressedSize); var escapeSequencePos = GetSizeIncludingEscapeSequences(str.Buffer, str.CompressedSize); _unmanagedWriteBuffer.Write(str.Buffer, escapeSequencePos); _position += escapeSequencePos; return(startPos); }
public unsafe int WriteValue(string str, out BlittableJsonToken token, UsageMode mode = UsageMode.None) { if (_intBuffer == null) { _intBuffer = new List <int>(); } int size = Encoding.UTF8.GetMaxByteCount(str.Length); FillBufferWithEscapePositions(str, _intBuffer); size += JsonParserState.GetEscapePositionsSize(_intBuffer); var buffer = _context.GetNativeTempBuffer(size); fixed(char *pChars = str) { var stringSize = Utf8Encoding.GetBytes(pChars, str.Length, buffer, size); return(WriteValue(buffer, stringSize, _intBuffer, out token, mode, null)); } }
internal IEnumerable<string> Visit(UsageMode usageMode, GeoDirectionsRequest request) { _result = new List<string>(); _usageMode = usageMode; _request = request; // Visit all of the request properties and determine if the parameter is valid within the context of the call. VistRequiredParameters(); VisitMode(); VisitWaypoints(); VisitAlternatives(); VisitRouteRestrictions(); VisitLanguage(); VisitUnits(); VisitRegion(); VisitDepartureTime(); VisitArrivalTime(); VisitTransitMode(); VisitTransitRoutingPreference(); return _result; }
public unsafe int WriteValue(LazyStringValue str, out BlittableJsonToken token, UsageMode mode, int?initialCompressedSize) { if (str.EscapePositions != null) { return(WriteValue(str.Buffer, str.Size, str.EscapePositions, out token, mode, initialCompressedSize)); } // else this is a raw value var startPos = _position; token = BlittableJsonToken.String; _position += WriteVariableSizeInt(str.Size); var escapeSequencePos = GetSizeIncludingEscapeSequences(str.Buffer, str.Size); _unmanagedWriteBuffer.Write(str.Buffer, escapeSequencePos); _position += escapeSequencePos; return(startPos); }
public GeoDirectionsClient() { _mode = UsageMode.Free; }
public GeoDirectionsClient(string clientKey) { _clientKey = clientKey; _mode = UsageMode.ClientKey; }
public unsafe int WriteValue(LazyStringValue str, out BlittableJsonToken token, UsageMode mode, int?initialCompressedSize) { return(WriteValue(str.Buffer, str.Size, str.EscapePositions, out token, mode, initialCompressedSize)); }
/// <summary> /// Initialize GeocodeClient with your Google API key to utilize it in the requests to Google and bypass the default annonymous throttling. /// </summary> /// <param name="apiKey">Google Maps API Key</param> public GeocodeClient(string apiKey) { _clientKey = apiKey; _mode = UsageMode.ClientKey; }
/// <summary> /// Initialize GeocodeClient with your Google API key to utilize it in the requests to Google and bypass the default annonymous throttling. /// </summary> /// <param name="clientId">The client ID. Applicable when using Maps API for Work.</param> /// <param name="cryptoKey">The base64 encoded crypto key. Applicable when using Maps API for Work.</param> /// <remarks> /// See - https://developers.google.com/maps/documentation/business/webservices/#client_id /// </remarks> public GeocodeClient(string clientId, string cryptoKey) { _clientId = clientId; _cryptoKey = cryptoKey; _mode = UsageMode.ApiForWork; }
public void Reset(UsageMode mode) { _mode = mode; _writer.ResetAndRenew(); }
public unsafe int WriteValue(byte *buffer, int size, int[] escapePositions, out BlittableJsonToken token, UsageMode mode, int?initialCompressedSize) { var startPos = _position; token = BlittableJsonToken.String; _position += WriteVariableSizeInt(size); // if we are more than this size, we want to abort the compression early and just use // the verbatim string int maxGoodCompressionSize = size - sizeof(int) * 2; if (maxGoodCompressionSize > 0) { size = TryCompressValue(ref buffer, ref _position, size, ref token, mode, initialCompressedSize, maxGoodCompressionSize); } _unmanagedWriteBuffer.Write(buffer, size); _position += size; if (escapePositions == null) { _position += WriteVariableSizeInt(0); return(startPos); } // we write the number of the escape sequences required // and then we write the distance to the _next_ escape sequence _position += WriteVariableSizeInt(escapePositions.Length); // PERF: Use indexer to avoid the allocation and overhead of the foreach. int count = escapePositions.Length; for (int i = 0; i < count; i++) { _position += WriteVariableSizeInt(escapePositions[i]); } return(startPos); }
public unsafe int WriteValue(byte *buffer, int size, ICollection <int> escapePositions, out BlittableJsonToken token, UsageMode mode, int?initialCompressedSize) { var startPos = _position; token = BlittableJsonToken.String; _position += WriteVariableSizeInt(size); var maxGoodCompressionSize = // if we are more than this size, we want to abort the compression early and just use // the verbatim string size - sizeof(int) * 2; var shouldCompress = initialCompressedSize.HasValue || (((mode & UsageMode.CompressStrings) == UsageMode.CompressStrings) && (size > 128)) || ((mode & UsageMode.CompressSmallStrings) == UsageMode.CompressSmallStrings) && (size <= 128); if (maxGoodCompressionSize > 0 && shouldCompress) { int compressedSize; byte *compressionBuffer; if (initialCompressedSize.HasValue) { // we already have compressed data here compressedSize = initialCompressedSize.Value; compressionBuffer = buffer; } else { compressionBuffer = CompressBuffer(buffer, size, maxGoodCompressionSize, out compressedSize); } if (compressedSize > 0)// only if we actually save more than space { token = BlittableJsonToken.CompressedString; buffer = compressionBuffer; size = compressedSize; _position += WriteVariableSizeInt(compressedSize); } } _unmanagedWriteBuffer.Write(buffer, size); _position += size; if (escapePositions == null) { _position += WriteVariableSizeInt(0); return(startPos); } // we write the number of the escape sequences required // and then we write the distance to the _next_ escape sequence _position += WriteVariableSizeInt(escapePositions.Count); foreach (int escapePos in escapePositions) { _position += WriteVariableSizeInt(escapePos); } return(startPos); }
public unsafe int WriteString(LazyStringValue str, out BlittableJsonToken token, UsageMode state) { var startPos = _position; token = BlittableJsonToken.String; _position += WriteVariableSizeInt(str.Size); var buffer = str.Buffer; var size = str.Size; var maxGoodCompressionSize = // if we are more than this size, we want to abort the compression early and just use // the verbatim string str.Size - sizeof(int) * 2; var shouldCompress = _state.CompressedSize != null && ((state & UsageMode.CompressStrings) == UsageMode.CompressStrings && size > 128 || (state & UsageMode.CompressSmallStrings) == UsageMode.CompressSmallStrings); if (maxGoodCompressionSize > 0 && shouldCompress) { Compressed++; int compressedSize; byte *compressionBuffer; if (_state.CompressedSize != null) { // we already have compressed data here compressedSize = _state.CompressedSize.Value; compressionBuffer = _state.StringBuffer; } else { compressionBuffer = CompressBuffer(str, maxGoodCompressionSize, out compressedSize); } if (compressedSize > 0)// only if we actually save more than space { token = BlittableJsonToken.CompressedString; buffer = compressionBuffer; size = compressedSize; _position += WriteVariableSizeInt(compressedSize); } else { DiscardedCompressions++; } } _stream.Write(buffer, size); _position += size; return(startPos); }
/// <summary> /// Initialize GeocodeClient without a Google API key and use default annonymouse access. /// NOTE: Throttling may apply. /// </summary> public GeocodeClient() { _mode = UsageMode.Free; }
/// <summary> /// For creating at the Molecule level (create molecule and first transition group) or modifying at the transition level /// Null values imply "don't ask user for this" /// </summary> public EditCustomMoleculeDlg(SkylineWindow parent, UsageMode usageMode, string title, Identity initialId, IEnumerable <Identity> existingIds, int minCharge, int maxCharge, SrmSettings settings, CustomMolecule molecule, Adduct defaultCharge, ExplicitTransitionGroupValues explicitTransitionGroupAttributes, ExplicitTransitionValues explicitTransitionAttributes, ExplicitRetentionTimeInfo explicitRetentionTime, IsotopeLabelType defaultIsotopeLabelType) { Text = title; _parent = parent; _initialId = initialId; _existingIds = existingIds; _minCharge = minCharge; _maxCharge = maxCharge; _transitionSettings = settings != null ? settings.TransitionSettings : null; _peptideSettings = settings != null ? settings.PeptideSettings : null; _resultAdduct = Adduct.EMPTY; _resultCustomMolecule = molecule; _usageMode = usageMode; var enableFormulaEditing = usageMode == UsageMode.moleculeNew || usageMode == UsageMode.moleculeEdit || usageMode == UsageMode.fragment; var enableAdductEditing = usageMode == UsageMode.moleculeNew || usageMode == UsageMode.precursor || usageMode == UsageMode.fragment; var suggestOnlyAdductsWithMass = usageMode != UsageMode.fragment; var needExplicitTransitionValues = usageMode == UsageMode.fragment; var needExplicitTransitionGroupValues = usageMode == UsageMode.moleculeNew || usageMode == UsageMode.precursor; InitializeComponent(); NameText = molecule == null ? String.Empty : molecule.Name; textName.Enabled = usageMode == UsageMode.moleculeNew || usageMode == UsageMode.moleculeEdit || usageMode == UsageMode.fragment; // Can user edit name? var needOptionalValuesBox = explicitRetentionTime != null || explicitTransitionGroupAttributes != null || explicitTransitionAttributes != null; if (!needExplicitTransitionValues) { labelCollisionEnergy.Visible = false; textCollisionEnergy.Visible = false; labelSLens.Visible = false; textSLens.Visible = false; labelConeVoltage.Visible = false; textConeVoltage.Visible = false; labelIonMobilityHighEnergyOffset.Visible = false; textIonMobilityHighEnergyOffset.Visible = false; labelDeclusteringPotential.Visible = false; textDeclusteringPotential.Visible = false; } if (!needExplicitTransitionGroupValues) { labelCCS.Visible = false; textBoxCCS.Visible = false; labelIonMobility.Visible = false; textIonMobility.Visible = false; labelIonMobilityUnits.Visible = false; comboBoxIonMobilityUnits.Visible = false; } var heightDelta = 0; // Initialise the ion mobility units dropdown with L10N values foreach (eIonMobilityUnits t in Enum.GetValues(typeof(eIonMobilityUnits))) { comboBoxIonMobilityUnits.Items.Add(IonMobilityFilter.IonMobilityUnitsL10NString(t)); } if (needOptionalValuesBox) { var newHeight = groupBoxOptionalValues.Height; var movers = new List <Control>(); int offset = 0; if (!needExplicitTransitionGroupValues && !needExplicitTransitionValues) { // We blanked out everything but the retention time newHeight = labelCollisionEnergy.Location.Y; } else if (!needExplicitTransitionGroupValues) { // We need to shift transition-level items up to where retention time was movers.AddRange(new Control[] { textCollisionEnergy, labelCollisionEnergy, textDeclusteringPotential, labelDeclusteringPotential, textSLens, labelSLens, textConeVoltage, labelConeVoltage, textIonMobilityHighEnergyOffset, labelIonMobilityHighEnergyOffset }); labelIonMobilityHighEnergyOffset.Location = labelIonMobility.Location; textIonMobilityHighEnergyOffset.Location = textIonMobility.Location; offset = labelCollisionEnergy.Location.Y - labelRetentionTime.Location.Y; newHeight = textBoxCCS.Location.Y; } else if (!needExplicitTransitionValues) { // We need to shift precursor-level items up to where retention time was movers.AddRange(new Control[] { textBoxCCS, labelCCS, textIonMobility, labelIonMobility, comboBoxIonMobilityUnits, labelIonMobilityUnits }); offset = labelIonMobility.Location.Y - (explicitRetentionTime == null ? labelRetentionTime.Location.Y : labelCollisionEnergy.Location.Y); newHeight = explicitRetentionTime == null ? textSLens.Location.Y : textIonMobility.Location.Y; } foreach (var mover in movers) { mover.Anchor = AnchorStyles.Left | AnchorStyles.Top; mover.Location = new Point(mover.Location.X, mover.Location.Y - offset); } heightDelta = groupBoxOptionalValues.Height - newHeight; groupBoxOptionalValues.Height = newHeight; } ResultExplicitTransitionGroupValues = new ExplicitTransitionGroupValues(explicitTransitionGroupAttributes); ResultExplicitTransitionValues = new ExplicitTransitionValues(explicitTransitionAttributes); string labelAverage = !defaultCharge.IsEmpty ? Resources.EditCustomMoleculeDlg_EditCustomMoleculeDlg_A_verage_m_z_ : Resources.EditCustomMoleculeDlg_EditCustomMoleculeDlg_A_verage_mass_; string labelMono = !defaultCharge.IsEmpty ? Resources.EditCustomMoleculeDlg_EditCustomMoleculeDlg__Monoisotopic_m_z_ : Resources.EditCustomMoleculeDlg_EditCustomMoleculeDlg__Monoisotopic_mass_; var defaultFormula = molecule == null ? string.Empty : molecule.Formula; var transition = initialId as Transition; FormulaBox.EditMode editMode; if (enableAdductEditing && !enableFormulaEditing) { editMode = FormulaBox.EditMode.adduct_only; } else if (!enableAdductEditing && enableFormulaEditing) { editMode = FormulaBox.EditMode.formula_only; } else { editMode = FormulaBox.EditMode.formula_and_adduct; } string formulaBoxLabel; if (defaultCharge.IsEmpty) { formulaBoxLabel = Resources.EditCustomMoleculeDlg_EditCustomMoleculeDlg_Chemi_cal_formula_; } else if (editMode == FormulaBox.EditMode.adduct_only) { var prompt = defaultFormula; if (string.IsNullOrEmpty(defaultFormula) && molecule != null) { // Defined by mass only prompt = molecule.ToString(); } formulaBoxLabel = string.Format(Resources.EditCustomMoleculeDlg_EditCustomMoleculeDlg_Addu_ct_for__0__, prompt); } else { formulaBoxLabel = Resources.EditMeasuredIonDlg_EditMeasuredIonDlg_Ion__chemical_formula_; } double?averageMass = null; double?monoMass = null; if (transition != null && string.IsNullOrEmpty(defaultFormula) && transition.IsCustom()) { averageMass = transition.CustomIon.AverageMass; monoMass = transition.CustomIon.MonoisotopicMass; } else if (molecule != null) { averageMass = molecule.AverageMass; monoMass = molecule.MonoisotopicMass; } _formulaBox = new FormulaBox(false, // Not proteomic, so offer Cl and Br in atoms popup formulaBoxLabel, labelAverage, labelMono, defaultCharge, editMode, suggestOnlyAdductsWithMass) { NeutralFormula = defaultFormula, AverageMass = averageMass, MonoMass = monoMass, Location = new Point(textName.Left, textName.Bottom + 12) }; _formulaBox.ChargeChange += (sender, args) => { if (!_formulaBox.Adduct.IsEmpty) { Adduct = _formulaBox.Adduct; var revisedFormula = _formulaBox.NeutralFormula + Adduct.AdductFormula; if (!Equals(revisedFormula, _formulaBox.Formula)) { _formulaBox.Formula = revisedFormula; } if (string.IsNullOrEmpty(_formulaBox.NeutralFormula) && averageMass.HasValue) { _formulaBox.AverageMass = averageMass; _formulaBox.MonoMass = monoMass; } } }; Controls.Add(_formulaBox); _formulaBox.TabIndex = 2; _formulaBox.Enabled = enableFormulaEditing || enableAdductEditing; Adduct = defaultCharge; var needCharge = !Adduct.IsEmpty; textCharge.Visible = labelCharge.Visible = needCharge; if (needOptionalValuesBox && !needCharge) { heightDelta += groupBoxOptionalValues.Location.Y - labelCharge.Location.Y; groupBoxOptionalValues.Location = new Point(groupBoxOptionalValues.Location.X, labelCharge.Location.Y); } if (explicitRetentionTime == null) { // Don't ask user for retetention times RetentionTime = null; RetentionTimeWindow = null; labelRetentionTime.Visible = false; labelRetentionTimeWindow.Visible = false; textRetentionTime.Visible = false; textRetentionTimeWindow.Visible = false; } else { RetentionTime = explicitRetentionTime.RetentionTime; RetentionTimeWindow = explicitRetentionTime.RetentionTimeWindow; } if (!needOptionalValuesBox) { groupBoxOptionalValues.Visible = false; heightDelta = groupBoxOptionalValues.Height; } // Initialize label if (settings != null && defaultIsotopeLabelType != null) { _driverLabelType = new PeptideSettingsUI.LabelTypeComboDriver(PeptideSettingsUI.LabelTypeComboDriver.UsageType.InternalStandardPicker, comboIsotopeLabelType, settings.PeptideSettings.Modifications, null, null, null, null) { SelectedName = defaultIsotopeLabelType.Name }; } else { comboIsotopeLabelType.Visible = false; labelIsotopeLabelType.Visible = false; } Height -= heightDelta; }
/// <summary> /// Initialize GeocodeClient without a Google API key and use default anonymous access. /// NOTE: Throttling may apply. /// </summary> public GeocodeClient() { _mode = UsageMode.Free; _proxyProvider = new DefaultGeocodeProxyProvider(); }
public unsafe int WriteValue(byte *buffer, int size, out BlittableJsonToken token, UsageMode mode, int?initialCompressedSize) { int startPos = _position; token = BlittableJsonToken.String; _position += WriteVariableSizeInt(size); // if we are more than this size, we want to abort the compression early and just use // the verbatim string int maxGoodCompressionSize = size - sizeof(int) * 2; if (maxGoodCompressionSize > 0) { size = TryCompressValue(ref buffer, ref _position, size, ref token, mode, initialCompressedSize, maxGoodCompressionSize); } _unmanagedWriteBuffer.Write(buffer, size); _position += size; _position += WriteVariableSizeInt(0); return(startPos); }
private unsafe int TryCompressValue(ref byte *buffer, ref int position, int size, ref BlittableJsonToken token, UsageMode mode, int?initialCompressedSize, int maxGoodCompressionSize) { bool shouldCompress = initialCompressedSize.HasValue || (((mode & UsageMode.CompressStrings) == UsageMode.CompressStrings) && (size > 128)) || ((mode & UsageMode.CompressSmallStrings) == UsageMode.CompressSmallStrings) && (size <= 128); if (shouldCompress) { int compressedSize; byte *compressionBuffer; if (initialCompressedSize.HasValue) { // we already have compressed data here compressedSize = initialCompressedSize.Value; compressionBuffer = buffer; } else { compressionBuffer = CompressBuffer(buffer, size, maxGoodCompressionSize, out compressedSize); } if (compressedSize > 0) // only if we actually save more than space { token = BlittableJsonToken.CompressedString; buffer = compressionBuffer; size = compressedSize; position += WriteVariableSizeInt(compressedSize); } } return(size); }
public unsafe int WriteValue(byte *buffer, int size, out BlittableJsonToken token, UsageMode mode, int?initialCompressedSize) { return(WriteValue(buffer, size, null, out token, mode, initialCompressedSize)); }