fNbt.NbtBinaryReader.ReadString C# (CSharp) 메소드

ReadString() 공개 메소드

public ReadString ( ) : string
리턴 string
        public override string ReadString()
        {
            short length = ReadInt16();
            if (length < 0) {
                throw new NbtFormatException("Negative string length given!");
            }
            if (length < stringConversionBuffer.Length) {
                int stringBytesRead = 0;
                while (stringBytesRead < length) {
                    int bytesReadThisTime = BaseStream.Read(stringConversionBuffer, stringBytesRead, length);
                    if (bytesReadThisTime == 0) {
                        throw new EndOfStreamException();
                    }
                    stringBytesRead += bytesReadThisTime;
                }
                return Encoding.UTF8.GetString(stringConversionBuffer, 0, length);
            } else {
                byte[] stringData = ReadBytes(length);
                if (stringData.Length < length) {
                    throw new EndOfStreamException();
                }
                return Encoding.UTF8.GetString(stringData);
            }
        }

Usage Example

예제 #1
0
        void ReadTagHeader(bool readName)
        {
            // Setting state to error in case reader throws
            NbtParseState oldState = state;

            state = NbtParseState.Error;
            TagsRead++;
            TagName = (readName ? reader.ReadString() : null);

            valueCache = null;
            TagLength  = 0;
            atValue    = false;
            ListType   = NbtTagType.Unknown;

            switch (TagType)
            {
            case NbtTagType.Byte:
            case NbtTagType.Short:
            case NbtTagType.Int:
            case NbtTagType.Long:
            case NbtTagType.Float:
            case NbtTagType.Double:
            case NbtTagType.String:
                atValue = true;
                state   = oldState;
                break;

            case NbtTagType.IntArray:
            case NbtTagType.ByteArray:
            case NbtTagType.LongArray:
                TagLength = reader.ReadInt32();
                if (TagLength < 0)
                {
                    throw new NbtFormatException("Negative array length given: " + TagLength);
                }
                atValue = true;
                state   = oldState;
                break;

            case NbtTagType.List:
                ListType  = reader.ReadTagType();
                TagLength = reader.ReadInt32();
                if (TagLength < 0)
                {
                    throw new NbtFormatException("Negative tag length given: " + TagLength);
                }
                state = NbtParseState.AtListBeginning;
                break;

            case NbtTagType.Compound:
                state = NbtParseState.AtCompoundBeginning;
                break;

            default:
                // This should not happen unless NbtBinaryReader is bugged
                throw new NbtFormatException("Trying to read tag of unknown type.");
            }
        }
All Usage Examples Of fNbt.NbtBinaryReader::ReadString