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

Unified Diff: impl/memory/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, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | impl/memory/datastore_index.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: impl/memory/binary_tools.go
diff --git a/impl/memory/binary_tools.go b/impl/memory/binary_tools.go
deleted file mode 100644
index a0def895b10448250e3b0625292f17b2798564e4..0000000000000000000000000000000000000000
--- a/impl/memory/binary_tools.go
+++ /dev/null
@@ -1,65 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-package memory
-
-import (
- "fmt"
-)
-
-func bjoin(itms ...[]byte) []byte {
- total := 0
- for _, i := range itms {
- total += len(i)
- }
- ret := make([]byte, 0, total)
- for _, i := range itms {
- ret = append(ret, i...)
- }
- return ret
-}
-
-// invert simply inverts all the bytes in bs.
-func invert(bs []byte) []byte {
- if len(bs) == 0 {
- return nil
- }
- ret := make([]byte, len(bs))
- for i, b := range bs {
- ret[i] = 0xFF ^ b
- }
- return ret
-}
-
-func increment(bstr []byte) []byte {
- if len(bstr) > 0 {
- // Copy bstr
- ret := bjoin(bstr)
- for i := len(ret) - 1; i >= 0; i-- {
- if ret[i] == 0xFF {
- ret[i] = 0
- } else {
- ret[i]++
- return ret
- }
- }
- }
-
- // This byte string was ALL 0xFF's. The only safe incrementation to do here
- // would be to add a new byte to the beginning of bstr with the value 0x01,
- // and a byte to the beginning OF ALL OTHER []byte's which bstr may be
- // compared with. This is obviously impossible to do here, so panic. If we
- // hit this, then we would need to add a spare 0 byte before every index
- // column.
- //
- // Another way to think about this is that we just accumulated a 'carry' bit,
- // and the new value has overflowed this representation.
- //
- // Fortunately, the first byte of a serialized index column entry is a
- // PropertyType byte, and the only valid values that we'll be incrementing
- // are never equal to 0xFF, since they have the high bit set (so either they're
- // 0x8*, or 0x7*, depending on if it's inverted).
- impossible(fmt.Errorf("incrementing %v would require more sigfigs", bstr))
- return nil
-}
« no previous file with comments | « no previous file | impl/memory/datastore_index.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698