static void encodeDate(final long epochDay, final MutableAsciiBuffer string, final int offset) { // adjust to 0000-03-01 so leap day is at end of four year cycle final long zeroDay = epochDay + DAYS_UNTIL_START_OF_UNIX_EPOCH - 60; long yearEstimate = (400 * zeroDay + 591) / DAYS_IN_400_YEAR_CYCLE; long dayEstimate = estimateDayOfYear(zeroDay, yearEstimate); if (dayEstimate < 0) { // fix estimate yearEstimate--; dayEstimate = estimateDayOfYear(zeroDay, yearEstimate); } final int marchDay0 = (int)dayEstimate; // convert march-based values back to january-based final int marchMonth0 = (marchDay0 * 5 + 2) / 153; final int month = (marchMonth0 + 2) % 12 + 1; final int day = marchDay0 - (marchMonth0 * 306 + 5) / 10 + 1; final int year = (int)(yearEstimate + marchMonth0 / 10); string.putNaturalPaddedIntAscii(offset, 4, year); string.putNaturalPaddedIntAscii(offset + 4, 2, month); string.putNaturalPaddedIntAscii(offset + 6, 2, day); }
static void encodeFraction( final long epochSecond, final int fractionOfSecond, final MutableAsciiBuffer string, final int offset, final int fractionFieldLength) { int secondOfDay = (int)Math.floorMod(epochSecond, SECONDS_IN_DAY); final int hours = secondOfDay / SECONDS_IN_HOUR; secondOfDay -= hours * SECONDS_IN_HOUR; final int minutes = secondOfDay / SECONDS_IN_MINUTE; secondOfDay -= minutes * SECONDS_IN_MINUTE; string.putNaturalPaddedIntAscii(offset, 2, hours); string.putChar(offset + 2, ':'); string.putNaturalPaddedIntAscii(offset + 3, 2, minutes); string.putChar(offset + 5, ':'); string.putNaturalPaddedIntAscii(offset + 6, 2, secondOfDay); if (fractionOfSecond > 0) { string.putChar(offset + 8, '.'); string.putNaturalPaddedIntAscii(offset + 9, fractionFieldLength, fractionOfSecond); } } }
private void updateChecksum(final int messageClaimOffset, final int beforeChecksum, final int messageEndOffset) { final int lengthOfSeparator = 1; final int checksumEnd = beforeChecksum + lengthOfSeparator; final int checksum = mutableAsciiFlyweight.computeChecksum(messageClaimOffset, checksumEnd); final int checksumValueOffset = messageEndOffset - (CHECKSUM_VALUE_LENGTH + SEPARATOR_LENGTH); mutableAsciiFlyweight.putNaturalPaddedIntAscii(checksumValueOffset, CHECKSUM_VALUE_LENGTH, checksum); mutableAsciiFlyweight.putSeparator(checksumValueOffset + CHECKSUM_VALUE_LENGTH); }
public int encode(final MutableAsciiBuffer buffer, final int offset) { final int endYear = offset + SIZE_OF_YEAR; final int endMonth = endYear + SIZE_OF_MONTH; buffer.putNaturalPaddedIntAscii(offset, SIZE_OF_YEAR, year()); buffer.putNaturalPaddedIntAscii(endYear, SIZE_OF_MONTH, month().getValue()); final int dayOfMonth = dayOfMonth(); if (dayOfMonth != NONE) { buffer.putNaturalPaddedIntAscii(endMonth, SIZE_OF_DAY_OF_MONTH, dayOfMonth); return LONG_LENGTH; } else { final int weekOfMonth = weekOfMonth(); if (weekOfMonth != NONE) { buffer.putChar(endMonth, 'w'); buffer.putNaturalPaddedIntAscii(endMonth + 1, SIZE_OF_WEEK_OF_MONTH, weekOfMonth); return LONG_LENGTH; } } return SHORT_LENGTH; }
mutableAsciiFlyweight.putNaturalPaddedIntAscii( bodyLengthClaimOffset, lengthOfUpdatedBodyLengthField, newBodyLength);