public static int lenIonTimestamp ( Timestamp di ) { if ( di == null ) return 0 ; int len = 0 ; switch ( di . getPrecision ( ) ) { case FRACTION : case SECOND : { BigDecimal fraction = di . getFractionalSecond ( ) ; if ( fraction != null ) { assert fraction . signum ( ) >= 0 && ! fraction . equals ( BigDecimal . ZERO ) : "Bad timestamp fraction: " + fraction ; // Since the fraction is not 0d0, at least one subfield of the // exponent and mantissa is non-zero, so this will always write at // least one byte. int fracLen = IonBinary . lenIonDecimal ( fraction ) ; assert fracLen > 0 ; len += fracLen ; } len ++ ; // len of seconds < 60 } case MINUTE : len += 2 ; // len of hour and minutes (both < 127) case DAY : len += 1 ; // len of month and day (both < 127) case MONTH : len += 1 ; // len of month and day (both < 127) case YEAR : len += IonBinary . lenVarUInt ( di . getZYear ( ) ) ; } Integer offset = di . getLocalOffset ( ) ; if ( offset == null ) { len ++ ; // room for the -0 (i.e. offset is "no specified offset") } else if ( offset == 0 ) { len ++ ; } else { len += IonBinary . lenVarInt ( offset . longValue ( ) ) ; } return len ; }
this method computes the output length of this timestamp value in the Ion binary format . It does not include the length of the typedesc byte that preceeds the actual value . The output length of a null value is 0 as a result this this .