Exemplo n.º 1
0
Arquivo: Utils.cs Projeto: flwn/HmLib
        private static string tokenize(HmBinaryStreamReader r, StringBuilder outB, int state, int expected, bool returnAfterLoop)
        {
            do
            {
                var ct = state == 0 ? r.ReadContentType()
                    : state-- == 2 ? ContentType.String : ContentType.Array;

                switch (ct)
                {
                    case ContentType.Int:
                        outB.AppendFormat("i'{0}' ", r.ReadInt32());
                        break;
                    case ContentType.Boolean:
                        outB.AppendFormat("b'{0}' ", r.ReadBoolean());
                        break;
                    case ContentType.String:
                        outB.AppendFormat("s'{0}' ", r.ReadString());
                        break;
                    case ContentType.Float:
                        outB.AppendFormat("f'{0}' ", r.ReadDouble());
                        break;
                    case ContentType.Base64:
                        outB.AppendFormat("b64'{0}' ", r.ReadString());
                        break;
                    case ContentType.Array:
                        var arrItems = r.ReadInt32();
                        outB.AppendFormat("array({0})[ ", arrItems);
                        while (arrItems-- > 0)
                        {
                            tokenize(r, outB, state, expected, true);
                        }
                        outB.Append("] ");
                        break;
                    case ContentType.Struct:
                        var itemCount = r.ReadInt32();
                        outB.AppendFormat("struct({0})[ ", itemCount);
                        while (itemCount-- > 0)
                        {
                            outB.AppendFormat("{0}=", r.ReadString());
                            tokenize(r, outB, state, expected, true);
                        }
                        outB.Append("] ");
                        break;
                    default:
                        outB.Append("?? ");
                        break;
                }

                if (returnAfterLoop) break;

            } while (r.BytesRead < expected && state >= 0);

            return outB.ToString();
        }
Exemplo n.º 2
0
        private void ReadBody()
        {
            if (_readKeyValuePairs)
            {
                PropertyName = _stream.ReadString();
            }

            if (!_typeReader.MoveNext())
            {
                MoveToEof();
                return;
            }

            ValueType = _typeReader.Current;

            if (ValueType == ContentType.Array || ValueType == ContentType.Struct)
            {
                ItemCount = _stream.ReadInt32();
                BeginCollection();
                return;
            }

            if (ValueType == ContentType.String || ValueType == ContentType.Base64)
            {
                StringValue = _stream.ReadString();
            }
            else if (ValueType == ContentType.Int)
            {
                IntValue = _stream.ReadInt32();
            }
            else if (ValueType == ContentType.Float)
            {
                DoubleValue = _stream.ReadDouble();
            }
            else if (ValueType == ContentType.Boolean)
            {
                BooleanValue = _stream.ReadBoolean();
            }
            else
            {
                throw new NotImplementedException();
            }

            EndItem();
        }
Exemplo n.º 3
0
Arquivo: Utils.cs Projeto: flwn/HmLib
        private static string tokenize(HmBinaryStreamReader r, StringBuilder outB, int state, int expected, bool returnAfterLoop)
        {
            do
            {
                var ct = state == 0 ? r.ReadContentType()
                    : state-- == 2 ? ContentType.String : ContentType.Array;

                switch (ct)
                {
                case ContentType.Int:
                    outB.AppendFormat("i'{0}' ", r.ReadInt32());
                    break;

                case ContentType.Boolean:
                    outB.AppendFormat("b'{0}' ", r.ReadBoolean());
                    break;

                case ContentType.String:
                    outB.AppendFormat("s'{0}' ", r.ReadString());
                    break;

                case ContentType.Float:
                    outB.AppendFormat("f'{0}' ", r.ReadDouble());
                    break;

                case ContentType.Base64:
                    outB.AppendFormat("b64'{0}' ", r.ReadString());
                    break;

                case ContentType.Array:
                    var arrItems = r.ReadInt32();
                    outB.AppendFormat("array({0})[ ", arrItems);
                    while (arrItems-- > 0)
                    {
                        tokenize(r, outB, state, expected, true);
                    }
                    outB.Append("] ");
                    break;

                case ContentType.Struct:
                    var itemCount = r.ReadInt32();
                    outB.AppendFormat("struct({0})[ ", itemCount);
                    while (itemCount-- > 0)
                    {
                        outB.AppendFormat("{0}=", r.ReadString());
                        tokenize(r, outB, state, expected, true);
                    }
                    outB.Append("] ");
                    break;

                default:
                    outB.Append("?? ");
                    break;
                }

                if (returnAfterLoop)
                {
                    break;
                }
            } while (r.BytesRead < expected && state >= 0);

            return(outB.ToString());
        }