Exemple #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void writeDateTime(long epochSecondUTC, int nano, String zoneId) throws IllegalArgumentException
            public override void WriteDateTime(long epochSecondUTC, int nano, string zoneId)
            {
                if (AllowStorePointsAndTemporal)
                {
                    Block.ValueBlocks = TemporalType.encodeDateTime(KeyId, epochSecondUTC, nano, zoneId);
                }
                else
                {
                    throw new UnsupportedFormatCapabilityException(Capability.TEMPORAL_PROPERTIES);
                }
            }
Exemple #2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void writeDate(long epochDay) throws IllegalArgumentException
            public override void WriteDate(long epochDay)
            {
                if (AllowStorePointsAndTemporal)
                {
                    Block.ValueBlocks = TemporalType.encodeDate(KeyId, epochDay);
                }
                else
                {
                    throw new UnsupportedFormatCapabilityException(Capability.TEMPORAL_PROPERTIES);
                }
            }
Exemple #3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void writeTime(long nanosOfDayUTC, int offsetSeconds) throws IllegalArgumentException
            public override void WriteTime(long nanosOfDayUTC, int offsetSeconds)
            {
                if (AllowStorePointsAndTemporal)
                {
                    Block.ValueBlocks = TemporalType.encodeTime(KeyId, nanosOfDayUTC, offsetSeconds);
                }
                else
                {
                    throw new UnsupportedFormatCapabilityException(Capability.TEMPORAL_PROPERTIES);
                }
            }
Exemple #4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void writeDuration(long months, long days, long seconds, int nanos) throws IllegalArgumentException
            public override void WriteDuration(long months, long days, long seconds, int nanos)
            {
                if (AllowStorePointsAndTemporal)
                {
                    Block.ValueBlocks = TemporalType.encodeDuration(KeyId, months, days, seconds, nanos);
                }
                else
                {
                    throw new UnsupportedFormatCapabilityException(Capability.TEMPORAL_PROPERTIES);
                }
            }
Exemple #5
0
        public static Value GetRightArray(Pair <sbyte[], sbyte[]> data)
        {
            sbyte[] header = data.First();
            sbyte[] bArray = data.Other();
            sbyte   typeId = header[0];

            if (typeId == PropertyType.String.intValue())
            {
                ByteBuffer headerBuffer = ByteBuffer.wrap(header, 1, header.Length - 1);
                int        arrayLength  = headerBuffer.Int;
                string[]   result       = new string[arrayLength];

                ByteBuffer dataBuffer = ByteBuffer.wrap(bArray);
                for (int i = 0; i < arrayLength; i++)
                {
                    int     byteLength      = dataBuffer.Int;
                    sbyte[] stringByteArray = new sbyte[byteLength];
                    dataBuffer.get(stringByteArray);
                    result[i] = PropertyStore.DecodeString(stringByteArray);
                }
                return(Values.stringArray(result));
            }
            else if (typeId == PropertyType.Geometry.intValue())
            {
                GeometryType.GeometryHeader geometryHeader = GeometryType.GeometryHeader.fromArrayHeaderBytes(header);
                return(GeometryType.decodeGeometryArray(geometryHeader, bArray));
            }
            else if (typeId == PropertyType.Temporal.intValue())
            {
                TemporalType.TemporalHeader temporalHeader = TemporalType.TemporalHeader.fromArrayHeaderBytes(header);
                return(TemporalType.decodeTemporalArray(temporalHeader, bArray));
            }
            else
            {
                ShortArray type = ShortArray.typeOf(typeId);
                int        bitsUsedInLastByte = header[1];
                int        requiredBits       = header[2];
                if (requiredBits == 0)
                {
                    return(type.createEmptyArray());
                }
                if (type == ShortArray.Byte && requiredBits == (sizeof(sbyte) * 8))
                {                         // Optimization for byte arrays (probably large ones)
                    return(Values.byteArray(bArray));
                }
                else
                {                         // Fallback to the generic approach, which is a slower
                    Bits bits   = Bits.bitsFromBytes(bArray);
                    int  length = (bArray.Length * 8 - (8 - bitsUsedInLastByte)) / requiredBits;
                    return(type.createArray(length, bits, requiredBits));
                }
            }
        }
Exemple #6
0
        /// <summary>
        ///     Converts given unix timestamp to DateTime
        /// </summary>
        /// <param name="value">unix timestamp for conversion</param>
        /// <param name="temporalType">type of conversion</param>
        /// <returns>converted DateTime value</returns>
        /// <exception cref="ArgumentOutOfRangeException">in case of unknown conversionType was given</exception>
        public static DateTime ToDateTime(this long value, TemporalType temporalType)
        {
            var timestamp = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Local);

            switch (temporalType)
            {
            case TemporalType.Milliseconds:
                return(timestamp.AddMilliseconds(value).ToLocalTime());

            case TemporalType.Seconds:
                return(timestamp.AddSeconds(value).ToLocalTime());

            default:
                throw new ArgumentOutOfRangeException(nameof(temporalType), temporalType, null);
            }
        }
