public AmqpReader(ReadOnlySpan <byte> buffer) { _buffer = buffer; CurrentType = default; _current = 0; _currentLength = 0; _next = 0; _itemType = default; }
public Converted(AmqpType amqpType, Type source, Type target, Func <object, Type, object> getTarget, Func <object, Type, object> getSource) : base(null, target) { this.AmqpType = amqpType; this.source = source; this.target = target; this.getTarget = getTarget; this.getSource = getSource; this.encoder = AmqpEncoding.GetEncoding(target); }
public static bool TryReadConstructor(Span <byte> span, out AmqpType constructor) { if (span.Length == 0) { constructor = default; return(false); } constructor = (AmqpType)span[0]; if (constructor == AmqpType.String8) { return(true); } if (constructor == AmqpType.Descriptor) { return(true); } return(false); }
public Converted(AmqpType amqpType, Type source, Type target, Func<object, object> getTarget, Func<object, object> getSource) : base(null, target) { this.AmqpType = amqpType; this.source = source; this.target = target; this.GetTarget = getTarget; this.GetSource = getSource; this.encoder = AmqpEncoding.GetEncoding(target); }
public AmqpToken MoveNext() { _buffer = _buffer.Slice(_next); _next = 0; if (_buffer.Length == 0) { return(AmqpToken.EndOfData); } var constructor = (AmqpType)_buffer[0]; switch (constructor) { case AmqpType.Descriptor: _next++; CurrentType = AmqpToken.Descriptor; break; case AmqpType.Binary8: if (_buffer.Length == 1) { return(AmqpToken.EndOfData); } _currentLength = _buffer[1]; _current = 2; _next += _currentLength + _current; CurrentType = AmqpToken.Binary; break; case AmqpType.Binary32: _currentLength = BinaryPrimitives.ReadInt32BigEndian(_buffer.Slice(1)); _current = 5; _next += _currentLength + _current; CurrentType = AmqpToken.Binary; break; case AmqpType.String8: _current = 2; _currentLength = _buffer[1]; _next += _currentLength + _current; CurrentType = AmqpToken.String; break; case AmqpType.String32: _current = 5; _currentLength = BinaryPrimitives.ReadInt32BigEndian(_buffer.Slice(1)); _next += _currentLength + _current; CurrentType = AmqpToken.String; break; case AmqpType.Array8: { if (_buffer.Length < 4) { return(AmqpToken.EndOfData); } var itemSize = _buffer[1]; _currentLength = _buffer[2]; _itemType = (AmqpType)_buffer[3]; _current = 4; _next = _current + (_currentLength * itemSize); CurrentType = AmqpToken.Array; break; } case AmqpType.Array32: { if (_buffer.Length < 10) { return(AmqpToken.EndOfData); } var dataSize = BinaryPrimitives.ReadInt32BigEndian(_buffer.Slice(1)) - 5; _currentLength = BinaryPrimitives.ReadInt32BigEndian(_buffer.Slice(5)) * sizeof(int); _itemType = (AmqpType)_buffer[9]; _current = 10; _next = _current + dataSize; CurrentType = AmqpToken.Array; break; } default: throw new NotImplementedException(); } return(CurrentType); }