protected override Decimal OnRead(TProtocolReader reader) { string v = reader.ReadString(); Decimal dc = default(Decimal); Decimal.TryParse(v, out dc); return(dc); }
protected override Guid OnRead(TProtocolReader reader) { string v = reader.ReadString(); Guid id = Guid.Empty; Guid.TryParse(v, out id); return(id); }
private Object[] ReadArguments(TProtocol inProtocol) { try { int numArgs = _method.GetParameters().Length; Object[] args = new Object[numArgs]; TProtocolReader reader = new TProtocolReader(inProtocol); // Map incoming arguments from the ID passed in on the wire to the position in the // java argument list we expect to see a parameter with that ID. reader.ReadStructBegin(); while (reader.NextField()) { short fieldId = reader.GetFieldId(); IThriftCodec codec = null; if (!_parameterCodecs.TryGetValue(fieldId, out codec)) { // unknown field reader.SkipFieldData(); } else { // Map the incoming arguments to an array of arguments ordered as the java // code for the handler method expects to see them args[_thriftParameterIdToCSharpArgument[fieldId]] = reader.ReadField(codec); } } reader.ReadStructEnd(); // Walk through our list of expected parameters and if no incoming parameters were // mapped to a particular expected parameter, fill the expected parameter slow with // the default for the parameter type. int argumentPosition = 0; foreach (ThriftFieldMetadata argument in _parameters) { if (args[argumentPosition] == null) { Type argumentType = argument.ThriftType.CSharpType; if (!argumentType.Equals(typeof(void))) { args[argumentPosition] = ThriftyUtilities.GetDefaultValue(argumentType); } } argumentPosition++; } return(args); } catch (TProtocolException e) { // TProtocolException is the only recoverable exception // Other exceptions may have left the input stream in corrupted state so we must // tear down the socket. throw new TApplicationException(TApplicationException.ExceptionType.ProtocolError, e.Message); } }
public override T Read(TProtocol protocol) { TProtocolReader reader = new TProtocolReader(protocol); reader.ReadStructBegin(); IDictionary <short, Object> data = new Dictionary <short, Object>(_metadata.Fields.Count()); while (reader.NextField()) { short fieldId = reader.GetFieldId(); // do we have a codec for this field IThriftCodec codec; if (!_fields.TryGetValue(fieldId, out codec)) { reader.SkipFieldData(); continue; } // is this field readable ThriftFieldMetadata field = _metadata.GetField(fieldId); if (field.ReadOnly || field.Type != FieldKind.ThriftField) { reader.SkipFieldData(); continue; } // read the value Object value = reader.ReadField(codec); if (value == null) { if (field.Required == ThriftFieldAttribute.Requiredness.Required) { throw new TProtocolException($"'{field.Name}(id: {fieldId})' is a required field, but it was not set, thrift type: '{field.ThriftType.ToString()}', codec: '{codec.GetType().Name}'"); } else { continue; } } data[fieldId] = value; } reader.ReadStructEnd(); // build the struct return(ConstructStruct(data)); }
private Object ReadResponse(TProtocol inProtocol) { TProtocolReader reader = new TProtocolReader(inProtocol); reader.ReadStructBegin(); Object results = null; Exception exception = null; while (reader.NextField()) { if (reader.GetFieldId() == 0) { results = reader.ReadField(_successCodec); } else { IThriftCodec exceptionCodec = null; if (_exceptionCodecs.TryGetValue(reader.GetFieldId(), out exceptionCodec)) { exception = (Exception)reader.ReadField(exceptionCodec); } else { reader.SkipFieldData(); } } } reader.ReadStructEnd(); inProtocol.ReadMessageEnd(); if (exception != null) { throw exception; } if (_successCodec.Type == ThriftType.Void) { // TODO: check for non-null return from a void function? return(null); } if (results == null) { throw new TApplicationException(TApplicationException.ExceptionType.MissingResult, $"{this.QualifiedName} failed: unknown result"); } return(results); }
protected override DateTime[] OnRead(TProtocolReader reader) { var longArray = reader.ReadI64Array(); if (longArray == null) { return(null); } else { DateTime[] result = new DateTime[longArray.Length]; for (var i = 0; i < longArray.Length; i++) { result[i] = DateTimeThriftCodec.FromLongValue(longArray[i]); } return(result); } }
protected override short OnRead(TProtocolReader reader) { return(reader.ReadI16()); }
protected override long[] OnRead(TProtocolReader reader) { return(reader.ReadI64Array()); }
protected override ISet <T> OnRead(TProtocolReader reader) { return(reader.ReadSet(_elementCodec)); }
protected override int OnRead(TProtocolReader reader) { return(reader.ReadI32()); }
protected override IEnumerable <T> OnRead(TProtocolReader reader) { var list = reader.ReadList(elementCodec); return(_isArray ? list.ToArray() : list); }
protected override byte[] OnRead(TProtocolReader reader) { return(reader.ReadBinary()); }
protected override long OnRead(TProtocolReader reader) { return(reader.ReadI64()); }
protected override bool OnRead(TProtocolReader reader) { return(reader.ReadBool()); }
protected override bool[] OnRead(TProtocolReader reader) { return(reader.ReadBoolArray()); }
protected override float[] OnRead(TProtocolReader reader) { return(reader.ReadDoubleArray().Select(d => (float)d).ToArray());; }
protected override double OnRead(TProtocolReader reader) { return(reader.ReadDouble()); }
protected override double[] OnRead(TProtocolReader reader) { return(reader.ReadDoubleArray()); }
protected abstract T OnRead(TProtocolReader reader);
protected override float OnRead(TProtocolReader reader) { return((float)reader.ReadDouble()); }
protected override DateTime OnRead(TProtocolReader reader) { long value = reader.ReadI64(); return(FromLongValue(value)); }
protected override IDictionary <K, V> OnRead(TProtocolReader reader) { return(reader.ReadMap(_keyCodec, _valueCodec)); }
protected override byte OnRead(TProtocolReader reader) { return(reader.ReadByte()); }
protected override int[] OnRead(TProtocolReader reader) { return(reader.ReadI32Array()); }
protected override string OnRead(TProtocolReader reader) { return(reader.ReadString()); }
protected override short[] OnRead(TProtocolReader reader) { return(reader.ReadI16Array()); }