OLD | NEW |
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 datastore | 5 package datastore |
6 | 6 |
7 import ( | 7 import ( |
8 "bytes" | 8 "bytes" |
9 "encoding/base64" | 9 "encoding/base64" |
10 "encoding/json" | 10 "encoding/json" |
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 // | 403 // |
404 // toks is guaranteed to be empty if and only if k is nil. If k is non-nil then | 404 // toks is guaranteed to be empty if and only if k is nil. If k is non-nil then |
405 // it contains at least one token. | 405 // it contains at least one token. |
406 func (k *Key) Split() (appID, namespace string, toks []KeyTok) { | 406 func (k *Key) Split() (appID, namespace string, toks []KeyTok) { |
407 appID = k.appID | 407 appID = k.appID |
408 namespace = k.namespace | 408 namespace = k.namespace |
409 toks = make([]KeyTok, len(k.toks)) | 409 toks = make([]KeyTok, len(k.toks)) |
410 copy(toks, k.toks) | 410 copy(toks, k.toks) |
411 return | 411 return |
412 } | 412 } |
| 413 |
| 414 // EstimateSize estimates the size of a Key. |
| 415 // |
| 416 // It uses https://cloud.google.com/appengine/articles/storage_breakdown?csw=1 |
| 417 // as a guide for these values. |
| 418 func (k *Key) EstimateSize() int64 { |
| 419 ret := int64(len(k.appID)) |
| 420 ret += int64(len(k.namespace)) |
| 421 for _, t := range k.toks { |
| 422 ret += int64(len(t.Kind)) |
| 423 if t.StringID != "" { |
| 424 ret += int64(len(t.StringID)) |
| 425 } else { |
| 426 ret += 8 |
| 427 } |
| 428 } |
| 429 return ret |
| 430 } |
OLD | NEW |