Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Minor cleanups: sub order, vertical alignment, #=
* Move decode subs to the top so that all the read-* subs can be together.
* Vertically align some arguments that were bugging me as is.
* Change a # comment to #=.
  • Loading branch information
Geoffrey Broadwell committed Oct 26, 2013
1 parent ce9bea8 commit 63fc1c5
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions lib/PB/Binary/Reader.pm
Expand Up @@ -20,6 +20,18 @@ class X::PB::Binary::Invalid is Exception {
}


#= Convert combined field key to (field tag number, wire type)
sub decode-field-key($key) is export {
($key +> 3, $key +& 7)
}


#= Decode a zigzag-encoded signed number
sub decode-zigzag($zigzag) is export {
($zigzag +> 1) +^ -($zigzag +& 1)
}


#= Read a varint from a buffer at a given offset, updating the offset
sub read-varint($buffer, $offset is rw) is export {
my Int $value = 0;
Expand Down Expand Up @@ -59,27 +71,15 @@ sub read-fixed64($buffer, $offset is rw) is export {
}


#= Convert varint field key to (field tag number, wire type)
sub decode-field-key($key) is export {
($key +> 3, $key +& 7)
}


#= Decode a zigzag-encoded signed number
sub decode-zigzag($zigzag) is export {
($zigzag +> 1) +^ -($zigzag +& 1)
}


# Read a kv pair from a buffer at a given offset, updating the offset
#= Read a kv pair from a buffer at a given offset, updating the offset
sub read-pair($buffer, $offset is rw) is export {
my $orig-offset = $offset;
my ($field-tag, $wire-type)
= decode-field-key(read-varint($buffer, $offset));

my $value = do given $wire-type {
# Just plain values: varint, 64-bit, 32-bit
when 0 { read-varint($buffer, $offset) }
when 0 { read-varint( $buffer, $offset) }
when 1 { read-fixed64($buffer, $offset) }
when 5 { read-fixed32($buffer, $offset) }

Expand Down

0 comments on commit 63fc1c5

Please sign in to comment.