public void OnEncoding(Token fieldToken, DirectBuffer buffer, int index, Token typeToken, int actingVersion)
        {
            string value = ReadEncodingAsString(buffer, index, typeToken, actingVersion);

            PrintScope();
            Console.WriteLine("{0}={1}", fieldToken.Name, value);
        }
        private static void DecodeComposite(Token fieldToken, DirectBuffer buffer, int bufferIndex, IList<Token> tokens,
            int fromIndex, int toIndex, int actingVersion, ITokenListener listener)
        {
            listener.OnBeginComposite(fieldToken, tokens, fromIndex, toIndex);

            for (int i = fromIndex + 1; i < toIndex; i++)
            {
                Token token = tokens[i];
                listener.OnEncoding(token, buffer, bufferIndex + token.Offset, token, actingVersion);
            }

            listener.OnEndComposite(fieldToken, tokens, fromIndex, toIndex);
        }
        public void OnEnum(Token fieldToken, DirectBuffer buffer, int bufferIndex, IList<Token> tokens, int beginIndex,
            int endIndex, int actingVersion)
        {
            Token typeToken = tokens[beginIndex + 1];
            long encodedValue = ReadEncodingAsLong(buffer, bufferIndex, typeToken, actingVersion);

            string value = null;
            for (int i = beginIndex + 1; i < endIndex; i++)
            {
                // TODO to check..
                if (encodedValue == tokens[i].Encoding.ConstValue.LongValue())
                {
                    value = tokens[i].Name;
                    break;
                }
            }

            PrintScope();
            Console.WriteLine("{0}={1}", fieldToken.Name, value);
        }
        public virtual void OnBitSet(Token fieldToken, DirectBuffer buffer, int bufferIndex, IList<Token> tokens,
            int beginIndex, int endIndex, int actingVersion)
        {
            Token typeToken = tokens[beginIndex + 1];
            long encodedValue = ReadEncodingAsLong(buffer, bufferIndex, typeToken, actingVersion);

            PrintScope();
            Console.Write("{0}:", fieldToken.Name);

            for (int i = beginIndex + 1; i < endIndex; i++)
            {
                Console.Write(" {0}=", tokens[i].Name);

                long bitPosition = tokens[i].Encoding.ConstValue.LongValue();
                bool flag = (encodedValue & (long) Math.Pow(2, bitPosition)) != 0;

                Console.Write(Convert.ToString(flag));
            }

            Console.WriteLine();
        }
 public void OnEndMessage(Token token)
 {
     _namedScope.Pop();
 }
        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 (actingVersion < token.Version)
                {
                    return encoding.ApplicableNullVal;
                }
            }

            return null;
        }
