Remove dead code
This commit is contained in:
@ -2,37 +2,18 @@ package nearenough.protocol;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ByteBufAllocator;
|
||||
import nearenough.util.BytesUtil;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import static nearenough.protocol.RtConstants.TIMESTAMP_LENGTH;
|
||||
import static nearenough.util.Preconditions.*;
|
||||
import static nearenough.util.Preconditions.checkNotNull;
|
||||
import static nearenough.util.Preconditions.checkState;
|
||||
|
||||
/**
|
||||
* Encodes/decodes {@link RtMessage Roughtime messages} and fields to/from their on-the-wire format.
|
||||
*/
|
||||
public final class RtWire {
|
||||
|
||||
/**
|
||||
* Convert the on-the-wire UTC midpoint value to a {@link ZonedDateTime} in UTC.
|
||||
*
|
||||
* @param midpBytes The MIDP value
|
||||
*
|
||||
* @return A {@link ZonedDateTime} that corresponds to the UTC time from the provided MIDP.
|
||||
*/
|
||||
public static ZonedDateTime timeFromMidpoint(byte[] midpBytes) {
|
||||
checkArgument(midpBytes.length == TIMESTAMP_LENGTH, "invalid MIDP length %s", midpBytes.length);
|
||||
|
||||
long midp = BytesUtil.getLongLE(midpBytes, 0);
|
||||
Instant midpInst = Instant.ofEpochMilli(midp / 1000L);
|
||||
return ZonedDateTime.ofInstant(midpInst, ZoneId.of("UTC"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode the given message for network transmission using the system default ByteBuf allocator.
|
||||
*
|
||||
|
@ -3,29 +3,17 @@ package nearenough.protocol;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static net.i2p.crypto.eddsa.Utils.hexToBytes;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.core.IsEqual.equalTo;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
|
||||
public final class RtWireTest {
|
||||
|
||||
@Test
|
||||
public void decodeMidpoint() {
|
||||
ZonedDateTime expectedMidpoint = ZonedDateTime.parse("2017-01-31T19:41:15.267Z[UTC]");
|
||||
|
||||
byte[] midpointBytes = hexToBytes("90a37a1d69470500");
|
||||
ZonedDateTime readMidpoint = RtWire.timeFromMidpoint(midpointBytes);
|
||||
|
||||
assertThat(readMidpoint, equalTo(expectedMidpoint));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sizeOfEmptyMessage() {
|
||||
int size = RtWire.computeEncodedSize(Collections.emptyMap());
|
||||
|
Reference in New Issue
Block a user