簡體   English   中英

如何使用Java獲取Appengine實體的大小

[英]How to get an appengine entity size in Java

是否可以獲得實體的大小? 看起來這應該是一件簡單的事情,但我不知道如何做。

我看到了

com.google.apphosting.api.ApiProxy$RequestTooLargeException: The request to API call datastore_v3.Put() was too large.

但我不確定該實體是否在1mb以上。 希望我能檢測到是否存在,並對此進行處理。 在catch子句中處理這種情況是否是最佳實踐?

如果您想要估計大小,則可以獲取protoBuffer的大小,該實體將通過put()調用轉換為該大小:

EntityProto ep=EntityTranslator.convertToPb(entity);

int size=ep.propertySize();

我得到一個估計:

EntityTranslator.convertToPb(entity).maxEncodingSize();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM