Example #1
0
        private AMQTypedValue SetProperty(string key, AMQTypedValue value)
        {
            InitMapIfNecessary();
            _encodedForm = null;
            if (value == null)
            {
                RemoveKey(key);
            }
            AMQTypedValue oldVal = (AMQTypedValue)_properties[key];

            _properties.Add(key, value);
            if (oldVal != null)
            {
                _encodedSize -= oldVal.EncodingLength;
            }
            else
            {
                _encodedSize += EncodingUtils.EncodedShortStringLength(key) + (uint)1;
            }
            if (value != null)
            {
                _encodedSize += value.EncodingLength;
            }

            return(oldVal);
        }
Example #2
0
        private void SetFromBuffer(ByteBuffer buffer, uint length)
        {
            bool trace = _log.IsDebugEnabled;

            if (length > 0)
            {
                int expectedRemaining = buffer.Remaining - (int)length;
                _properties = new LinkedHashtable();

                do
                {
                    string        key   = EncodingUtils.ReadShortString(buffer);
                    AMQTypedValue value = AMQTypedValue.ReadFromBuffer(buffer);
                    if (trace)
                    {
                        _log.Debug(string.Format("FieldTable::PropFieldTable(buffer,{0}): Read type '{1}', key '{2}', value '{3}'", length, value.Type, key, value.Value));
                    }
                    _properties.Add(key, value);
                } while (buffer.Remaining > expectedRemaining);
                _encodedSize = length;
            }
            if (trace)
            {
                _log.Debug("FieldTable::FieldTable(buffer," + length + "): Done.");
            }
        }
Example #3
0
        //
        // Public Methods
        //

        /// <summary>
        /// Removes the property with the specified name
        /// </summary>
        /// <param name="key">The name of the property to remove</param>
        /// <returns>The previous value of the property or null</returns>
        public AMQTypedValue RemoveKey(string key)
        {
            InitMapIfNecessary();
            _encodedForm = null;
            AMQTypedValue value = (AMQTypedValue)_properties[key];

            if (value != null)
            {
                _properties.Remove(key);
                _encodedSize -= EncodingUtils.EncodedShortStringLength(key);
                _encodedSize--;
                _encodedSize -= value.EncodingLength;
            }
            return(value);
        }
Example #4
0
 public void WritePayload(ByteBuffer buffer)
 {
     if (_encodedForm != null)
     {
         lock ( _syncLock )
         {
             buffer.Put(_encodedForm);
             _encodedForm.Flip();
         }
     }
     else if (_properties != null)
     {
         foreach (DictionaryEntry de in _properties)
         {
             string        key   = (string)de.Key;
             AMQTypedValue value = (AMQTypedValue)de.Value;
             try
             {
                 if (_log.IsDebugEnabled)
                 {
                     _log.Debug("Writing Property:" + key +
                                " Type:" + value.Type +
                                " Value:" + value.Value);
                     _log.Debug("Buffer Position:" + buffer.Position +
                                " Remaining:" + buffer.Remaining);
                 }
                 //Write the actual parameter name
                 EncodingUtils.WriteShortStringBytes(buffer, key);
                 value.WriteToBuffer(buffer);
             } catch (Exception ex)
             {
                 if (_log.IsDebugEnabled)
                 {
                     _log.Debug("Exception thrown:" + ex);
                     _log.Debug("Writing Property:" + key +
                                " Type:" + value.Type +
                                " Value:" + value.Value);
                     _log.Debug("Buffer Position:" + buffer.Position +
                                " Remaining:" + buffer.Remaining);
                 }
                 throw;
             }
         }
     }
 }
Example #5
0
        private AMQTypedValue SetProperty(string key, AMQTypedValue value)
        {
           InitMapIfNecessary();
           _encodedForm = null;
           if ( value == null )
           {
              RemoveKey(key);
           }
           AMQTypedValue oldVal = (AMQTypedValue)_properties[key];
           _properties.Add(key, value);
           if ( oldVal != null )
           {
              _encodedSize -= oldVal.EncodingLength;
           } else
           {
              _encodedSize += EncodingUtils.EncodedShortStringLength(key) + (uint)1;
           }
           if ( value != null )
           {
              _encodedSize += value.EncodingLength;
           }

           return oldVal;
        }
Example #6
0
        private object GetObject(string key)
        {
            AMQTypedValue value = GetProperty(key);

            return(value != null ? value.Value : null);
        }