Skip to content

Commit

Permalink
Merge pull request #22 from evanj/evan.jones/rm-unused-function
Browse files Browse the repository at this point in the history
stream.go: Use protowire package; Remove zigzag32/64 functions
  • Loading branch information
richardartoul authored May 31, 2024
2 parents 30622f9 + 8db2523 commit 429ac4f
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ func (ps *ProtoStream) Sint64(fieldNumber int, value int64) error {
}
ps.scratchBuffer = ps.scratchBuffer[:0]
ps.encodeKeyToScratch(fieldNumber, protowire.VarintType)
ps.scratchBuffer = protowire.AppendVarint(ps.scratchBuffer, zigzag64(uint64(value)))
ps.scratchBuffer = protowire.AppendVarint(ps.scratchBuffer, protowire.EncodeZigZag(value))
return ps.writeScratch()
}

Expand All @@ -253,7 +253,7 @@ func (ps *ProtoStream) Sint64Packed(fieldNumber int, values []int64) error {
}
ps.scratchBuffer = ps.scratchBuffer[:0]
for _, value := range values {
ps.scratchBuffer = protowire.AppendVarint(ps.scratchBuffer, zigzag64(uint64(value)))
ps.scratchBuffer = protowire.AppendVarint(ps.scratchBuffer, protowire.EncodeZigZag(value))
}
return ps.writeScratchAsPacked(fieldNumber)
}
Expand Down Expand Up @@ -502,11 +502,3 @@ func (ps *ProtoStream) writeAllString(value string) error {
func (ps *ProtoStream) encodeKeyToScratch(fieldNumber int, wireType protowire.Type) {
ps.scratchBuffer = protowire.AppendVarint(ps.scratchBuffer, uint64(fieldNumber)<<3+uint64(wireType))
}

func zigzag32(v uint64) uint64 {
return uint64((uint32(v) << 1) ^ uint32((int32(v) >> 31)))
}

func zigzag64(v uint64) uint64 {
return (v << 1) ^ uint64((int64(v) >> 63))
}

0 comments on commit 429ac4f

Please sign in to comment.