Beispiel #1
0
        private static long GetLong(DirectBuffer buffer, int index, Encoding encoding)
        {
            switch (encoding.PrimitiveType.Type)
            {
            case SbePrimitiveType.Char:
                return(buffer.CharGet(index));

            case SbePrimitiveType.Int8:
                return(buffer.Int8Get(index));

            case SbePrimitiveType.Int16:
                return(buffer.Int16GetLittleEndian(index));

            case SbePrimitiveType.Int32:
                return(buffer.Int32GetLittleEndian(index));

            case SbePrimitiveType.Int64:
                return(buffer.Int64GetLittleEndian(index));

            case SbePrimitiveType.UInt8:
                return(buffer.Uint8Get(index));

            case SbePrimitiveType.UInt16:
                return(buffer.Uint16GetLittleEndian(index));

            case SbePrimitiveType.UInt32:
                return(buffer.Uint32GetLittleEndian(index));

            case SbePrimitiveType.UInt64:
                return((long)buffer.Uint64GetLittleEndian(index));     // TODO this is incorrect

            default:
                throw new ArgumentException("Unsupported type for long: " + encoding.PrimitiveType);
            }
        }
Beispiel #2
0
        private static PrimitiveValue ConstOrNotPresentValue(Token token, int actingVersion)
        {
            Encoding encoding = token.Encoding;

            if (encoding.Presence == Presence.Constant)
            {
                return(encoding.ConstValue);
            }

            if (Presence.Optional == encoding.Presence)
            {
                if (token.Version < actingVersion)
                {
                    return(encoding.ApplicableNullVal);
                }
            }

            return(null);
        }
Beispiel #3
0
        private static string ReadEncodingAsString(DirectBuffer buffer, int index, Token typeToken, int actingVersion)
        {
            PrimitiveValue constOrNotPresentValue = ConstOrNotPresentValue(typeToken, actingVersion);

            if (null != constOrNotPresentValue)
            {
                return(constOrNotPresentValue.ToString());
            }

            var      sb          = new StringBuilder();
            Encoding encoding    = typeToken.Encoding;
            int      elementSize = encoding.PrimitiveType.Size;

            for (int i = 0, size = typeToken.ArrayLength; i < size; i++)
            {
                MapEncodingToString(sb, buffer, index + (i * elementSize), encoding);
                sb.Append(", ");
            }

            sb.Length = sb.Length - 2;

            return(sb.ToString());
        }
        /// <summary>
        /// Construct an <seealso cref="Token"/> by providing values for all fields.
        /// </summary>
        /// <param name="signal"> for the token role </param>
        /// <param name="name"> of the token in the message </param>
        /// <param name="id"> as the identifier in the message declaration </param>
        /// <param name="version"> application within the template </param>
        /// <param name="size"> of the component part </param>
        /// <param name="offset"> in the underlying message as octets </param>
        /// <param name="encoding"> of the primitive field </param>
        public Token(Signal signal, string name, int id, int version, int size, int offset, Encoding encoding)
        {
            Verify.NotNull(signal, "signal");
            Verify.NotNull(name, "name");
            Verify.NotNull(encoding, "encoding");

            _signal = signal;
            _name = name;
            _id = id;
            _version = version;
            _size = size;
            _offset = offset;
            _encoding = encoding;
        }
 public Builder Encoding(Encoding encoding)
 {
     _encoding = encoding;
     return this;
 }
        private static long GetLong(DirectBuffer buffer, int index, Encoding encoding)
        {
            switch (encoding.PrimitiveType.Type)
            {
                case SbePrimitiveType.Char:
                    return buffer.CharGet(index);

                case SbePrimitiveType.Int8:
                    return buffer.Int8Get(index);

                case SbePrimitiveType.Int16:
                    return buffer.Int16GetLittleEndian(index);

                case SbePrimitiveType.Int32:
                    return buffer.Int32GetLittleEndian(index);

                case SbePrimitiveType.Int64:
                    return buffer.Int64GetLittleEndian(index);

                case SbePrimitiveType.UInt8:
                    return buffer.Uint8Get(index);

                case SbePrimitiveType.UInt16:
                    return buffer.Uint16GetLittleEndian(index);

                case SbePrimitiveType.UInt32:
                    return buffer.Uint32GetLittleEndian(index);

                case SbePrimitiveType.UInt64:
                    return (long) buffer.Uint64GetLittleEndian(index); // TODO this is incorrect

                default:
                    throw new ArgumentException("Unsupported type for long: " + encoding.PrimitiveType);
            }
        }
        //TODO big endian
        private static void MapEncodingToString(StringBuilder sb, DirectBuffer buffer, int index, Encoding encoding)
        {
            switch (encoding.PrimitiveType.Type)
            {
                case SbePrimitiveType.Char:
                    sb.Append('\'').Append(buffer.CharGet(index)).Append('\'');
                    break;

                case SbePrimitiveType.Int8:
                    sb.Append(buffer.Int8Get(index));
                    break;

                case SbePrimitiveType.Int16:
                    sb.Append(buffer.Int16GetLittleEndian(index));
                    break;

                case SbePrimitiveType.Int32:
                    sb.Append(buffer.Int32GetLittleEndian(index));
                    break;

                case SbePrimitiveType.Int64:
                    sb.Append(buffer.Int64GetLittleEndian(index));
                    break;

                case SbePrimitiveType.UInt8:
                    sb.Append(buffer.Uint8Get(index));
                    break;

                case SbePrimitiveType.UInt16:
                    sb.Append(buffer.Uint16GetLittleEndian(index));
                    break;

                case SbePrimitiveType.UInt32:
                    sb.Append(buffer.Uint32GetLittleEndian(index));
                    break;

                case SbePrimitiveType.UInt64:
                    sb.Append(buffer.Uint64GetLittleEndian(index));
                    break;

                case SbePrimitiveType.Float:
                    sb.Append(buffer.FloatGetLittleEndian(index));
                    break;

                case SbePrimitiveType.Double:
                    sb.Append(buffer.DoubleGetLittleEndian(index));
                    break;
            }
        }
Beispiel #8
0
        //TODO big endian
        private static void MapEncodingToString(StringBuilder sb, DirectBuffer buffer, int index, Encoding encoding)
        {
            switch (encoding.PrimitiveType.Type)
            {
            case SbePrimitiveType.Char:
                sb.Append('\'').Append(buffer.CharGet(index)).Append('\'');
                break;

            case SbePrimitiveType.Int8:
                sb.Append(buffer.Int8Get(index));
                break;

            case SbePrimitiveType.Int16:
                sb.Append(buffer.Int16GetLittleEndian(index));
                break;

            case SbePrimitiveType.Int32:
                sb.Append(buffer.Int32GetLittleEndian(index));
                break;

            case SbePrimitiveType.Int64:
                sb.Append(buffer.Int64GetLittleEndian(index));
                break;

            case SbePrimitiveType.UInt8:
                sb.Append(buffer.Uint8Get(index));
                break;

            case SbePrimitiveType.UInt16:
                sb.Append(buffer.Uint16GetLittleEndian(index));
                break;

            case SbePrimitiveType.UInt32:
                sb.Append(buffer.Uint32GetLittleEndian(index));
                break;

            case SbePrimitiveType.UInt64:
                sb.Append(buffer.Uint64GetLittleEndian(index));
                break;

            case SbePrimitiveType.Float:
                sb.Append(buffer.FloatGetLittleEndian(index));
                break;

            case SbePrimitiveType.Double:
                sb.Append(buffer.DoubleGetLittleEndian(index));
                break;
            }
        }