Example #1
0
 public override async Task<TField> ReadFieldBeginAsync(CancellationToken cancellationToken)
 {
     var field = new TField();
     var ch = await Reader.PeekAsync(cancellationToken);
     if (ch == Rbrace[0])
     {
         field.Type = TType.Stop;
     }
     else
     {
         field.ID = (short) await ReadJsonIntegerAsync(cancellationToken);
         await ReadJsonObjectStartAsync(cancellationToken);
         field.Type = GetTypeIdForTypeName(await ReadJsonStringAsync(false, cancellationToken));
     }
     return field;
 }
Example #2
0
        public async Task WriteAsync(TProtocol oprot, CancellationToken cancellationToken)
        {
            if (cancellationToken.IsCancellationRequested)
            {
                await Task.FromCanceled(cancellationToken);
            }

            const string messageTypeFieldName = "message";
            const string exTypeFieldName = "exType";
            const string structApplicationExceptionName = "TApplicationException";

            var struc = new TStruct(structApplicationExceptionName);
            var field = new TField();

            await oprot.WriteStructBeginAsync(struc, cancellationToken);

            if (!string.IsNullOrEmpty(Message))
            {
                field.Name = messageTypeFieldName;
                field.Type = TType.String;
                field.ID = MessageTypeFieldId;
                await oprot.WriteFieldBeginAsync(field, cancellationToken);
                await oprot.WriteStringAsync(Message, cancellationToken);
                await oprot.WriteFieldEndAsync(cancellationToken);
            }

            field.Name = exTypeFieldName;
            field.Type = TType.I32;
            field.ID = ExTypeFieldId;

            await oprot.WriteFieldBeginAsync(field, cancellationToken);
            await oprot.WriteI32Async((int) Type, cancellationToken);
            await oprot.WriteFieldEndAsync(cancellationToken);
            await oprot.WriteFieldStopAsync(cancellationToken);
            await oprot.WriteStructEndAsync(cancellationToken);
        }
Example #3
0
        public override async Task<TField> ReadFieldBeginAsync(CancellationToken cancellationToken)
        {
            // Read a field header off the wire.
            var type = (byte) await ReadByteAsync(cancellationToken);
            // if it's a stop, then we can return immediately, as the struct is over.
            if (type == Types.Stop)
            {
                return Tstop;
            }

            short fieldId;
            // mask off the 4 MSB of the exType header. it could contain a field id delta.
            var modifier = (short) ((type & 0xf0) >> 4);
            if (modifier == 0)
            {
                fieldId = await ReadI16Async(cancellationToken);
            }
            else
            {
                fieldId = (short) (_lastFieldId + modifier);
            }

            var field = new TField(string.Empty, GetTType((byte) (type & 0x0f)), fieldId);
            // if this happens to be a boolean field, the value is encoded in the exType
            if (IsBoolType(type))
            {
                _boolValue = (byte) (type & 0x0f) == Types.BooleanTrue;
            }

            // push the new field onto the field stack so we can keep the deltas going.
            _lastFieldId = field.ID;
            return field;
        }
Example #4
0
 public override async Task WriteFieldBeginAsync(TField field, CancellationToken cancellationToken)
 {
     await WriteJsonIntegerAsync(field.ID, cancellationToken);
     await WriteJsonObjectStartAsync(cancellationToken);
     await WriteJsonStringAsync(GetTypeNameForTypeId(field.Type), cancellationToken);
 }
Example #5
0
 public override async Task WriteFieldBeginAsync(TField field, CancellationToken cancellationToken)
 {
     if (field.Type == TType.Bool)
     {
         _booleanField = field;
     }
     else
     {
         await WriteFieldBeginInternalAsync(field, 0xFF, cancellationToken);
     }
 }
Example #6
0
        private async Task WriteFieldBeginInternalAsync(TField field, byte typeOverride,
            CancellationToken cancellationToken)
        {
            // if there's a exType override, use that.
            var typeToWrite = typeOverride == 0xFF ? GetCompactType(field.Type) : typeOverride;

            // check if we can use delta encoding for the field id
            if ((field.ID > _lastFieldId) && (field.ID - _lastFieldId <= 15))
            {
                var b = (byte) (((field.ID - _lastFieldId) << 4) | typeToWrite);
                // Write them together
                await Trans.WriteAsync(new[] {b}, cancellationToken);
            }
            else
            {
                // Write them separate
                await Trans.WriteAsync(new[] {typeToWrite}, cancellationToken);
                await WriteI16Async(field.ID, cancellationToken);
            }

            _lastFieldId = field.ID;
        }
Example #7
0
 public override async Task WriteFieldBeginAsync(TField field, CancellationToken cancellationToken)
 {
     await _wrappedProtocol.WriteFieldBeginAsync(field, cancellationToken);
 }
Example #8
0
        public override async Task WriteFieldBeginAsync(TField field, CancellationToken cancellationToken)
        {
            if (cancellationToken.IsCancellationRequested)
            {
                return;
            }

            await WriteByteAsync((sbyte) field.Type, cancellationToken);
            await WriteI16Async(field.ID, cancellationToken);
        }
Example #9
0
        public override async Task<TField> ReadFieldBeginAsync(CancellationToken cancellationToken)
        {
            if (cancellationToken.IsCancellationRequested)
            {
                return await Task.FromCanceled<TField>(cancellationToken);
            }

            var field = new TField
            {
                Type = (TType) await ReadByteAsync(cancellationToken)
            };

            if (field.Type != TType.Stop)
            {
                field.ID = await ReadI16Async(cancellationToken);
            }

            return field;
        }