Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stream.go: Use protowire package; Remove zigzag32/64 functions #22

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
}
Loading