Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Side by Side Diff: service/datastore/serialize/binary_tools.go

Issue 1365743002: Refactor serialization helpers from impl/memory -> service/datastore/serialize (Closed) Base URL: https://github.com/luci/gae.git@estimate_size
Patch Set: fix comments Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « impl/memory/gkvlite_iter_test.go ('k') | service/datastore/serialize/serialize.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package serialize
6
7 import (
8 "bytes"
9 )
10
11 // Join is a convenience invocation of bytes.Join(itms, nil)
12 func Join(itms ...[]byte) []byte {
13 return bytes.Join(itms, nil)
14 }
15
16 // Invert simply inverts all the bytes in bs.
17 func Invert(bs []byte) []byte {
18 if len(bs) == 0 {
19 return nil
20 }
21 ret := make([]byte, len(bs))
22 for i, b := range bs {
23 ret[i] = 0xFF ^ b
24 }
25 return ret
26 }
27
28 // Increment attempts to increment a copy of bstr as if adding 1 to an integer.
29 //
30 // If it overflows, the returned []byte will be all 0's, and the overflow bool
31 // will be true.
32 func Increment(bstr []byte) ([]byte, bool) {
33 ret := Join(bstr)
34 for i := len(ret) - 1; i >= 0; i-- {
35 if ret[i] == 0xFF {
36 ret[i] = 0
37 } else {
38 ret[i]++
39 return ret, false
40 }
41 }
42 return ret, true
43 }
OLDNEW
« no previous file with comments | « impl/memory/gkvlite_iter_test.go ('k') | service/datastore/serialize/serialize.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698