Protocol buffer: how to determine the type of date?

I am trying to write a proto file with a Date field that is not defined as a type in the protocol buffer.

I read the following post, but could not find a suitable solution that suits me: What are the best ways to use decimals and datetimes with protocol buffers? .

I am trying to convert a proto file to java.

+6
source share
2 answers

My answer in a related post mainly relates to protobuf-net; however, since you are using this from java, I would recommend: keep it simple.

For dates, I would suggest just using time (perhaps milliseconds) in an era (traditionally January 1, 1970). For times, only the size in the same device (milliseconds, etc.). For decimal numbers, maybe use a fixed point simply by scaling - so maybe treat 1.05 as long 1050 and always state exactly 3dp (hence a fixed point).

It is simple and pragmatic and covers the most common scenarios without complicating the situation.

+4
source

I'm not selling this idea, but I'm really not selling the idea of ​​storing dates (which are not time points) as a timestamp, so here is my suggestion.

Convert the date to a human-readable integer (e.g. 2014-11-3 will become 20141103 ) and store this integer value. It contains exactly the data you need, is easy to create and analyze, and takes up minimal space. In addition, it is ordered and has an unambiguous comparison of dates with valid values ​​(provided, invalid numbers are possible, for example 20149999 , but they are easy to detect). In contrast, there are approximately 86,400 valid timestamps that represent each day.

NB: There is a discussion in DBA SE criticizing this method of storing dates, but in this context there is a specialized type of date, which is obviously not the case here.

+2
source

Source: https://habr.com/ru/post/900383/


All Articles