-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This allows to browse change index files
- Loading branch information
Showing
1 changed file
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
proc varint {name {delta 0}} { | ||
# loop through bytes reading protobuf varint | ||
set value 0 | ||
set shift 0 | ||
set start_offset [pos] | ||
while {1} { | ||
set byte [uint8] | ||
set value [expr {$value | (($byte & 0x7f) << $shift)}] | ||
set shift [expr {$shift + 7}] | ||
if {($byte & 0x80) == 0} { | ||
set value [expr {$value + $delta}] | ||
if {$name ne ""} { | ||
entry $name $value [expr {[pos] - $start_offset}] $start_offset | ||
} | ||
|
||
return $value | ||
} | ||
} | ||
} | ||
|
||
proc account_id {name} { | ||
set length [varint ""] | ||
if {$length == 0} { | ||
return "" | ||
} | ||
set value [str $length "utf8" $name] | ||
return $value | ||
} | ||
|
||
proc buffer {name} { | ||
set length [varint ""] | ||
if {$length == 0} { | ||
return "" | ||
} | ||
set value [hex $length $name] | ||
return $value | ||
} | ||
|
||
while {![end]} { | ||
section -collapsed "Account" { | ||
set account [account_id "account"] | ||
if {$account eq ""} { | ||
endsection | ||
break | ||
} | ||
sectionvalue $account | ||
|
||
while {1} { | ||
section "Key" { | ||
set key [buffer "key"] | ||
if {[string length $key] == 0} { | ||
endsection | ||
break | ||
} | ||
sectionvalue $key | ||
section "Changes" { | ||
set changes_count [varint "count"] | ||
sectionvalue $changes_count | ||
set prev_change [varint "0"] | ||
for {set i 1} {$i < $changes_count} {incr i} { | ||
varint "$i" $prev_change | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |