Java Code Examples for com.google.protobuf.ByteString#asReadOnlyByteBuffer()

The following examples show how to use com.google.protobuf.ByteString#asReadOnlyByteBuffer() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AdxBidRequest.java    From bidder with Apache License 2.0 6 votes vote down vote up
/**
 * Convert IP address to dotted decimal (ipv4) and coloned decimal (ipv6)
 * 
 * @param ip
 *            ByteString. The bytes to decode
 * @return String. The ip address form of the byte stream.
 */
protected static String convertIp(ByteString ip) {
	ByteBuffer b = ip.asReadOnlyByteBuffer();
	StringBuilder sb = new StringBuilder();
	if (ip.size() == 3) {
		for (int i = 0; i < ip.size(); i++) {
			sb.append(Integer.toUnsignedString(0xff & b.get(i)));
			sb.append(".");
		}
		sb.append("0");
	} else {
		for (int i = 0; i < ip.size(); i++) {
			sb.append(Integer.toUnsignedString(0xff & b.get(i)));
			sb.append(":");
		}
		sb.append("0");
	}
	return sb.toString();
}
 
Example 2
Source File: AdxBidRequest.java    From XRTB with Apache License 2.0 6 votes vote down vote up
/**
 * Convert IP address to dotted decimal (ipv4) and coloned decimal (ipv6)
 * 
 * @param ip
 *            ByteString. The bytes to decode
 * @return String. The ip address form of the byte stream.
 */
protected static String convertIp(ByteString ip) {
	ByteBuffer b = ip.asReadOnlyByteBuffer();
	StringBuilder sb = new StringBuilder();
	if (ip.size() == 3) {
		for (int i = 0; i < ip.size(); i++) {
			sb.append(Integer.toUnsignedString(0xff & b.get(i)));
			sb.append(".");
		}
		sb.append("0");
	} else {
		for (int i = 0; i < ip.size(); i++) {
			sb.append(Integer.toUnsignedString(0xff & b.get(i)));
			sb.append(":");
		}
		sb.append("0");
	}
	return sb.toString();
}
 
Example 3
Source File: AdxBidRequest.java    From bidder with Apache License 2.0 5 votes vote down vote up
/**
 * Return the hex string
 * 
 * @param ip
 *            ByteString. Source to convert
 * @return String. The string encoded version of the source, as a string og
 *         hex digits.
 */
protected static String convertToHex(ByteString ip) {
	ByteBuffer b = ip.asReadOnlyByteBuffer();
	StringBuilder sb = new StringBuilder();
	for (int i = 0; i < ip.size(); i++) {
		sb.append(Integer.toHexString(0xff & b.get(i)));
	}
	return sb.toString();
}
 
Example 4
Source File: AdxBidRequest.java    From XRTB with Apache License 2.0 5 votes vote down vote up
/**
 * Return the hex string
 * 
 * @param ip
 *            ByteString. Source to convert
 * @return String. The string encoded version of the source, as a string og
 *         hex digits.
 */
protected static String convertToHex(ByteString ip) {
	ByteBuffer b = ip.asReadOnlyByteBuffer();
	StringBuilder sb = new StringBuilder();
	for (int i = 0; i < ip.size(); i++) {
		sb.append(Integer.toHexString(0xff & b.get(i)));
	}
	return sb.toString();
}
 
Example 5
Source File: UUIDUtil.java    From jesos with Apache License 2.0 4 votes vote down vote up
public static UUID bytesUuid(final ByteString byteString)
{
    final ByteBuffer uuidBuffer = byteString.asReadOnlyByteBuffer();
    // This always works (JLS 15.7.4)
    return new UUID(uuidBuffer.getLong(), uuidBuffer.getLong());
}