Exemplo n.º 7
0
    private int EncodeToken(Token token)
    {
        Encoding encoding = token.encoding();
        PrimitiveType type = encoding.primitiveType();

        tokenCodec.wrapForEncode(directBuffer, 0).tokenOffset(token.offset()).tokenSize(token.size()).schemaId(token.schemaId()).tokenVersion(token.version()).signal(mapSignal(token.signal())).primitiveType(mapPrimitiveType(type)).byteOrder(mapByteOrder(encoding.byteOrder())).presence(mapPresence(encoding.presence()));

        sbyte[] nameBytes = token.name().getBytes(TokenCodec.nameCharacterEncoding());
        tokenCodec.putName(nameBytes, 0, nameBytes.Length);

        tokenCodec.putConstVal(valArray, 0, put(valBuffer, encoding.constVal(), type));
        tokenCodec.putMinVal(valArray, 0, put(valBuffer, encoding.minVal(), type));
        tokenCodec.putMaxVal(valArray, 0, put(valBuffer, encoding.maxVal(), type));
        tokenCodec.putNullVal(valArray, 0, put(valBuffer, encoding.nullVal(), type));

        sbyte[] charEncodingBytes = getBytes(encoding.characterEncoding(), TokenCodec.characterEncodingCharacterEncoding());
        tokenCodec.putCharacterEncoding(charEncodingBytes, 0, charEncodingBytes.Length);

        sbyte[] epochBytes = getBytes(encoding.epoch(), TokenCodec.epochCharacterEncoding());
        tokenCodec.putEpoch(epochBytes, 0, epochBytes.Length);

        sbyte[] timeUnitBytes = getBytes(encoding.timeUnit(), TokenCodec.timeUnitCharacterEncoding());
        tokenCodec.putTimeUnit(timeUnitBytes, 0, timeUnitBytes.Length);

        sbyte[] semanticTypeBytes = getBytes(encoding.semanticType(), TokenCodec.semanticTypeCharacterEncoding());
        tokenCodec.putSemanticType(semanticTypeBytes, 0, semanticTypeBytes.Length);

        return tokenCodec.size();
    }
 public virtual void OnEndGroup(Token token, int groupIndex, int numInGroup)
 {
     _namedScope.Pop();
 }
 public virtual void OnEndComposite(Token fieldToken, IList<Token> tokens, int fromIndex, int toIndex)
 {
     _namedScope.Pop();
 }
 /// <summary>
 /// Callback raised when the OTF decoder encounters a variable length data
 /// </summary>
 public virtual void OnVarData(Token fieldToken, DirectBuffer buffer, int bufferIndex, int length,
     Token typeToken)
 {
     // no op
 }
 /// <summary>
 /// Callback raised when the OTF decoder encounters the end of a group
 /// </summary>
 public virtual void OnEndGroup(Token token, int groupIndex, int numInGroup)
 {
     // no op
 }
 /// <summary>
 /// Callback raised when the OTF decoder encounters the end of a composite
 /// </summary>
 public virtual void OnEndComposite(Token fieldToken, IList<Token> tokens, int fromIndex, int toIndex)
 {
     // no op
 }
 /// <summary>
 /// Callback raised when the OTF decoder encounters a bit set
 /// </summary>
 public virtual void OnBitSet(Token fieldToken, DirectBuffer buffer, int bufferIndex, IList<Token> tokens,
     int fromIndex, int toIndex, int actingVersion)
 {
     // no op
 }
 /// <summary>
 /// Callback raised when the OTF decoder encounters an encoding
 /// </summary>
 public virtual void OnEncoding(Token fieldToken, DirectBuffer buffer, int bufferIndex, Token typeToken, int actingVersion)
 {
     // no op
 }
 /// <summary>
 /// Callback raised when the OTF decoder encounters the end of a message
 /// </summary>
 /// <param name="token">the corresponding token</param>
 public virtual void OnEndMessage(Token token)
 {
     // no op
 }
 /// <summary>
 /// Callback raised when the OTF decoder encounters the begining of a message
 /// </summary>
 /// <param name="token">the corresponding token</param>
 public virtual void OnBeginMessage(Token token)
 {
     // no op
 }
 public virtual void OnBeginComposite(Token fieldToken, IList<Token> tokens, int fromIndex, int toIndex)
 {
     _namedScope.Push(fieldToken.Name + ".");
 }
        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();
        }
 public virtual void OnBeginGroup(Token token, int groupIndex, int numInGroup)
 {
     _namedScope.Push(token.Name + ".");
 }
        private long ReadEncodingAsLong(DirectBuffer buffer, int bufferIndex, Token typeToken, int actingVersion)
        {
            PrimitiveValue constOrNotPresentValue = ConstOrNotPresentValue(typeToken, actingVersion);
            if (null != constOrNotPresentValue)
            {
                return constOrNotPresentValue.LongValue();
            }

            return GetLong(buffer, bufferIndex, typeToken.Encoding);
        }
        public virtual void OnVarData(Token fieldToken, DirectBuffer buffer, int bufferIndex, int length,
            Token typeToken)
        {
            string value;
            try
            {
                int varDataLength = buffer.GetBytes(bufferIndex, _tempBuffer, 0, length);
                System.Text.Encoding encoding = System.Text.Encoding.GetEncoding(typeToken.Encoding.CharacterEncoding);
                value = encoding.GetString(_tempBuffer, 0, varDataLength);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                Console.Write(ex.StackTrace);
                return;
            }

            PrintScope();
            Console.WriteLine("{0}={1}", fieldToken.Name, value);
        }
 public void OnBeginMessage(Token token)
 {
     _namedScope.Push(token.Name + ".");
 }