String returns a base-64 string representation of a cursor.
()
| 741 | |
| 742 | // String returns a base-64 string representation of a cursor. |
| 743 | func (c Cursor) String() string { |
| 744 | if c.cc == nil { |
| 745 | return "" |
| 746 | } |
| 747 | b, err := proto.Marshal(c.cc) |
| 748 | if err != nil { |
| 749 | // The only way to construct a Cursor with a non-nil cc field is to |
| 750 | // unmarshal from the byte representation. We panic if the unmarshal |
| 751 | // succeeds but the marshaling of the unchanged protobuf value fails. |
| 752 | panic(fmt.Sprintf("datastore: internal error: malformed cursor: %v", err)) |
| 753 | } |
| 754 | return strings.TrimRight(base64.URLEncoding.EncodeToString(b), "=") |
| 755 | } |
| 756 | |
| 757 | // DecodeCursor decodes a cursor from its base-64 string representation. |
| 758 | func DecodeCursor(s string) (Cursor, error) { |