Exemple #7
0
        public static void AllocateRecords(ICollection <DynamicRecord> target, object array, DynamicRecordAllocator recordAllocator, bool allowStorePointsAndTemporal)
        {
            if (!array.GetType().IsArray)
            {
                throw new System.ArgumentException(array + " not an array");
            }

            Type type = array.GetType().GetElementType();

            if (type.Equals(typeof(string)))
            {
                AllocateFromString(target, ( string[] )array, recordAllocator);
            }
            else if (type.Equals(typeof(PointValue)))
            {
                AllocateFromCompositeType(target, GeometryType.encodePointArray(( PointValue[] )array), recordAllocator, allowStorePointsAndTemporal, Capability.POINT_PROPERTIES);
            }
            else if (type.Equals(typeof(LocalDate)))
            {
                AllocateFromCompositeType(target, TemporalType.encodeDateArray(( LocalDate[] )array), recordAllocator, allowStorePointsAndTemporal, Capability.TEMPORAL_PROPERTIES);
            }
            else if (type.Equals(typeof(LocalTime)))
            {
                AllocateFromCompositeType(target, TemporalType.encodeLocalTimeArray(( LocalTime[] )array), recordAllocator, allowStorePointsAndTemporal, Capability.TEMPORAL_PROPERTIES);
            }
            else if (type.Equals(typeof(DateTime)))
            {
                AllocateFromCompositeType(target, TemporalType.encodeLocalDateTimeArray(( DateTime[] )array), recordAllocator, allowStorePointsAndTemporal, Capability.TEMPORAL_PROPERTIES);
            }
            else if (type.Equals(typeof(OffsetTime)))
            {
                AllocateFromCompositeType(target, TemporalType.encodeTimeArray(( OffsetTime[] )array), recordAllocator, allowStorePointsAndTemporal, Capability.TEMPORAL_PROPERTIES);
            }
            else if (type.Equals(typeof(ZonedDateTime)))
            {
                AllocateFromCompositeType(target, TemporalType.encodeDateTimeArray(( ZonedDateTime[] )array), recordAllocator, allowStorePointsAndTemporal, Capability.TEMPORAL_PROPERTIES);
            }
            else if (type.Equals(typeof(DurationValue)))
            {
                AllocateFromCompositeType(target, TemporalType.encodeDurationArray(( DurationValue[] )array), recordAllocator, allowStorePointsAndTemporal, Capability.TEMPORAL_PROPERTIES);
            }
            else
            {
                AllocateFromNumbers(target, array, recordAllocator);
            }
        }
Exemple #8
0
        public static ArrayValue ReadArrayFromBuffer(ByteBuffer buffer)
        {
            if (buffer.limit() <= 0)
            {
                throw new System.InvalidOperationException("Given buffer is empty");
            }

            sbyte typeId = buffer.get();

            buffer.order(ByteOrder.BIG_ENDIAN);
            try
            {
                if (typeId == PropertyType.String.intValue())
                {
                    int      arrayLength = buffer.Int;
                    string[] result      = new string[arrayLength];

                    for (int i = 0; i < arrayLength; i++)
                    {
                        int byteLength = buffer.Int;
                        result[i] = UTF8.decode(buffer.array(), buffer.position(), byteLength);
                        buffer.position(buffer.position() + byteLength);
                    }
                    return(Values.stringArray(result));
                }
                else if (typeId == PropertyType.Geometry.intValue())
                {
                    GeometryType.GeometryHeader header = GeometryType.GeometryHeader.fromArrayHeaderByteBuffer(buffer);
                    sbyte[] byteArray = new sbyte[buffer.limit() - buffer.position()];
                    buffer.get(byteArray);
                    return(GeometryType.decodeGeometryArray(header, byteArray));
                }
                else if (typeId == PropertyType.Temporal.intValue())
                {
                    TemporalType.TemporalHeader header = TemporalType.TemporalHeader.fromArrayHeaderByteBuffer(buffer);
                    sbyte[] byteArray = new sbyte[buffer.limit() - buffer.position()];
                    buffer.get(byteArray);
                    return(TemporalType.decodeTemporalArray(header, byteArray));
                }
                else
                {
                    ShortArray type = ShortArray.typeOf(typeId);
                    int        bitsUsedInLastByte = buffer.get();
                    int        requiredBits       = buffer.get();
                    if (requiredBits == 0)
                    {
                        return(type.createEmptyArray());
                    }
                    if (type == ShortArray.Byte && requiredBits == (sizeof(sbyte) * 8))
                    {                              // Optimization for byte arrays (probably large ones)
                        sbyte[] byteArray = new sbyte[buffer.limit() - buffer.position()];
                        buffer.get(byteArray);
                        return(Values.byteArray(byteArray));
                    }
                    else
                    {                              // Fallback to the generic approach, which is a slower
                        Bits bits   = Bits.bitsFromBytes(buffer.array(), buffer.position());
                        int  length = ((buffer.limit() - buffer.position()) * 8 - (8 - bitsUsedInLastByte)) / requiredBits;
                        return(type.createArray(length, bits, requiredBits));
                    }
                }
            }
            finally
            {
                buffer.order(ByteOrder.LITTLE_ENDIAN);
            }
        }
 public Temporal(TemporalType type)
 {
     _type = type;
 }