My favorites
▼
|
Sign in
aeftools
App Engine Tools by appenginefan.com
Project Home
Downloads
Wiki
Issues
Source
Checkout
Browse
Changes
Source path:
svn
/
trunk
/
src
/
java
/
com
/
appenginefan
/
toolkit
/
persistence
/
ProtocolBufferPersistence.java
r21
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package com.appenginefan.toolkit.persistence;
import com.google.common.base.Preconditions;
import com.google.protobuf.InvalidProtocolBufferException;
import com.google.protobuf.Message;
/**
* Persistence that uses googles protocol buffer framework
* for efficient representation and serialization of data.
*
* @param <T>
* the type of protocol message that this
* persistence is for
*/
public class ProtocolBufferPersistence<T extends Message>
extends MarshallingPersistence<T> {
private final T prototype;
/**
* Constructor
*
* @param backend
* a backend that stores serialized protocol
* buffers
* @param prototype
* a prototype instance of the generic type that
* this peristence object is for.
*/
public ProtocolBufferPersistence(
Persistence<byte[]> backend, T prototype) {
super(backend);
Preconditions.checkNotNull(prototype);
this.prototype = prototype;
}
@Override
protected byte[] makeArray(T nonNullValue) {
return nonNullValue.toByteArray();
}
@SuppressWarnings("unchecked")
@Override
protected T makeType(byte[] nonNullValue) {
try {
return (T) prototype.newBuilderForType().mergeFrom(
nonNullValue).build();
} catch (InvalidProtocolBufferException e) {
throw new StoreException(
"ProtocolBuffer deserialization failed", e);
}
}
}
Show details
Hide details
Change log
r2
by schefflerjens on Apr 17, 2009
Diff
Initial revision
Go to:
/trunk
/trunk/LICENSE-2.0.txt
/trunk/build.xml
/trunk/dist
/trunk/dist/aeftools.jar
/trunk/docs
/trunk/docs/api
...k/docs/api/allclasses-frame.html
...docs/api/allclasses-noframe.html
/trunk/docs/api/com
/trunk/docs/api/com/appenginefan
...ocs/api/com/appenginefan/toolkit
...appenginefan/toolkit/persistence
...stence/DatastorePersistence.html
...istence/MapBasedPersistence.html
...ence/MarshallingPersistence.html
...rsistence/ObjectPersistence.html
...kit/persistence/Persistence.html
...e/ProtocolBufferPersistence.html
.../persistence/StoreException.html
...rsistence/StringPersistence.html
...t/persistence/package-frame.html
...persistence/package-summary.html
...it/persistence/package-tree.html
...nk/docs/api/constant-values.html
...nk/docs/api/deprecated-list.html
/trunk/docs/api/help-doc.html
/trunk/docs/api/index-all.html
/trunk/docs/api/index.html
/trunk/docs/api/overview-tree.html
/trunk/docs/api/package-list
/trunk/docs/api/resources
...k/docs/api/resources/inherit.gif
...nk/docs/api/serialized-form.html
/trunk/docs/api/stylesheet.css
/trunk/lib
/trunk/lib/readme.txt
/trunk/src
/trunk/src/java
/trunk/src/java/com
/trunk/src/java/com/appenginefan
...rc/java/com/appenginefan/toolkit
...appenginefan/toolkit/persistence
...stence/DatastorePersistence.java
...istence/MapBasedPersistence.java
...ence/MarshallingPersistence.java
...rsistence/ObjectPersistence.java
...kit/persistence/Persistence.java
...e/ProtocolBufferPersistence.java
.../persistence/StoreException.java
Project members,
sign in
to write a code review
Older revisions
All revisions of this file
File info
Size: 1433 bytes, 54 lines
View raw file
Powered by
Google Project Hosting