2024-03-01 12:09:17 +02:00
|
|
|
#required BytesReader.sbsl
|
2024-03-01 13:14:46 +02:00
|
|
|
#required BytesHelper.sbsl
|
|
|
|
#required BracketsParser.sbsl
|
2024-03-01 12:09:17 +02:00
|
|
|
|
|
|
|
// This format is used in ExtensionZippedInfo field
|
|
|
|
@Global
|
|
|
|
structure Class
|
|
|
|
req val Reader: BytesReader.Class
|
|
|
|
|
|
|
|
@Global
|
2024-03-01 13:14:46 +02:00
|
|
|
method Peek(): Bytes
|
|
|
|
return Reader.Peek()
|
2024-03-01 12:09:17 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
@Global
|
2024-03-01 13:14:46 +02:00
|
|
|
method ReadByte(): Bytes
|
|
|
|
return Reader.Read()
|
2024-03-01 12:09:17 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
@Global
|
2024-03-01 13:14:46 +02:00
|
|
|
method ReadBytes(Count: Number): Bytes
|
|
|
|
return Reader.Read(Count)
|
2024-03-01 12:09:17 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
@Global
|
2024-03-01 13:14:46 +02:00
|
|
|
method Skip(Count: Number = 1)
|
|
|
|
Reader.Read(Count)
|
2024-03-01 12:09:17 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
@Global
|
|
|
|
method ReadBoolean(): Boolean
|
2024-03-01 13:14:46 +02:00
|
|
|
val Value = ReadByte()
|
2024-03-01 12:09:17 +02:00
|
|
|
|
|
|
|
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
|
2024-03-01 13:14:46 +02:00
|
|
|
case Peek()
|
2024-03-01 12:09:17 +02:00
|
|
|
when Bytes{9A}
|
|
|
|
val Data = ReadVarbinary()
|
|
|
|
return Data.ToString()
|
|
|
|
when Bytes{97}
|
|
|
|
Skip()
|
|
|
|
val Length = BytesHelper.ToChar(ReadByte())
|
|
|
|
val Data = ReadBytes(Length * 2)
|
2024-03-01 13:44:15 +02:00
|
|
|
return FromNChar(Data)
|
2024-03-01 12:09:17 +02:00
|
|
|
else
|
|
|
|
val Marker = ReadByte()
|
|
|
|
throw new IllegalFormatException("Unexpected character: ${Marker}. Expected: 0x9A or 0x97")
|
|
|
|
;
|
|
|
|
;
|
2024-03-01 13:14:46 +02:00
|
|
|
|
2024-03-01 12:09:17 +02:00
|
|
|
@Global
|
2024-03-01 13:14:46 +02:00
|
|
|
method ReadBracketsNode(): BracketsParser.BracketsNode
|
2024-03-01 12:09:17 +02:00
|
|
|
val Content = ReadString()
|
2024-03-01 13:14:46 +02:00
|
|
|
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}")
|
|
|
|
;
|
2024-03-01 12:09:17 +02:00
|
|
|
;
|
2024-03-01 13:44:15 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
;
|
2024-03-01 12:09:17 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
@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)
|
|
|
|
;
|