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

Side by Side Diff: impl/memory/datastore_query.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: rebassseeeee 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package memory 5 package memory
6 6
7 import ( 7 import (
8 "bytes" 8 "bytes"
9 "encoding/base64" 9 "encoding/base64"
10 "errors" 10 "errors"
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 ret.numCols = len(ret.suffixFormat) 238 ret.numCols = len(ret.suffixFormat)
239 for prop, vals := range ret.eqFilters { 239 for prop, vals := range ret.eqFilters {
240 if len(ret.suffixFormat) == 1 && prop == "__ancestor__" { 240 if len(ret.suffixFormat) == 1 && prop == "__ancestor__" {
241 continue 241 continue
242 } 242 }
243 ret.numCols += vals.Len() 243 ret.numCols += vals.Len()
244 } 244 }
245 245
246 return ret, nil 246 return ret, nil
247 } 247 }
248
249 var invert = serialize.Invert
Vadim Sh. 2015/09/24 19:06:14 same here. why?
iannucci 2015/09/24 19:43:41 same :)
250
251 func increment(bstr []byte) []byte {
252 ret, overflow := serialize.Increment(bstr)
253 if overflow {
254 // This byte string was ALL 0xFF's. The only safe incrementation to do here
255 // would be to add a new byte to the beginning of bstr with the value 0x01,
256 // and a byte to the beginning OF ALL OTHER []byte's which bstr may be
257 // compared with. This is obviously impossible to do here, so pa nic. If we
258 // hit this, then we would need to add a spare 0 byte before eve ry index
259 // column.
260 //
261 // Another way to think about this is that we just accumulated a 'carry' bit,
262 // and the new value has overflowed this representation.
263 //
264 // Fortunately, the first byte of a serialized index column entr y is a
265 // PropertyType byte, and the only valid values that we'll be in crementing
266 // are never equal to 0xFF, since they have the high bit set (so either they're
267 // 0x8*, or 0x7*, depending on if it's inverted).
268 impossible(fmt.Errorf("incrementing %v would require more sigfig s", bstr))
269 }
270 return ret
271 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698