예제 #1
0
파일: Utils.cs 프로젝트: 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();
        }
예제 #2
0
        private IEnumerable <ContentType> ReadValueType()
        {
            if (MessageType == MessageType.Request)
            {
                //request method
                yield return(ContentType.String);

                //request params
                yield return(ContentType.Array);
            }

            while (_expectedBodyEnd > _stream.BytesRead)
            {
                var contentType = _stream.ReadContentType();
                yield return(contentType);
            }
        }
예제 #3
0
파일: Utils.cs 프로젝트: 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());
        }