Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,14 @@ public static Builder newBuilder(Key key, FullEntity<?> copyFrom) {
public static Entity fromPb(com.google.datastore.v1.Entity entityPb) {
return new Builder().fill(entityPb).build();
}

/**
* Returns the size in bytes of the protobuf form of the provided entity.
*
* @param entity object whose size is measured.
*/
public static int calculateSerializedSize(BaseEntity<? extends IncompleteKey> entity) {
checkNotNull(entity);
return entity.toPb().getSerializedSize();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,9 @@ public void testCopyFromIncompleteEntity() throws Exception {
assertNotEquals(INCOMPLETE_ENTITY, entity);
assertEquals(INCOMPLETE_ENTITY.getProperties(), entity.getProperties());
}

@Test
public void testEntitySize() {
assertEquals(ENTITY.toPb().getSerializedSize(), Entity.calculateSerializedSize(ENTITY));
}
}