Private Sub WriteVarInt(Value As Long) As Int
Dim Len As Int = 1
Dim Shift As Int = 63
Dim bc As ByteConverter
Dim val(1) As Int
Dim i As Int
Dim intAnzahlBytes As Int
Log ("WriteVarInt Value: " & Value )
intAnzahlBytes = Ceil( Value/ 127)
intAnzahlBytes = intAnzahlBytes -1
Log ("Bytes relevant: " & intAnzahlBytes)
'First screen out the leading zeros
Do While Shift > 0 And Bit.And(Value,Bit.ShiftLeft(MASK,Shift)) = 0
Shift = Shift - 7
Loop
i = 5
Do While Shift > 0
i = i -1
If i < intAnzahlBytes Then
TdDos.WriteByte( Bit.Or( Bit.ShiftRight( Bit.And(Value, Bit.ShiftLeft(MASK,Shift)),Shift),0x80))
Log ("i: " & i & " Written!")
Len = Len + 1
End If
Log ("WriteVarInt TdDos 1: " & Bit.Or( Bit.ShiftRight( Bit.And(Value, Bit.ShiftLeft(MASK,Shift)),Shift),0x80) & TAB & TAB & TAB & TAB & " Hex: " & bc.HexFromBytes(bc.IntsToBytes((val))))
val(0) = Bit.Or( Bit.ShiftRight( Bit.And(Value, Bit.ShiftLeft(MASK,Shift)),Shift),0x80)
Shift = Shift - 7
'Len = Len + 1
Loop
TdDos.WriteByte(Bit.And(Value,MASK))
val(0) = Bit.And(Value,MASK)
Log ("WriteVarInt TdDos 2: " & Bit.And(Value,MASK) & TAB & TAB & TAB & TAB & " Hex: " & bc.HexFromBytes(bc.IntsToBytes((val))) )
Return Len
End Sub