コード例 #1
0
        public static DateTime ReadTime(Reader reader)
        {
            var result = ValueReader.ReadTime(reader.Stream);

            reader.AddReference(result);
            return(result);
        }
コード例 #2
0
        public static Guid ReadGuid(Reader reader)
        {
            var result = ValueReader.ReadGuid(reader.Stream);

            reader.AddReference(result);
            return(result);
        }
コード例 #3
0
        public static string ReadString(Reader reader)
        {
            var result = ValueReader.ReadString(reader.Stream);

            reader.AddReference(result);
            return(result);
        }
コード例 #4
0
        public static char[] ReadChars(Reader reader)
        {
            var result = ValueReader.ReadChars(reader.Stream);

            reader.AddReference(result);
            return(result);
        }
コード例 #5
0
        public static byte[] ReadBytes(Reader reader)
        {
            var result = ValueReader.ReadBytes(reader.Stream);

            reader.AddReference(result);
            return(result);
        }
コード例 #6
0
        public static T[] ReadArray <T>(Reader reader)
        {
            Stream stream = reader.Stream;
            int    count  = ValueReader.ReadCount(stream);

            T[] a = new T[count];
            reader.AddReference(a);
            var deserializer = Deserializer <T> .Instance;

            for (int i = 0; i < count; ++i)
            {
                a[i] = deserializer.Deserialize(reader);
            }
            stream.ReadByte();
            return(a);
        }
コード例 #7
0
        private static void ReadUTF8CharRaw(Stream stream, Stream ostream)
        {
            int tag = stream.ReadByte();

            switch (tag >> 4)
            {
            case 0:
            case 1:
            case 2:
            case 3:
            case 4:
            case 5:
            case 6:
            case 7: {
                // 0xxx xxxx
                ostream.WriteByte((byte)tag);
                break;
            }

            case 12:
            case 13: {
                // 110x xxxx   10xx xxxx
                ostream.WriteByte((byte)tag);
                ostream.WriteByte((byte)stream.ReadByte());
                break;
            }

            case 14: {
                // 1110 xxxx  10xx xxxx  10xx xxxx
                ostream.WriteByte((byte)tag);
                ostream.WriteByte((byte)stream.ReadByte());
                ostream.WriteByte((byte)stream.ReadByte());
                break;
            }

            default:
                throw ValueReader.BadEncoding(tag);
            }
        }
コード例 #8
0
        private static void ReadStringRaw(Stream stream, Stream ostream)
        {
            int count = 0;
            int tag   = '0';

            do
            {
                count *= 10;
                count += tag - '0';
                tag    = stream.ReadByte();
                ostream.WriteByte((byte)tag);
            } while (tag != TagQuote);
            for (int i = 0; i < count; ++i)
            {
                tag = stream.ReadByte();
                switch (tag >> 4)
                {
                case 0:
                case 1:
                case 2:
                case 3:
                case 4:
                case 5:
                case 6:
                case 7: {
                    // 0xxx xxxx
                    ostream.WriteByte((byte)tag);
                    break;
                }

                case 12:
                case 13: {
                    // 110x xxxx   10xx xxxx
                    ostream.WriteByte((byte)tag);
                    ostream.WriteByte((byte)stream.ReadByte());
                    break;
                }

                case 14: {
                    // 1110 xxxx  10xx xxxx  10xx xxxx
                    ostream.WriteByte((byte)tag);
                    ostream.WriteByte((byte)stream.ReadByte());
                    ostream.WriteByte((byte)stream.ReadByte());
                    break;
                }

                case 15: {
                    // 1111 0xxx  10xx xxxx  10xx xxxx  10xx xxxx
                    if ((tag & 0xf) <= 4)
                    {
                        ostream.WriteByte((byte)tag);
                        ostream.WriteByte((byte)stream.ReadByte());
                        ostream.WriteByte((byte)stream.ReadByte());
                        ostream.WriteByte((byte)stream.ReadByte());
                        ++i;
                        break;
                    }
                    goto default;
                    // no break here!! here need throw exception.
                }

                default:
                    throw ValueReader.BadEncoding(tag);
                }
            }
            ostream.WriteByte((byte)stream.ReadByte());
        }