#required BytesReader.sbsl #required BytesHelper.sbsl #required BracketsParser.sbsl // This format is used in ExtensionZippedInfo field @Global structure Class req val Reader: BytesReader.Class @Global method Peek(): Bytes return Reader.Peek() ; @Global method ReadByte(): Bytes return Reader.Read() ; @Global method ReadBytes(Count: Number): Bytes return Reader.Read(Count) ; @Global method Skip(Count: Number = 1) Reader.Read(Count) ; @Global method ReadBoolean(): Boolean val Value = ReadByte() case Value when Bytes{81} return False when Bytes{82} return True else throw new IllegalFormatException("Unexpected boolean character: ${Value}") ; ; @Global method ReadVarbinary(): Bytes val Marker = ReadByte() val Length = BytesHelper.ToChar(ReadByte()) if Marker == Bytes{9A} return ReadBytes(Length) else throw new IllegalFormatException("Unexpected character: ${Marker}. Expected: 0x9A") ; ; @Global method ReadString(): String case Peek() when Bytes{9A} val Data = ReadVarbinary() return Data.ToString() when Bytes{97} Skip() val Length = BytesHelper.ToChar(ReadByte()) val Data = ReadBytes(Length * 2) return FromNChar(Data) else val Marker = ReadByte() throw new IllegalFormatException("Unexpected character: ${Marker}. Expected: 0x9A or 0x97") ; ; @Global method ReadBracketsNode(): BracketsParser.BracketsNode val Content = ReadString() return BracketsParser.Parse(Content) ; @Global method ThrowIfNextIsNot(Pattern: Bytes) val Next = ReadBytes(Pattern.Length()) if Next != Pattern throw new IllegalFormatException("Unexpected character: ${Next}. Expected: ${Pattern}") ; ; method FromNChar(Data: Bytes): String var Result = "" var Offset = 0 while Offset < Data.Length() - 1 val Part = Data.GetRange(Offset, Offset + 2) val Reversed = BytesHelper.Reverse(Part) val TrimmedPart = BytesHelper.Trim(Reversed, Bytes{00}) val Encoding = TrimmedPart.Length() == 1 ? Encoding.Utf8 : Encoding.Utf16 Result += new String(TrimmedPart, Encoding) Offset += 2 ; return Result ; ; @Global method NewInstance(Data: Bytes, StartIndex = 0): AnotherFuckingOneCFormatReader.Class val Reader = BytesReader.NewInstance(Data, StartIndex) return AnotherFuckingOneCFormatReader.NewInstance(Reader) ; @Global method NewInstance(Reader: BytesReader.Class): AnotherFuckingOneCFormatReader.Class return new Class(Reader) ;