ttlmetric.java

来自「利用Java Socket写的一段通讯协议」· Java 代码 · 共 59 行

JAVA
59
字号
package com.ict.netcom2.metric;

import java.nio.ByteBuffer;

/**
 * 7 * 24 = 168 bytes
 * @author as
 *
 */
public class TTLMetric {	
	
	public static final int length = 168;

	public MetricUnit less5 = new MetricUnit(); // ttl值<5

	public MetricUnit less10 = new MetricUnit(); // ttl值在5到10之间

	public MetricUnit less20 = new MetricUnit(); // ttl值在10到20之间

	public MetricUnit less40 = new MetricUnit(); // ttl值在20到40之间

	public MetricUnit less80 = new MetricUnit(); // ttl值在40到80之间

	public MetricUnit less128 = new MetricUnit(); // ttl值在80到128之间

	public MetricUnit more128 = new MetricUnit(); // ttl值大于128
	
	public void store(byte[] result) {
		
		if (result.length != length) {
			System.err.println("[TTLMetric.store()] param len wrong.");
		}
		
		ByteBuffer buf = ByteBuffer.wrap(result);
		
		byte[] b = new byte[MetricUnit.length];
		buf.get(b);
		less5.store(b); // ttl值<5

		buf.get(b);
		less10.store(b); // ttl值在5到10之间

		buf.get(b);
		less20.store(b); // ttl值在10到20之间

		buf.get(b);
		less40.store(b); // ttl值在20到40之间

		buf.get(b);
		less80.store(b); // ttl值在40到80之间

		buf.get(b);
		less128.store(b); // ttl值在80到128之间

		buf.get(b);
		more128.store(b); // ttl值大于128
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?