remove kotlin lib and proto source from src server dir
This commit is contained in:
@@ -1,305 +0,0 @@
|
|||||||
import java.nio.ByteBuffer
|
|
||||||
import java.nio.ByteOrder
|
|
||||||
import WireFormat.VARINT_INFO_BITS_COUNT
|
|
||||||
import WireFormat.VARINT_INFO_BITS_MASK
|
|
||||||
import WireFormat.VARINT_UTIL_BIT_MASK
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by Dmitry Savvinov on 7/6/16.
|
|
||||||
*
|
|
||||||
* Hides details of work with Protobuf encoding
|
|
||||||
*
|
|
||||||
* Note that CodedInputStream reads protobuf-defined types from stream (such as int32, sint32, etc),
|
|
||||||
* while CodedOutputStream has methods for writing Kotlin-types (such as Boolean, Int, Long, Short, etc)
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
// TODO: refactor correctness checks into readTag
|
|
||||||
class CodedInputStream(input: java.io.InputStream) {
|
|
||||||
val bufferedInput: java.io.BufferedInputStream
|
|
||||||
init {
|
|
||||||
bufferedInput = java.io.BufferedInputStream(input) // TODO: Java's realization uses hand-written buffers. Why?
|
|
||||||
}
|
|
||||||
|
|
||||||
fun readInt32(expectedFieldNumber: Int): Int {
|
|
||||||
val tag = readTag(expectedFieldNumber, WireType.VARINT)
|
|
||||||
val actualFieldNumber = WireFormat.getTagFieldNumber(tag)
|
|
||||||
val actualWireType = WireFormat.getTagWireType(tag)
|
|
||||||
checkFieldCorrectness(expectedFieldNumber, actualFieldNumber, WireType.VARINT, actualWireType)
|
|
||||||
return readInt32NoTag()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Note that unsigned integer types are stored as their signed counterparts with top bit
|
|
||||||
// simply stored in the sign bit - similar to Java's protobuf implementation. Hence, all
|
|
||||||
// methods reading unsigned ints simply redirect call to corresponding signed-reading method
|
|
||||||
fun readUInt32(expectedFieldNumber: Int): Int {
|
|
||||||
val tag = readTag(expectedFieldNumber, WireType.VARINT)
|
|
||||||
return readUInt32NoTag()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun readUInt32NoTag(): Int {
|
|
||||||
return readInt32NoTag()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun readInt64(expectedFieldNumber: Int): Long {
|
|
||||||
val tag = readTag(expectedFieldNumber, WireType.VARINT)
|
|
||||||
return readInt64NoTag()
|
|
||||||
}
|
|
||||||
|
|
||||||
// See note on unsigned integers implementations above
|
|
||||||
fun readUInt64(expectedFieldNumber: Int): Long {
|
|
||||||
val tag = readTag(expectedFieldNumber, WireType.VARINT)
|
|
||||||
return readUInt64NoTag()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun readUInt64NoTag(): Long {
|
|
||||||
return readInt64NoTag()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun readBool(expectedFieldNumber: Int): Boolean {
|
|
||||||
val tag = readTag(expectedFieldNumber, WireType.VARINT)
|
|
||||||
return readBoolNoTag()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun readBoolNoTag(): Boolean {
|
|
||||||
val readValue = readInt32NoTag()
|
|
||||||
val boolValue = when (readValue) {
|
|
||||||
0 -> false
|
|
||||||
1 -> true
|
|
||||||
else -> throw InvalidProtocolBufferException("Expected boolean-encoding (1 or 0), got $readValue")
|
|
||||||
}
|
|
||||||
return boolValue
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reading enums is like reading one int32 number. Caller is responsible for converting this ordinal to enum-object
|
|
||||||
fun readEnum(expectedFieldNumber: Int): Int {
|
|
||||||
val tag = readTag(expectedFieldNumber, WireType.VARINT)
|
|
||||||
return readEnumNoTag()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun readEnumNoTag(): Int {
|
|
||||||
return readUInt32NoTag()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun readSInt32(expectedFieldNumber: Int): Int {
|
|
||||||
val tag = readTag(expectedFieldNumber, WireType.VARINT)
|
|
||||||
return readSInt32NoTag()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun readSInt32NoTag(): Int {
|
|
||||||
return readZigZag32NoTag()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun readSInt64(expectedFieldNumber: Int): Long {
|
|
||||||
val tag = readTag(expectedFieldNumber, WireType.VARINT)
|
|
||||||
return readZigZag64NoTag()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun readFixed32(expectedFieldNumber: Int): Int {
|
|
||||||
val tag = readTag(expectedFieldNumber, WireType.FIX_32)
|
|
||||||
return readFixed32NoInt()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun readFixed32NoInt(): Int {
|
|
||||||
return readLittleEndianInt()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun readSFixed32(expectedFieldNumber: Int): Int {
|
|
||||||
val tag = readTag(expectedFieldNumber, WireType.FIX_32)
|
|
||||||
return readSFixed32NoTag()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun readSFixed32NoTag(): Int {
|
|
||||||
return readLittleEndianInt()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun readFixed64(expectedFieldNumber: Int): Long {
|
|
||||||
val tag = readTag(expectedFieldNumber, WireType.FIX_64)
|
|
||||||
return readFixed64NoTag()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun readFixed64NoTag(): Long {
|
|
||||||
return readLittleEndianLong()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun readSFixed64(expectedFieldNumber: Int): Long {
|
|
||||||
val tag = readTag(expectedFieldNumber, WireType.FIX_64)
|
|
||||||
return readSFixed64NoTag()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun readSFixed64NoTag(): Long {
|
|
||||||
return readLittleEndianLong()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun readDouble(expectedFieldNumber: Int): Double {
|
|
||||||
val tag = readTag(expectedFieldNumber, WireType.FIX_64)
|
|
||||||
return readDoubleNoTag()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun readDoubleNoTag(): Double {
|
|
||||||
return readLittleEndianDouble()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun readFloat(expectedFieldNumber: Int): Float {
|
|
||||||
val tag = readTag(expectedFieldNumber, WireType.FIX_32)
|
|
||||||
return readFloatNoTag()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun readFloatNoTag(): Float {
|
|
||||||
return readLittleEndianFloat()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun readString(expectedFieldNumber: Int): String {
|
|
||||||
val tag = readTag(expectedFieldNumber, WireType.LENGTH_DELIMITED)
|
|
||||||
return readStringNoTag()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun readStringNoTag(): String {
|
|
||||||
val length = readInt32NoTag()
|
|
||||||
val value = String(readRawBytes(length))
|
|
||||||
return value
|
|
||||||
}
|
|
||||||
|
|
||||||
fun readBytes(expectedFieldNumber: Int): ByteArray {
|
|
||||||
val tag = readTag(expectedFieldNumber, WireType.LENGTH_DELIMITED)
|
|
||||||
return readBytesNoTag()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun readBytesNoTag(): ByteArray {
|
|
||||||
val length = readInt32NoTag()
|
|
||||||
return readRawBytes(length)
|
|
||||||
}
|
|
||||||
|
|
||||||
/** ============ Utility methods ==================
|
|
||||||
* They are left non-private for cases when one wants to implement her/his own protocol format.
|
|
||||||
* Then she/he can re-use low-level methods for operating with raw values, that are not annotated with Protobuf tags.
|
|
||||||
*/
|
|
||||||
|
|
||||||
fun checkFieldCorrectness(
|
|
||||||
expectedFieldNumber: Int,
|
|
||||||
actualFieldNumber: Int,
|
|
||||||
expectedWireType: WireType,
|
|
||||||
actualWireType: WireType) {
|
|
||||||
if (expectedFieldNumber != actualFieldNumber) {
|
|
||||||
throw InvalidProtocolBufferException(
|
|
||||||
"Error in protocol format: \n " +
|
|
||||||
"Expected field number ${expectedFieldNumber}, got ${actualFieldNumber}")
|
|
||||||
}
|
|
||||||
|
|
||||||
if (expectedWireType != actualWireType) {
|
|
||||||
throw InvalidProtocolBufferException("Error in protocol format: \n " +
|
|
||||||
"Expected ${expectedWireType.name} type, got ${actualWireType.name}")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun readLittleEndianDouble(): Double {
|
|
||||||
val byteBuffer = ByteBuffer.wrap(readRawBytes(8))
|
|
||||||
byteBuffer.order(ByteOrder.LITTLE_ENDIAN)
|
|
||||||
return byteBuffer.getDouble(0)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun readLittleEndianFloat(): Float {
|
|
||||||
val byteBuffer = ByteBuffer.wrap(readRawBytes(4))
|
|
||||||
byteBuffer.order(ByteOrder.LITTLE_ENDIAN)
|
|
||||||
return byteBuffer.getFloat(0)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun readLittleEndianInt(): Int {
|
|
||||||
val byteBuffer = ByteBuffer.wrap(readRawBytes(8))
|
|
||||||
byteBuffer.order(ByteOrder.LITTLE_ENDIAN)
|
|
||||||
return byteBuffer.getInt(0)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun readLittleEndianLong(): Long {
|
|
||||||
val byteBuffer = ByteBuffer.wrap(readRawBytes(4))
|
|
||||||
byteBuffer.order(ByteOrder.LITTLE_ENDIAN)
|
|
||||||
return byteBuffer.getLong(0)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun readRawBytes(count: Int): ByteArray {
|
|
||||||
val ba = ByteArray(count)
|
|
||||||
for (i in 0..(count - 1)) {
|
|
||||||
ba[i] = bufferedInput.read().toByte()
|
|
||||||
}
|
|
||||||
return ba
|
|
||||||
}
|
|
||||||
|
|
||||||
// reads tag. Note that it returns 0 for the end of message!
|
|
||||||
fun readTag(expectedFieldNumber: Int, expectedWireType: WireType): Int {
|
|
||||||
if (isAtEnd()) {
|
|
||||||
return 0 // we can safely return 0 as sign of end of message, because 0-tags are illegal
|
|
||||||
}
|
|
||||||
val tag = readInt32NoTag()
|
|
||||||
if (tag == 0) { // if we somehow had read 0-tag, then message is corrupted
|
|
||||||
throw InvalidProtocolBufferException("Invalid tag 0")
|
|
||||||
}
|
|
||||||
|
|
||||||
val actualFieldNumber = WireFormat.getTagFieldNumber(tag)
|
|
||||||
val actualWireType = WireFormat.getTagWireType(tag)
|
|
||||||
checkFieldCorrectness(expectedFieldNumber, actualFieldNumber, expectedWireType, actualWireType)
|
|
||||||
return tag
|
|
||||||
}
|
|
||||||
|
|
||||||
// reads varint not larger than 32-bit integer according to protobuf varint-encoding
|
|
||||||
fun readInt32NoTag(): Int {
|
|
||||||
var done: Boolean = false
|
|
||||||
var result: Int = 0
|
|
||||||
var step: Int = 0
|
|
||||||
while (!done) {
|
|
||||||
val byte: Int = bufferedInput.read()
|
|
||||||
result = result or
|
|
||||||
(
|
|
||||||
(byte and VARINT_INFO_BITS_MASK)
|
|
||||||
shl
|
|
||||||
(VARINT_INFO_BITS_COUNT * step)
|
|
||||||
)
|
|
||||||
step++
|
|
||||||
if ((byte and VARINT_UTIL_BIT_MASK) == 0) {
|
|
||||||
done = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
// reads varint not larger than 64-bit integer according to protobuf varint-encoding
|
|
||||||
fun readInt64NoTag(): Long {
|
|
||||||
var done: Boolean = false
|
|
||||||
var result: Long = 0
|
|
||||||
var step: Int = 0
|
|
||||||
while (!done) {
|
|
||||||
val byte: Int = bufferedInput.read()
|
|
||||||
result = result or
|
|
||||||
(
|
|
||||||
(byte and VARINT_INFO_BITS_MASK).toLong()
|
|
||||||
shl
|
|
||||||
(VARINT_INFO_BITS_COUNT * step)
|
|
||||||
)
|
|
||||||
step++
|
|
||||||
if ((byte and VARINT_UTIL_BIT_MASK) == 0 || byte == -1) {
|
|
||||||
done = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
// reads zig-zag encoded integer not larger than 32-bit long
|
|
||||||
fun readZigZag32NoTag(): Int {
|
|
||||||
val value = readInt32NoTag()
|
|
||||||
return (value shr 1) xor (-(value and 1)) // bit magic for decoding zig-zag number
|
|
||||||
}
|
|
||||||
|
|
||||||
// reads zig-zag encoded integer not larger than 64-bit long
|
|
||||||
fun readZigZag64NoTag(): Long {
|
|
||||||
val value = readInt64NoTag()
|
|
||||||
return (value shr 1) xor (-(value and 1L)) // bit magic for decoding zig-zag number
|
|
||||||
}
|
|
||||||
|
|
||||||
// checks if at least one more byte can be read from underlying input stream
|
|
||||||
fun isAtEnd(): Boolean {
|
|
||||||
bufferedInput.mark(1)
|
|
||||||
val byte = bufferedInput.read()
|
|
||||||
bufferedInput.reset()
|
|
||||||
return byte == -1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,258 +0,0 @@
|
|||||||
import java.nio.ByteBuffer
|
|
||||||
import java.nio.ByteOrder
|
|
||||||
import WireFormat.VARINT_INFO_BITS_COUNT
|
|
||||||
import WireFormat.VARINT_INFO_BITS_MASK
|
|
||||||
import WireFormat.VARINT_UTIL_BIT_MASK
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by user on 7/6/16.
|
|
||||||
*/
|
|
||||||
|
|
||||||
class CodedOutputStream(val output: java.io.OutputStream) {
|
|
||||||
fun writeTag(fieldNumber: Int, type: WireType) {
|
|
||||||
val tag = (fieldNumber shl 3) or type.ordinal
|
|
||||||
writeInt32NoTag(tag)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun writeInt32(fieldNumber: Int, value: Int?) {
|
|
||||||
value ?: return
|
|
||||||
writeTag(fieldNumber, WireType.VARINT)
|
|
||||||
writeInt32NoTag(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Note that unsigned integer types are stored as their signed counterparts with top bit
|
|
||||||
// simply stored in the sign bit - similar to Java's protobuf implementation. Hence, all
|
|
||||||
// methods, writing unsigned ints simply redirect call to corresponding signed-writing method
|
|
||||||
fun writeUInt32(fieldNumber: Int, value: Int?) {
|
|
||||||
value ?: return
|
|
||||||
writeInt32(fieldNumber, value)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun writeInt64(fieldNumber: Int, value: Long?) {
|
|
||||||
value ?: return
|
|
||||||
writeTag(fieldNumber, WireType.VARINT)
|
|
||||||
writeInt64NoTag(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
// See notes on unsigned integers implementation above
|
|
||||||
fun writeUInt64(fieldNumber: Int, value: Long?) {
|
|
||||||
value ?: return
|
|
||||||
writeInt64(fieldNumber, value)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun writeBool(fieldNumber: Int, value: Boolean?) {
|
|
||||||
value ?: return
|
|
||||||
writeTag(fieldNumber, WireType.VARINT)
|
|
||||||
writeBoolNoTag(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun writeBoolNoTag(value: Boolean) {
|
|
||||||
writeInt32NoTag(if (value) 1 else 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Writing enums is like writing one int32 number. Caller is responsible for converting enum-object to ordinal
|
|
||||||
fun writeEnum(fieldNumber: Int, value: Int?) {
|
|
||||||
value ?: return
|
|
||||||
writeTag(fieldNumber, WireType.VARINT)
|
|
||||||
writeEnumNoTag(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun writeEnumNoTag(value: Int) {
|
|
||||||
writeInt32NoTag(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun writeSInt32(fieldNumber: Int, value: Int?) {
|
|
||||||
value ?: return
|
|
||||||
writeTag(fieldNumber, WireType.VARINT)
|
|
||||||
writeSInt32NoTag(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun writeSInt32NoTag(value: Int) {
|
|
||||||
writeInt32NoTag((value shl 1) xor (value shr 31))
|
|
||||||
}
|
|
||||||
|
|
||||||
fun writeSInt64(fieldNumber: Int, value: Long?) {
|
|
||||||
value ?: return
|
|
||||||
writeTag(fieldNumber, WireType.VARINT)
|
|
||||||
writeSInt64NoTag(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun writeSInt64NoTag(value: Long) {
|
|
||||||
writeInt64NoTag((value shl 1) xor (value shr 63))
|
|
||||||
}
|
|
||||||
|
|
||||||
fun writeFixed32(fieldNumber: Int, value: Int?) {
|
|
||||||
value ?: return
|
|
||||||
writeTag(fieldNumber, WireType.FIX_32)
|
|
||||||
writeFixed32NoTag(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun writeFixed32NoTag(value: Int) {
|
|
||||||
writeLittleEndian(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
// See notes on unsigned integers implementation above
|
|
||||||
fun writeSFixed32(fieldNumber: Int, value: Int?) {
|
|
||||||
value ?: return
|
|
||||||
writeTag(fieldNumber, WireType.FIX_32)
|
|
||||||
writeSFixed32NoTag(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun writeSFixed32NoTag(value: Int) {
|
|
||||||
writeLittleEndian(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun writeFixed64(fieldNumber: Int, value: Long?) {
|
|
||||||
value ?: return
|
|
||||||
writeTag(fieldNumber, WireType.FIX_64)
|
|
||||||
writeFixed64NoTag(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun writeFixed64NoTag(value: Long) {
|
|
||||||
writeLittleEndian(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
// See notes on unsigned integers implementation above
|
|
||||||
fun writeSFixed64(fieldNumber: Int, value: Long?) {
|
|
||||||
value ?: return
|
|
||||||
writeTag(fieldNumber, WireType.FIX_64)
|
|
||||||
writeSFixed64NoTag(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun writeSFixed64NoTag(value: Long) {
|
|
||||||
writeLittleEndian(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun writeDouble(fieldNumber: Int, value: Double?) {
|
|
||||||
value ?: return
|
|
||||||
writeTag(fieldNumber, WireType.FIX_64)
|
|
||||||
writeDoubleNoTag(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun writeDoubleNoTag(value: Double) {
|
|
||||||
writeLittleEndian(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun writeFloat(fieldNumber: Int, value: Float?) {
|
|
||||||
value ?: return
|
|
||||||
writeTag(fieldNumber, WireType.FIX_32)
|
|
||||||
writeFloatNoTag(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun writeFloatNoTag(value: Float) {
|
|
||||||
writeLittleEndian(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun writeString(fieldNumber: Int, value: String?) {
|
|
||||||
value ?: return
|
|
||||||
writeTag(fieldNumber, WireType.LENGTH_DELIMITED)
|
|
||||||
writeStringNoTag(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun writeStringNoTag(value: String) {
|
|
||||||
writeInt32NoTag(value.length)
|
|
||||||
output.write(value.toByteArray(Charsets.UTF_8))
|
|
||||||
}
|
|
||||||
|
|
||||||
fun writeBytes(fieldNumber: Int, value: ByteArray?) {
|
|
||||||
value ?: return
|
|
||||||
writeTag(fieldNumber, WireType.LENGTH_DELIMITED)
|
|
||||||
writeBytesNoTag(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun writeBytesNoTag(value: ByteArray) {
|
|
||||||
writeInt32NoTag(value.size)
|
|
||||||
output.write(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
/** ============ Utility methods ==================
|
|
||||||
* They are left non-private for cases when one wants to implement her/his own protocol format.
|
|
||||||
* Then she/he can re-use low-level methods for operating with raw values, that are not annotated with Protobuf tags.
|
|
||||||
*/
|
|
||||||
|
|
||||||
fun writeLittleEndian(value: Int?) {
|
|
||||||
value ?: return
|
|
||||||
val bb = ByteBuffer.allocate(4)
|
|
||||||
bb.order(ByteOrder.LITTLE_ENDIAN)
|
|
||||||
bb.putInt(value)
|
|
||||||
output.write(bb.array())
|
|
||||||
}
|
|
||||||
|
|
||||||
fun writeLittleEndian(value: Long?) {
|
|
||||||
value ?: return
|
|
||||||
val bb = ByteBuffer.allocate(8)
|
|
||||||
bb.order(ByteOrder.LITTLE_ENDIAN)
|
|
||||||
bb.putLong(value)
|
|
||||||
output.write(bb.array())
|
|
||||||
}
|
|
||||||
|
|
||||||
fun writeLittleEndian(value: Double?) {
|
|
||||||
value ?: return
|
|
||||||
val bb = ByteBuffer.allocate(8)
|
|
||||||
bb.order(ByteOrder.LITTLE_ENDIAN)
|
|
||||||
bb.putDouble(value)
|
|
||||||
output.write(bb.array())
|
|
||||||
}
|
|
||||||
|
|
||||||
fun writeLittleEndian(value: Float?) {
|
|
||||||
value ?: return
|
|
||||||
val bb = ByteBuffer.allocate(4)
|
|
||||||
bb.order(ByteOrder.LITTLE_ENDIAN)
|
|
||||||
bb.putFloat(value)
|
|
||||||
output.write(bb.array())
|
|
||||||
}
|
|
||||||
|
|
||||||
fun writeInt32NoTag(value: Int?) {
|
|
||||||
value ?: return
|
|
||||||
var curValue: Int = value
|
|
||||||
|
|
||||||
// we have at most 32 information bits. With overhead of 1 bit per 7 bits we need at most 5 bytes for encoding
|
|
||||||
val res = ByteArray(5)
|
|
||||||
|
|
||||||
var resSize = 0
|
|
||||||
do {
|
|
||||||
// encode current 7 bits
|
|
||||||
var curByte = (curValue and WireFormat.VARINT_INFO_BITS_MASK)
|
|
||||||
|
|
||||||
// discard encoded bits. Note that unsigned shift is needed for cases with negative numbers
|
|
||||||
curValue = curValue ushr VARINT_INFO_BITS_COUNT
|
|
||||||
|
|
||||||
// check if there will be next byte in encoding and set util bit if needed
|
|
||||||
if (curValue != 0) {
|
|
||||||
curByte = curByte or VARINT_UTIL_BIT_MASK
|
|
||||||
}
|
|
||||||
|
|
||||||
res[resSize] = curByte.toByte()
|
|
||||||
resSize++
|
|
||||||
} while(curValue != 0)
|
|
||||||
output.write(res, 0, resSize)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun writeInt64NoTag(value: Long?) {
|
|
||||||
value ?: return
|
|
||||||
var curValue: Long = value
|
|
||||||
|
|
||||||
// we have at most 64 information bits. With overhead of 1 bit per 7 bits we need at most 10 bytes for encoding
|
|
||||||
val res = ByteArray(10)
|
|
||||||
|
|
||||||
var resSize = 0
|
|
||||||
while(curValue != 0L) {
|
|
||||||
// encode current 7 bits
|
|
||||||
var curByte = (curValue and VARINT_INFO_BITS_MASK.toLong())
|
|
||||||
|
|
||||||
// discard encoded bits. Note that unsigned shift is needed for cases with negative numbers
|
|
||||||
curValue = curValue ushr VARINT_INFO_BITS_COUNT
|
|
||||||
|
|
||||||
// check if there will be next byte and set util bit if needed
|
|
||||||
if (curValue != 0L) {
|
|
||||||
curByte = curByte or VARINT_UTIL_BIT_MASK.toLong()
|
|
||||||
}
|
|
||||||
|
|
||||||
res[resSize] = curByte.toByte()
|
|
||||||
resSize++
|
|
||||||
}
|
|
||||||
output.write(res, 0, resSize)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
/**
|
|
||||||
* Created by user on 7/7/16.
|
|
||||||
*/
|
|
||||||
|
|
||||||
class InvalidProtocolBufferException(
|
|
||||||
override val message: String? = null,
|
|
||||||
override val cause : Throwable? = null
|
|
||||||
) : Throwable(message, cause) {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,118 +0,0 @@
|
|||||||
/**
|
|
||||||
* Created by user on 7/6/16.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
object WireFormat {
|
|
||||||
// couple of constants for magic numbers
|
|
||||||
val TAG_TYPE_BITS: Int = 3
|
|
||||||
val TAG_TYPE_MASK: Int = (1 shl TAG_TYPE_BITS) - 1
|
|
||||||
val VARINT_INFO_BITS_COUNT: Int = 7
|
|
||||||
val VARINT_INFO_BITS_MASK: Int = 0b01111111 // mask for separating lowest 7 bits, where actual information stored
|
|
||||||
val VARINT_UTIL_BIT_MASK: Int = 0b10000000 // mask for separating highest bit, that indicates next byte presence
|
|
||||||
val FIXED_32_BYTE_SIZE: Int = 4
|
|
||||||
val FIXED_64_BYTE_SIZE: Int = 8
|
|
||||||
|
|
||||||
fun getTagWireType(tag: Int): WireType {
|
|
||||||
return WireType from (tag and TAG_TYPE_MASK).toByte()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getTagFieldNumber(tag: Int): Int {
|
|
||||||
return tag ushr TAG_TYPE_BITS
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: refactor casts into function overloading as soon as translator will support it
|
|
||||||
fun getTagSize(fieldNumber: Int, wireType: WireType): Int {
|
|
||||||
return getVarint32Size((fieldNumber shl 3) or wireType.ordinal)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getVarint32Size(value: Int): Int {
|
|
||||||
var curValue = value
|
|
||||||
var size = 0
|
|
||||||
while (curValue != 0) {
|
|
||||||
size += 1
|
|
||||||
curValue = value ushr VARINT_INFO_BITS_COUNT
|
|
||||||
}
|
|
||||||
return size
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getVarint64Size(value: Long): Int {
|
|
||||||
var curValue = value
|
|
||||||
var size = 0
|
|
||||||
while (curValue != 0L) {
|
|
||||||
size += 1
|
|
||||||
curValue = value ushr VARINT_INFO_BITS_COUNT
|
|
||||||
}
|
|
||||||
return size
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getZigZag32Size(value: Int): Int {
|
|
||||||
return getVarint32Size((value shl 1) xor (value shr 31))
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getZigZag64Size(value: Long): Int {
|
|
||||||
return getVarint64Size((value shl 1) xor (value shr 63))
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getInt32Size(fieldNumber: Int, value: Int): Int {
|
|
||||||
return getTagSize(fieldNumber, WireType.VARINT) + getVarint32Size(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getUInt32Size(fieldNumber: Int, value: Int): Int {
|
|
||||||
return getInt32Size(fieldNumber, value)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getInt64Size(fieldNumber: Int, value: Long): Int {
|
|
||||||
return getTagSize(fieldNumber, WireType.VARINT) + getVarint64Size(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getUInt64Size(fieldNumber: Int, value: Long): Int {
|
|
||||||
return getInt64Size(fieldNumber, value)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getBoolSize(fieldNumber: Int, value: Boolean): Int {
|
|
||||||
val intValue = if (value) 1 else 0
|
|
||||||
return getInt32Size(fieldNumber, intValue)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getEnumSize(fieldNumber: Int, value: Int): Int {
|
|
||||||
return getInt32Size(fieldNumber, value)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getSInt32Size(fieldNumber: Int, value: Int): Int {
|
|
||||||
return getTagSize(fieldNumber, WireType.VARINT) + getZigZag32Size(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getSInt64Size(fieldNumber: Int, value: Long): Int {
|
|
||||||
return getTagSize(fieldNumber, WireType.VARINT) + getZigZag64Size(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getFixed32Size(fieldNumber: Int, value: Long): Int {
|
|
||||||
return getTagSize(fieldNumber, WireType.FIX_32) + FIXED_32_BYTE_SIZE
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getFixed64Size(fieldNumber: Int, value: Long): Int {
|
|
||||||
return getTagSize(fieldNumber, WireType.FIX_64) + FIXED_64_BYTE_SIZE
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getDoubleSize(fieldNumber: Int, value: Double): Int {
|
|
||||||
return getTagSize(fieldNumber, WireType.FIX_32) + FIXED_32_BYTE_SIZE
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getFloatSize(fieldNumber: Int, value: Float): Int {
|
|
||||||
return getTagSize(fieldNumber, WireType.FIX_64) + FIXED_64_BYTE_SIZE
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getStringSize(fieldNumber: Int, value: String): Int {
|
|
||||||
if (value.length == 0)
|
|
||||||
return 0
|
|
||||||
val encodedStringSize = value.toByteArray(Charsets.UTF_8).size //TODO: not sure if it's the best way to do it
|
|
||||||
return encodedStringSize + getTagSize(fieldNumber, WireType.LENGTH_DELIMITED) + getVarint32Size(encodedStringSize)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getBytesSize(fieldNumber: Int, value: ByteArray): Int {
|
|
||||||
if (value.size == 0)
|
|
||||||
return 0
|
|
||||||
return value.size + getTagSize(fieldNumber, WireType.LENGTH_DELIMITED) + getVarint32Size(value.size)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
/**
|
|
||||||
* Created by Dmitry Savvinov on 7/6/16.
|
|
||||||
* Enum for possible WireTypes.
|
|
||||||
* See details at [official Google reference]()https://developers.google.com/protocol-buffers/docs/encoding#structure)
|
|
||||||
*/
|
|
||||||
|
|
||||||
enum class WireType(val id: Int) {
|
|
||||||
VARINT(0), // int32, int64, uint32, uint64, sint32, sint64, bool, enum
|
|
||||||
FIX_64(1), // fixed64, sfixed64, double
|
|
||||||
LENGTH_DELIMITED(2), // string, bytes, embedded messages, packed repeated fields
|
|
||||||
START_GROUP(3), // groups (deprecated)
|
|
||||||
END_GROUP(4), // groups (deprecated)
|
|
||||||
FIX_32(5); // fixed32, sfixed32, float
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
infix fun from (value: Byte): WireType {
|
|
||||||
return when (value) {
|
|
||||||
0.toByte() -> VARINT
|
|
||||||
1.toByte() -> FIX_64
|
|
||||||
2.toByte() -> LENGTH_DELIMITED
|
|
||||||
3.toByte() -> START_GROUP
|
|
||||||
4.toByte() -> END_GROUP
|
|
||||||
5.toByte() -> FIX_32
|
|
||||||
else -> throw IllegalArgumentException()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,328 +0,0 @@
|
|||||||
class ConnectionRequest private constructor (ip: String = "", port: Int = 0) {
|
|
||||||
var ip : String
|
|
||||||
private set
|
|
||||||
|
|
||||||
var port : Int
|
|
||||||
private set
|
|
||||||
|
|
||||||
|
|
||||||
init {
|
|
||||||
this.ip = ip
|
|
||||||
this.port = port
|
|
||||||
}
|
|
||||||
|
|
||||||
fun writeTo (output: CodedOutputStream) {
|
|
||||||
if (ip != "") {
|
|
||||||
output.writeString (1, ip)
|
|
||||||
}
|
|
||||||
if (port != 0) {
|
|
||||||
output.writeInt32 (2, port)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class BuilderConnectionRequest constructor (ip: String = "", port: Int = 0) {
|
|
||||||
var ip : String
|
|
||||||
private set
|
|
||||||
fun setIp(value: String): ConnectionRequest.BuilderConnectionRequest {
|
|
||||||
ip = value
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
var port : Int
|
|
||||||
private set
|
|
||||||
fun setPort(value: Int): ConnectionRequest.BuilderConnectionRequest {
|
|
||||||
port = value
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
init {
|
|
||||||
this.ip = ip
|
|
||||||
this.port = port
|
|
||||||
}
|
|
||||||
|
|
||||||
fun writeTo (output: CodedOutputStream) {
|
|
||||||
if (ip != "") {
|
|
||||||
output.writeString (1, ip)
|
|
||||||
}
|
|
||||||
if (port != 0) {
|
|
||||||
output.writeInt32 (2, port)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun build(): ConnectionRequest {
|
|
||||||
return ConnectionRequest(ip, port)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun parseFieldFrom(input: CodedInputStream): Boolean {
|
|
||||||
if (input.isAtEnd()) { return false }
|
|
||||||
val tag = input.readInt32NoTag()
|
|
||||||
if (tag == 0) { return false }
|
|
||||||
val fieldNumber = WireFormat.getTagFieldNumber(tag)
|
|
||||||
val wireType = WireFormat.getTagWireType(tag)
|
|
||||||
when(fieldNumber) {
|
|
||||||
1 -> {
|
|
||||||
if (wireType != WireType.LENGTH_DELIMITED) {
|
|
||||||
throw InvalidProtocolBufferException("Error: Field number 1 has wire type WireType.LENGTH_DELIMITED but read ${wireType.toString()}")}
|
|
||||||
ip = input.readStringNoTag()
|
|
||||||
}
|
|
||||||
2 -> {
|
|
||||||
if (wireType != WireType.VARINT) {
|
|
||||||
throw InvalidProtocolBufferException("Error: Field number 2 has wire type WireType.VARINT but read ${wireType.toString()}")}
|
|
||||||
port = input.readInt32NoTag()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true}
|
|
||||||
fun parseFromWithSize(input: CodedInputStream, expectedSize: Int): ConnectionRequest.BuilderConnectionRequest {
|
|
||||||
while(getSizeNoTag() < expectedSize) {
|
|
||||||
parseFieldFrom(input)
|
|
||||||
}
|
|
||||||
if (getSizeNoTag() > expectedSize) { throw InvalidProtocolBufferException("Error: expected size of message $expectedSize, but have read at least ${getSizeNoTag()}") }
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
fun parseFrom(input: CodedInputStream): ConnectionRequest.BuilderConnectionRequest {
|
|
||||||
while(parseFieldFrom(input)) {}
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
fun getSize(fieldNumber: Int): Int {
|
|
||||||
var size = 0
|
|
||||||
if (ip != "") {
|
|
||||||
size += WireFormat.getStringSize(1, ip)
|
|
||||||
}
|
|
||||||
if (port != 0) {
|
|
||||||
size += WireFormat.getInt32Size(2, port)
|
|
||||||
}
|
|
||||||
size += WireFormat.getVarint32Size(size) + WireFormat.getTagSize(fieldNumber, WireType.LENGTH_DELIMITED)
|
|
||||||
return size
|
|
||||||
}
|
|
||||||
fun getSizeNoTag(): Int {
|
|
||||||
var size = 0
|
|
||||||
if (ip != "") {
|
|
||||||
size += WireFormat.getStringSize(1, ip)
|
|
||||||
}
|
|
||||||
if (port != 0) {
|
|
||||||
size += WireFormat.getInt32Size(2, port)
|
|
||||||
}
|
|
||||||
return size
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
fun mergeWith (other: ConnectionRequest) {
|
|
||||||
ip = other.ip
|
|
||||||
port = other.port
|
|
||||||
}
|
|
||||||
|
|
||||||
fun mergeFromWithSize (input: CodedInputStream, expectedSize: Int) {
|
|
||||||
val builder = ConnectionRequest.BuilderConnectionRequest()
|
|
||||||
mergeWith(builder.parseFromWithSize(input, expectedSize).build())}
|
|
||||||
|
|
||||||
fun mergeFrom (input: CodedInputStream) {
|
|
||||||
val builder = ConnectionRequest.BuilderConnectionRequest()
|
|
||||||
mergeWith(builder.parseFrom(input).build())}
|
|
||||||
fun getSize(fieldNumber: Int): Int {
|
|
||||||
var size = 0
|
|
||||||
if (ip != "") {
|
|
||||||
size += WireFormat.getStringSize(1, ip)
|
|
||||||
}
|
|
||||||
if (port != 0) {
|
|
||||||
size += WireFormat.getInt32Size(2, port)
|
|
||||||
}
|
|
||||||
size += WireFormat.getVarint32Size(size) + WireFormat.getTagSize(fieldNumber, WireType.LENGTH_DELIMITED)
|
|
||||||
return size
|
|
||||||
}
|
|
||||||
fun getSizeNoTag(): Int {
|
|
||||||
var size = 0
|
|
||||||
if (ip != "") {
|
|
||||||
size += WireFormat.getStringSize(1, ip)
|
|
||||||
}
|
|
||||||
if (port != 0) {
|
|
||||||
size += WireFormat.getInt32Size(2, port)
|
|
||||||
}
|
|
||||||
return size
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class ConnectionResponse private constructor (uid: Int = 0, code: Int = 0, errorMsg: String = "") {
|
|
||||||
var uid : Int
|
|
||||||
private set
|
|
||||||
|
|
||||||
var code : Int
|
|
||||||
private set
|
|
||||||
|
|
||||||
var errorMsg : String
|
|
||||||
private set
|
|
||||||
|
|
||||||
|
|
||||||
init {
|
|
||||||
this.uid = uid
|
|
||||||
this.code = code
|
|
||||||
this.errorMsg = errorMsg
|
|
||||||
}
|
|
||||||
|
|
||||||
fun writeTo (output: CodedOutputStream) {
|
|
||||||
if (uid != 0) {
|
|
||||||
output.writeInt32 (1, uid)
|
|
||||||
}
|
|
||||||
if (code != 0) {
|
|
||||||
output.writeInt32 (2, code)
|
|
||||||
}
|
|
||||||
if (errorMsg != "") {
|
|
||||||
output.writeString (3, errorMsg)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class BuilderConnectionResponse constructor (uid: Int = 0, code: Int = 0, errorMsg: String = "") {
|
|
||||||
var uid : Int
|
|
||||||
private set
|
|
||||||
fun setUid(value: Int): ConnectionResponse.BuilderConnectionResponse {
|
|
||||||
uid = value
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
var code : Int
|
|
||||||
private set
|
|
||||||
fun setCode(value: Int): ConnectionResponse.BuilderConnectionResponse {
|
|
||||||
code = value
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
var errorMsg : String
|
|
||||||
private set
|
|
||||||
fun setErrorMsg(value: String): ConnectionResponse.BuilderConnectionResponse {
|
|
||||||
errorMsg = value
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
init {
|
|
||||||
this.uid = uid
|
|
||||||
this.code = code
|
|
||||||
this.errorMsg = errorMsg
|
|
||||||
}
|
|
||||||
|
|
||||||
fun writeTo (output: CodedOutputStream) {
|
|
||||||
if (uid != 0) {
|
|
||||||
output.writeInt32 (1, uid)
|
|
||||||
}
|
|
||||||
if (code != 0) {
|
|
||||||
output.writeInt32 (2, code)
|
|
||||||
}
|
|
||||||
if (errorMsg != "") {
|
|
||||||
output.writeString (3, errorMsg)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun build(): ConnectionResponse {
|
|
||||||
return ConnectionResponse(uid, code, errorMsg)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun parseFieldFrom(input: CodedInputStream): Boolean {
|
|
||||||
if (input.isAtEnd()) { return false }
|
|
||||||
val tag = input.readInt32NoTag()
|
|
||||||
if (tag == 0) { return false }
|
|
||||||
val fieldNumber = WireFormat.getTagFieldNumber(tag)
|
|
||||||
val wireType = WireFormat.getTagWireType(tag)
|
|
||||||
when(fieldNumber) {
|
|
||||||
1 -> {
|
|
||||||
if (wireType != WireType.VARINT) {
|
|
||||||
throw InvalidProtocolBufferException("Error: Field number 1 has wire type WireType.VARINT but read ${wireType.toString()}")}
|
|
||||||
uid = input.readInt32NoTag()
|
|
||||||
}
|
|
||||||
2 -> {
|
|
||||||
if (wireType != WireType.VARINT) {
|
|
||||||
throw InvalidProtocolBufferException("Error: Field number 2 has wire type WireType.VARINT but read ${wireType.toString()}")}
|
|
||||||
code = input.readInt32NoTag()
|
|
||||||
}
|
|
||||||
3 -> {
|
|
||||||
if (wireType != WireType.LENGTH_DELIMITED) {
|
|
||||||
throw InvalidProtocolBufferException("Error: Field number 3 has wire type WireType.LENGTH_DELIMITED but read ${wireType.toString()}")}
|
|
||||||
errorMsg = input.readStringNoTag()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true}
|
|
||||||
fun parseFromWithSize(input: CodedInputStream, expectedSize: Int): ConnectionResponse.BuilderConnectionResponse {
|
|
||||||
while(getSizeNoTag() < expectedSize) {
|
|
||||||
parseFieldFrom(input)
|
|
||||||
}
|
|
||||||
if (getSizeNoTag() > expectedSize) { throw InvalidProtocolBufferException("Error: expected size of message $expectedSize, but have read at least ${getSizeNoTag()}") }
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
fun parseFrom(input: CodedInputStream): ConnectionResponse.BuilderConnectionResponse {
|
|
||||||
while(parseFieldFrom(input)) {}
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
fun getSize(fieldNumber: Int): Int {
|
|
||||||
var size = 0
|
|
||||||
if (uid != 0) {
|
|
||||||
size += WireFormat.getInt32Size(1, uid)
|
|
||||||
}
|
|
||||||
if (code != 0) {
|
|
||||||
size += WireFormat.getInt32Size(2, code)
|
|
||||||
}
|
|
||||||
if (errorMsg != "") {
|
|
||||||
size += WireFormat.getStringSize(3, errorMsg)
|
|
||||||
}
|
|
||||||
size += WireFormat.getVarint32Size(size) + WireFormat.getTagSize(fieldNumber, WireType.LENGTH_DELIMITED)
|
|
||||||
return size
|
|
||||||
}
|
|
||||||
fun getSizeNoTag(): Int {
|
|
||||||
var size = 0
|
|
||||||
if (uid != 0) {
|
|
||||||
size += WireFormat.getInt32Size(1, uid)
|
|
||||||
}
|
|
||||||
if (code != 0) {
|
|
||||||
size += WireFormat.getInt32Size(2, code)
|
|
||||||
}
|
|
||||||
if (errorMsg != "") {
|
|
||||||
size += WireFormat.getStringSize(3, errorMsg)
|
|
||||||
}
|
|
||||||
return size
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
fun mergeWith (other: ConnectionResponse) {
|
|
||||||
uid = other.uid
|
|
||||||
code = other.code
|
|
||||||
errorMsg = other.errorMsg
|
|
||||||
}
|
|
||||||
|
|
||||||
fun mergeFromWithSize (input: CodedInputStream, expectedSize: Int) {
|
|
||||||
val builder = ConnectionResponse.BuilderConnectionResponse()
|
|
||||||
mergeWith(builder.parseFromWithSize(input, expectedSize).build())}
|
|
||||||
|
|
||||||
fun mergeFrom (input: CodedInputStream) {
|
|
||||||
val builder = ConnectionResponse.BuilderConnectionResponse()
|
|
||||||
mergeWith(builder.parseFrom(input).build())}
|
|
||||||
fun getSize(fieldNumber: Int): Int {
|
|
||||||
var size = 0
|
|
||||||
if (uid != 0) {
|
|
||||||
size += WireFormat.getInt32Size(1, uid)
|
|
||||||
}
|
|
||||||
if (code != 0) {
|
|
||||||
size += WireFormat.getInt32Size(2, code)
|
|
||||||
}
|
|
||||||
if (errorMsg != "") {
|
|
||||||
size += WireFormat.getStringSize(3, errorMsg)
|
|
||||||
}
|
|
||||||
size += WireFormat.getVarint32Size(size) + WireFormat.getTagSize(fieldNumber, WireType.LENGTH_DELIMITED)
|
|
||||||
return size
|
|
||||||
}
|
|
||||||
fun getSizeNoTag(): Int {
|
|
||||||
var size = 0
|
|
||||||
if (uid != 0) {
|
|
||||||
size += WireFormat.getInt32Size(1, uid)
|
|
||||||
}
|
|
||||||
if (code != 0) {
|
|
||||||
size += WireFormat.getInt32Size(2, code)
|
|
||||||
}
|
|
||||||
if (errorMsg != "") {
|
|
||||||
size += WireFormat.getStringSize(3, errorMsg)
|
|
||||||
}
|
|
||||||
return size
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,312 +0,0 @@
|
|||||||
class DirectionRequest private constructor (command: DirectionRequest.Command = DirectionRequest.Command.fromIntToCommand(0), sid: Int = 0) {
|
|
||||||
var command : DirectionRequest.Command
|
|
||||||
private set
|
|
||||||
|
|
||||||
var sid : Int
|
|
||||||
private set
|
|
||||||
|
|
||||||
|
|
||||||
init {
|
|
||||||
this.command = command
|
|
||||||
this.sid = sid
|
|
||||||
}
|
|
||||||
enum class Command(val ord: Int) {
|
|
||||||
stop (0),
|
|
||||||
forward (1),
|
|
||||||
backward (2),
|
|
||||||
left (3),
|
|
||||||
right (4);
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
fun fromIntToCommand (ord: Int): Command {
|
|
||||||
return when (ord) {
|
|
||||||
0 -> Command.stop
|
|
||||||
1 -> Command.forward
|
|
||||||
2 -> Command.backward
|
|
||||||
3 -> Command.left
|
|
||||||
4 -> Command.right
|
|
||||||
else -> throw InvalidProtocolBufferException("Error: got unexpected int ${ord} while parsing Command ");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun writeTo (output: CodedOutputStream) {
|
|
||||||
if (command != DirectionRequest.Command.fromIntToCommand(0)) {
|
|
||||||
output.writeEnum (1, command.ord)
|
|
||||||
}
|
|
||||||
if (sid != 0) {
|
|
||||||
output.writeInt32 (2, sid)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class BuilderDirectionRequest constructor (command: DirectionRequest.Command = DirectionRequest.Command.fromIntToCommand(0), sid: Int = 0) {
|
|
||||||
var command : DirectionRequest.Command
|
|
||||||
private set
|
|
||||||
fun setCommand(value: DirectionRequest.Command): DirectionRequest.BuilderDirectionRequest {
|
|
||||||
command = value
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
var sid : Int
|
|
||||||
private set
|
|
||||||
fun setSid(value: Int): DirectionRequest.BuilderDirectionRequest {
|
|
||||||
sid = value
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
init {
|
|
||||||
this.command = command
|
|
||||||
this.sid = sid
|
|
||||||
}
|
|
||||||
|
|
||||||
fun writeTo (output: CodedOutputStream) {
|
|
||||||
if (command != DirectionRequest.Command.fromIntToCommand(0)) {
|
|
||||||
output.writeEnum (1, command.ord)
|
|
||||||
}
|
|
||||||
if (sid != 0) {
|
|
||||||
output.writeInt32 (2, sid)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun build(): DirectionRequest {
|
|
||||||
return DirectionRequest(command, sid)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun parseFieldFrom(input: CodedInputStream): Boolean {
|
|
||||||
if (input.isAtEnd()) { return false }
|
|
||||||
val tag = input.readInt32NoTag()
|
|
||||||
if (tag == 0) { return false }
|
|
||||||
val fieldNumber = WireFormat.getTagFieldNumber(tag)
|
|
||||||
val wireType = WireFormat.getTagWireType(tag)
|
|
||||||
when(fieldNumber) {
|
|
||||||
1 -> {
|
|
||||||
if (wireType != WireType.VARINT) {
|
|
||||||
throw InvalidProtocolBufferException("Error: Field number 1 has wire type WireType.VARINT but read ${wireType.toString()}")}
|
|
||||||
command = DirectionRequest.Command.fromIntToCommand(input.readEnumNoTag())
|
|
||||||
}
|
|
||||||
2 -> {
|
|
||||||
if (wireType != WireType.VARINT) {
|
|
||||||
throw InvalidProtocolBufferException("Error: Field number 2 has wire type WireType.VARINT but read ${wireType.toString()}")}
|
|
||||||
sid = input.readInt32NoTag()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true}
|
|
||||||
fun parseFromWithSize(input: CodedInputStream, expectedSize: Int): DirectionRequest.BuilderDirectionRequest {
|
|
||||||
while(getSizeNoTag() < expectedSize) {
|
|
||||||
parseFieldFrom(input)
|
|
||||||
}
|
|
||||||
if (getSizeNoTag() > expectedSize) { throw InvalidProtocolBufferException("Error: expected size of message $expectedSize, but have read at least ${getSizeNoTag()}") }
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
fun parseFrom(input: CodedInputStream): DirectionRequest.BuilderDirectionRequest {
|
|
||||||
while(parseFieldFrom(input)) {}
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
fun getSize(fieldNumber: Int): Int {
|
|
||||||
var size = 0
|
|
||||||
if (command != DirectionRequest.Command.fromIntToCommand(0)) {
|
|
||||||
size += WireFormat.getEnumSize(1, command.ord)
|
|
||||||
}
|
|
||||||
if (sid != 0) {
|
|
||||||
size += WireFormat.getInt32Size(2, sid)
|
|
||||||
}
|
|
||||||
size += WireFormat.getVarint32Size(size) + WireFormat.getTagSize(fieldNumber, WireType.LENGTH_DELIMITED)
|
|
||||||
return size
|
|
||||||
}
|
|
||||||
fun getSizeNoTag(): Int {
|
|
||||||
var size = 0
|
|
||||||
if (command != DirectionRequest.Command.fromIntToCommand(0)) {
|
|
||||||
size += WireFormat.getEnumSize(1, command.ord)
|
|
||||||
}
|
|
||||||
if (sid != 0) {
|
|
||||||
size += WireFormat.getInt32Size(2, sid)
|
|
||||||
}
|
|
||||||
return size
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
fun mergeWith (other: DirectionRequest) {
|
|
||||||
command = other.command
|
|
||||||
sid = other.sid
|
|
||||||
}
|
|
||||||
|
|
||||||
fun mergeFromWithSize (input: CodedInputStream, expectedSize: Int) {
|
|
||||||
val builder = DirectionRequest.BuilderDirectionRequest()
|
|
||||||
mergeWith(builder.parseFromWithSize(input, expectedSize).build())}
|
|
||||||
|
|
||||||
fun mergeFrom (input: CodedInputStream) {
|
|
||||||
val builder = DirectionRequest.BuilderDirectionRequest()
|
|
||||||
mergeWith(builder.parseFrom(input).build())}
|
|
||||||
fun getSize(fieldNumber: Int): Int {
|
|
||||||
var size = 0
|
|
||||||
if (command != DirectionRequest.Command.fromIntToCommand(0)) {
|
|
||||||
size += WireFormat.getEnumSize(1, command.ord)
|
|
||||||
}
|
|
||||||
if (sid != 0) {
|
|
||||||
size += WireFormat.getInt32Size(2, sid)
|
|
||||||
}
|
|
||||||
size += WireFormat.getVarint32Size(size) + WireFormat.getTagSize(fieldNumber, WireType.LENGTH_DELIMITED)
|
|
||||||
return size
|
|
||||||
}
|
|
||||||
fun getSizeNoTag(): Int {
|
|
||||||
var size = 0
|
|
||||||
if (command != DirectionRequest.Command.fromIntToCommand(0)) {
|
|
||||||
size += WireFormat.getEnumSize(1, command.ord)
|
|
||||||
}
|
|
||||||
if (sid != 0) {
|
|
||||||
size += WireFormat.getInt32Size(2, sid)
|
|
||||||
}
|
|
||||||
return size
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class DirectionResponse private constructor (code: Int = 0, errorMsg: String = "") {
|
|
||||||
var code : Int
|
|
||||||
private set
|
|
||||||
|
|
||||||
var errorMsg : String
|
|
||||||
private set
|
|
||||||
|
|
||||||
|
|
||||||
init {
|
|
||||||
this.code = code
|
|
||||||
this.errorMsg = errorMsg
|
|
||||||
}
|
|
||||||
|
|
||||||
fun writeTo (output: CodedOutputStream) {
|
|
||||||
if (code != 0) {
|
|
||||||
output.writeInt32 (1, code)
|
|
||||||
}
|
|
||||||
if (errorMsg != "") {
|
|
||||||
output.writeString (2, errorMsg)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class BuilderDirectionResponse constructor (code: Int = 0, errorMsg: String = "") {
|
|
||||||
var code : Int
|
|
||||||
private set
|
|
||||||
fun setCode(value: Int): DirectionResponse.BuilderDirectionResponse {
|
|
||||||
code = value
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
var errorMsg : String
|
|
||||||
private set
|
|
||||||
fun setErrorMsg(value: String): DirectionResponse.BuilderDirectionResponse {
|
|
||||||
errorMsg = value
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
init {
|
|
||||||
this.code = code
|
|
||||||
this.errorMsg = errorMsg
|
|
||||||
}
|
|
||||||
|
|
||||||
fun writeTo (output: CodedOutputStream) {
|
|
||||||
if (code != 0) {
|
|
||||||
output.writeInt32 (1, code)
|
|
||||||
}
|
|
||||||
if (errorMsg != "") {
|
|
||||||
output.writeString (2, errorMsg)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun build(): DirectionResponse {
|
|
||||||
return DirectionResponse(code, errorMsg)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun parseFieldFrom(input: CodedInputStream): Boolean {
|
|
||||||
if (input.isAtEnd()) { return false }
|
|
||||||
val tag = input.readInt32NoTag()
|
|
||||||
if (tag == 0) { return false }
|
|
||||||
val fieldNumber = WireFormat.getTagFieldNumber(tag)
|
|
||||||
val wireType = WireFormat.getTagWireType(tag)
|
|
||||||
when(fieldNumber) {
|
|
||||||
1 -> {
|
|
||||||
if (wireType != WireType.VARINT) {
|
|
||||||
throw InvalidProtocolBufferException("Error: Field number 1 has wire type WireType.VARINT but read ${wireType.toString()}")}
|
|
||||||
code = input.readInt32NoTag()
|
|
||||||
}
|
|
||||||
2 -> {
|
|
||||||
if (wireType != WireType.LENGTH_DELIMITED) {
|
|
||||||
throw InvalidProtocolBufferException("Error: Field number 2 has wire type WireType.LENGTH_DELIMITED but read ${wireType.toString()}")}
|
|
||||||
errorMsg = input.readStringNoTag()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true}
|
|
||||||
fun parseFromWithSize(input: CodedInputStream, expectedSize: Int): DirectionResponse.BuilderDirectionResponse {
|
|
||||||
while(getSizeNoTag() < expectedSize) {
|
|
||||||
parseFieldFrom(input)
|
|
||||||
}
|
|
||||||
if (getSizeNoTag() > expectedSize) { throw InvalidProtocolBufferException("Error: expected size of message $expectedSize, but have read at least ${getSizeNoTag()}") }
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
fun parseFrom(input: CodedInputStream): DirectionResponse.BuilderDirectionResponse {
|
|
||||||
while(parseFieldFrom(input)) {}
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
fun getSize(fieldNumber: Int): Int {
|
|
||||||
var size = 0
|
|
||||||
if (code != 0) {
|
|
||||||
size += WireFormat.getInt32Size(1, code)
|
|
||||||
}
|
|
||||||
if (errorMsg != "") {
|
|
||||||
size += WireFormat.getStringSize(2, errorMsg)
|
|
||||||
}
|
|
||||||
size += WireFormat.getVarint32Size(size) + WireFormat.getTagSize(fieldNumber, WireType.LENGTH_DELIMITED)
|
|
||||||
return size
|
|
||||||
}
|
|
||||||
fun getSizeNoTag(): Int {
|
|
||||||
var size = 0
|
|
||||||
if (code != 0) {
|
|
||||||
size += WireFormat.getInt32Size(1, code)
|
|
||||||
}
|
|
||||||
if (errorMsg != "") {
|
|
||||||
size += WireFormat.getStringSize(2, errorMsg)
|
|
||||||
}
|
|
||||||
return size
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
fun mergeWith (other: DirectionResponse) {
|
|
||||||
code = other.code
|
|
||||||
errorMsg = other.errorMsg
|
|
||||||
}
|
|
||||||
|
|
||||||
fun mergeFromWithSize (input: CodedInputStream, expectedSize: Int) {
|
|
||||||
val builder = DirectionResponse.BuilderDirectionResponse()
|
|
||||||
mergeWith(builder.parseFromWithSize(input, expectedSize).build())}
|
|
||||||
|
|
||||||
fun mergeFrom (input: CodedInputStream) {
|
|
||||||
val builder = DirectionResponse.BuilderDirectionResponse()
|
|
||||||
mergeWith(builder.parseFrom(input).build())}
|
|
||||||
fun getSize(fieldNumber: Int): Int {
|
|
||||||
var size = 0
|
|
||||||
if (code != 0) {
|
|
||||||
size += WireFormat.getInt32Size(1, code)
|
|
||||||
}
|
|
||||||
if (errorMsg != "") {
|
|
||||||
size += WireFormat.getStringSize(2, errorMsg)
|
|
||||||
}
|
|
||||||
size += WireFormat.getVarint32Size(size) + WireFormat.getTagSize(fieldNumber, WireType.LENGTH_DELIMITED)
|
|
||||||
return size
|
|
||||||
}
|
|
||||||
fun getSizeNoTag(): Int {
|
|
||||||
var size = 0
|
|
||||||
if (code != 0) {
|
|
||||||
size += WireFormat.getInt32Size(1, code)
|
|
||||||
}
|
|
||||||
if (errorMsg != "") {
|
|
||||||
size += WireFormat.getStringSize(2, errorMsg)
|
|
||||||
}
|
|
||||||
return size
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,371 +0,0 @@
|
|||||||
class LocationResponse private constructor (locationResponseData: LocationResponse.LocationData = LocationResponse.LocationData.BuilderLocationData().build(), code: Int = 0, errorMsg: String = "") {
|
|
||||||
var locationResponseData : LocationResponse.LocationData
|
|
||||||
private set
|
|
||||||
|
|
||||||
var code : Int
|
|
||||||
private set
|
|
||||||
|
|
||||||
var errorMsg : String
|
|
||||||
private set
|
|
||||||
|
|
||||||
|
|
||||||
init {
|
|
||||||
this.locationResponseData = locationResponseData
|
|
||||||
this.code = code
|
|
||||||
this.errorMsg = errorMsg
|
|
||||||
}
|
|
||||||
class LocationData private constructor (x: Double = 0.0, y: Double = 0.0, angle: Double = 0.0) {
|
|
||||||
var x : Double
|
|
||||||
private set
|
|
||||||
|
|
||||||
var y : Double
|
|
||||||
private set
|
|
||||||
|
|
||||||
var angle : Double
|
|
||||||
private set
|
|
||||||
|
|
||||||
|
|
||||||
init {
|
|
||||||
this.x = x
|
|
||||||
this.y = y
|
|
||||||
this.angle = angle
|
|
||||||
}
|
|
||||||
|
|
||||||
fun writeTo (output: CodedOutputStream) {
|
|
||||||
if (x != 0.0) {
|
|
||||||
output.writeDouble (1, x)
|
|
||||||
}
|
|
||||||
if (y != 0.0) {
|
|
||||||
output.writeDouble (2, y)
|
|
||||||
}
|
|
||||||
if (angle != 0.0) {
|
|
||||||
output.writeDouble (3, angle)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class BuilderLocationData constructor (x: Double = 0.0, y: Double = 0.0, angle: Double = 0.0) {
|
|
||||||
var x : Double
|
|
||||||
private set
|
|
||||||
fun setX(value: Double): LocationResponse.LocationData.BuilderLocationData {
|
|
||||||
x = value
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
var y : Double
|
|
||||||
private set
|
|
||||||
fun setY(value: Double): LocationResponse.LocationData.BuilderLocationData {
|
|
||||||
y = value
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
var angle : Double
|
|
||||||
private set
|
|
||||||
fun setAngle(value: Double): LocationResponse.LocationData.BuilderLocationData {
|
|
||||||
angle = value
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
init {
|
|
||||||
this.x = x
|
|
||||||
this.y = y
|
|
||||||
this.angle = angle
|
|
||||||
}
|
|
||||||
|
|
||||||
fun writeTo (output: CodedOutputStream) {
|
|
||||||
if (x != 0.0) {
|
|
||||||
output.writeDouble (1, x)
|
|
||||||
}
|
|
||||||
if (y != 0.0) {
|
|
||||||
output.writeDouble (2, y)
|
|
||||||
}
|
|
||||||
if (angle != 0.0) {
|
|
||||||
output.writeDouble (3, angle)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun build(): LocationResponse.LocationData {
|
|
||||||
return LocationResponse.LocationData(x, y, angle)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun parseFieldFrom(input: CodedInputStream): Boolean {
|
|
||||||
if (input.isAtEnd()) { return false }
|
|
||||||
val tag = input.readInt32NoTag()
|
|
||||||
if (tag == 0) { return false }
|
|
||||||
val fieldNumber = WireFormat.getTagFieldNumber(tag)
|
|
||||||
val wireType = WireFormat.getTagWireType(tag)
|
|
||||||
when(fieldNumber) {
|
|
||||||
1 -> {
|
|
||||||
if (wireType != WireType.FIX_64) {
|
|
||||||
throw InvalidProtocolBufferException("Error: Field number 1 has wire type WireType.FIX_64 but read ${wireType.toString()}")}
|
|
||||||
x = input.readDoubleNoTag()
|
|
||||||
}
|
|
||||||
2 -> {
|
|
||||||
if (wireType != WireType.FIX_64) {
|
|
||||||
throw InvalidProtocolBufferException("Error: Field number 2 has wire type WireType.FIX_64 but read ${wireType.toString()}")}
|
|
||||||
y = input.readDoubleNoTag()
|
|
||||||
}
|
|
||||||
3 -> {
|
|
||||||
if (wireType != WireType.FIX_64) {
|
|
||||||
throw InvalidProtocolBufferException("Error: Field number 3 has wire type WireType.FIX_64 but read ${wireType.toString()}")}
|
|
||||||
angle = input.readDoubleNoTag()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true}
|
|
||||||
fun parseFromWithSize(input: CodedInputStream, expectedSize: Int): LocationResponse.LocationData.BuilderLocationData {
|
|
||||||
while(getSizeNoTag() < expectedSize) {
|
|
||||||
parseFieldFrom(input)
|
|
||||||
}
|
|
||||||
if (getSizeNoTag() > expectedSize) { throw InvalidProtocolBufferException("Error: expected size of message $expectedSize, but have read at least ${getSizeNoTag()}") }
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
fun parseFrom(input: CodedInputStream): LocationResponse.LocationData.BuilderLocationData {
|
|
||||||
while(parseFieldFrom(input)) {}
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
fun getSize(fieldNumber: Int): Int {
|
|
||||||
var size = 0
|
|
||||||
if (x != 0.0) {
|
|
||||||
size += WireFormat.getDoubleSize(1, x)
|
|
||||||
}
|
|
||||||
if (y != 0.0) {
|
|
||||||
size += WireFormat.getDoubleSize(2, y)
|
|
||||||
}
|
|
||||||
if (angle != 0.0) {
|
|
||||||
size += WireFormat.getDoubleSize(3, angle)
|
|
||||||
}
|
|
||||||
size += WireFormat.getVarint32Size(size) + WireFormat.getTagSize(fieldNumber, WireType.LENGTH_DELIMITED)
|
|
||||||
return size
|
|
||||||
}
|
|
||||||
fun getSizeNoTag(): Int {
|
|
||||||
var size = 0
|
|
||||||
if (x != 0.0) {
|
|
||||||
size += WireFormat.getDoubleSize(1, x)
|
|
||||||
}
|
|
||||||
if (y != 0.0) {
|
|
||||||
size += WireFormat.getDoubleSize(2, y)
|
|
||||||
}
|
|
||||||
if (angle != 0.0) {
|
|
||||||
size += WireFormat.getDoubleSize(3, angle)
|
|
||||||
}
|
|
||||||
return size
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
fun mergeWith (other: LocationResponse.LocationData) {
|
|
||||||
x = other.x
|
|
||||||
y = other.y
|
|
||||||
angle = other.angle
|
|
||||||
}
|
|
||||||
|
|
||||||
fun mergeFromWithSize (input: CodedInputStream, expectedSize: Int) {
|
|
||||||
val builder = LocationResponse.LocationData.BuilderLocationData()
|
|
||||||
mergeWith(builder.parseFromWithSize(input, expectedSize).build())}
|
|
||||||
|
|
||||||
fun mergeFrom (input: CodedInputStream) {
|
|
||||||
val builder = LocationResponse.LocationData.BuilderLocationData()
|
|
||||||
mergeWith(builder.parseFrom(input).build())}
|
|
||||||
fun getSize(fieldNumber: Int): Int {
|
|
||||||
var size = 0
|
|
||||||
if (x != 0.0) {
|
|
||||||
size += WireFormat.getDoubleSize(1, x)
|
|
||||||
}
|
|
||||||
if (y != 0.0) {
|
|
||||||
size += WireFormat.getDoubleSize(2, y)
|
|
||||||
}
|
|
||||||
if (angle != 0.0) {
|
|
||||||
size += WireFormat.getDoubleSize(3, angle)
|
|
||||||
}
|
|
||||||
size += WireFormat.getVarint32Size(size) + WireFormat.getTagSize(fieldNumber, WireType.LENGTH_DELIMITED)
|
|
||||||
return size
|
|
||||||
}
|
|
||||||
fun getSizeNoTag(): Int {
|
|
||||||
var size = 0
|
|
||||||
if (x != 0.0) {
|
|
||||||
size += WireFormat.getDoubleSize(1, x)
|
|
||||||
}
|
|
||||||
if (y != 0.0) {
|
|
||||||
size += WireFormat.getDoubleSize(2, y)
|
|
||||||
}
|
|
||||||
if (angle != 0.0) {
|
|
||||||
size += WireFormat.getDoubleSize(3, angle)
|
|
||||||
}
|
|
||||||
return size
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
fun writeTo (output: CodedOutputStream) {
|
|
||||||
if (locationResponseData != LocationResponse.LocationData.BuilderLocationData().build()) {
|
|
||||||
output.writeTag(1, WireType.LENGTH_DELIMITED)
|
|
||||||
output.writeInt32NoTag(locationResponseData.getSizeNoTag())
|
|
||||||
locationResponseData.writeTo(output)
|
|
||||||
}
|
|
||||||
if (code != 0) {
|
|
||||||
output.writeInt32 (2, code)
|
|
||||||
}
|
|
||||||
if (errorMsg != "") {
|
|
||||||
output.writeString (3, errorMsg)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class BuilderLocationResponse constructor (locationResponseData: LocationResponse.LocationData = LocationResponse.LocationData.BuilderLocationData().build(), code: Int = 0, errorMsg: String = "") {
|
|
||||||
var locationResponseData : LocationResponse.LocationData
|
|
||||||
private set
|
|
||||||
fun setLocationResponseData(value: LocationResponse.LocationData): LocationResponse.BuilderLocationResponse {
|
|
||||||
locationResponseData = value
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
var code : Int
|
|
||||||
private set
|
|
||||||
fun setCode(value: Int): LocationResponse.BuilderLocationResponse {
|
|
||||||
code = value
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
var errorMsg : String
|
|
||||||
private set
|
|
||||||
fun setErrorMsg(value: String): LocationResponse.BuilderLocationResponse {
|
|
||||||
errorMsg = value
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
init {
|
|
||||||
this.locationResponseData = locationResponseData
|
|
||||||
this.code = code
|
|
||||||
this.errorMsg = errorMsg
|
|
||||||
}
|
|
||||||
|
|
||||||
fun writeTo (output: CodedOutputStream) {
|
|
||||||
if (locationResponseData != LocationResponse.LocationData.BuilderLocationData().build()) {
|
|
||||||
output.writeTag(1, WireType.LENGTH_DELIMITED)
|
|
||||||
output.writeInt32NoTag(locationResponseData.getSizeNoTag())
|
|
||||||
locationResponseData.writeTo(output)
|
|
||||||
}
|
|
||||||
if (code != 0) {
|
|
||||||
output.writeInt32 (2, code)
|
|
||||||
}
|
|
||||||
if (errorMsg != "") {
|
|
||||||
output.writeString (3, errorMsg)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun build(): LocationResponse {
|
|
||||||
return LocationResponse(locationResponseData, code, errorMsg)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun parseFieldFrom(input: CodedInputStream): Boolean {
|
|
||||||
if (input.isAtEnd()) { return false }
|
|
||||||
val tag = input.readInt32NoTag()
|
|
||||||
if (tag == 0) { return false }
|
|
||||||
val fieldNumber = WireFormat.getTagFieldNumber(tag)
|
|
||||||
val wireType = WireFormat.getTagWireType(tag)
|
|
||||||
when(fieldNumber) {
|
|
||||||
1 -> {
|
|
||||||
if (wireType != WireType.LENGTH_DELIMITED) {
|
|
||||||
throw InvalidProtocolBufferException("Error: Field number 1 has wire type WireType.LENGTH_DELIMITED but read ${wireType.toString()}")}
|
|
||||||
run {
|
|
||||||
val expectedSize = input.readInt32NoTag()
|
|
||||||
locationResponseData.mergeFromWithSize(input, expectedSize)
|
|
||||||
if (expectedSize != locationResponseData.getSizeNoTag()) { throw InvalidProtocolBufferException ("Expected size ${expectedSize} got ${locationResponseData.getSizeNoTag()}") }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
2 -> {
|
|
||||||
if (wireType != WireType.VARINT) {
|
|
||||||
throw InvalidProtocolBufferException("Error: Field number 2 has wire type WireType.VARINT but read ${wireType.toString()}")}
|
|
||||||
code = input.readInt32NoTag()
|
|
||||||
}
|
|
||||||
3 -> {
|
|
||||||
if (wireType != WireType.LENGTH_DELIMITED) {
|
|
||||||
throw InvalidProtocolBufferException("Error: Field number 3 has wire type WireType.LENGTH_DELIMITED but read ${wireType.toString()}")}
|
|
||||||
errorMsg = input.readStringNoTag()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true}
|
|
||||||
fun parseFromWithSize(input: CodedInputStream, expectedSize: Int): LocationResponse.BuilderLocationResponse {
|
|
||||||
while(getSizeNoTag() < expectedSize) {
|
|
||||||
parseFieldFrom(input)
|
|
||||||
}
|
|
||||||
if (getSizeNoTag() > expectedSize) { throw InvalidProtocolBufferException("Error: expected size of message $expectedSize, but have read at least ${getSizeNoTag()}") }
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
fun parseFrom(input: CodedInputStream): LocationResponse.BuilderLocationResponse {
|
|
||||||
while(parseFieldFrom(input)) {}
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
fun getSize(fieldNumber: Int): Int {
|
|
||||||
var size = 0
|
|
||||||
if (locationResponseData != LocationResponse.LocationData.BuilderLocationData().build()) {
|
|
||||||
size += locationResponseData.getSize(1)
|
|
||||||
}
|
|
||||||
if (code != 0) {
|
|
||||||
size += WireFormat.getInt32Size(2, code)
|
|
||||||
}
|
|
||||||
if (errorMsg != "") {
|
|
||||||
size += WireFormat.getStringSize(3, errorMsg)
|
|
||||||
}
|
|
||||||
size += WireFormat.getVarint32Size(size) + WireFormat.getTagSize(fieldNumber, WireType.LENGTH_DELIMITED)
|
|
||||||
return size
|
|
||||||
}
|
|
||||||
fun getSizeNoTag(): Int {
|
|
||||||
var size = 0
|
|
||||||
if (locationResponseData != LocationResponse.LocationData.BuilderLocationData().build()) {
|
|
||||||
size += locationResponseData.getSize(1)
|
|
||||||
}
|
|
||||||
if (code != 0) {
|
|
||||||
size += WireFormat.getInt32Size(2, code)
|
|
||||||
}
|
|
||||||
if (errorMsg != "") {
|
|
||||||
size += WireFormat.getStringSize(3, errorMsg)
|
|
||||||
}
|
|
||||||
return size
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
fun mergeWith (other: LocationResponse) {
|
|
||||||
locationResponseData = other.locationResponseData
|
|
||||||
code = other.code
|
|
||||||
errorMsg = other.errorMsg
|
|
||||||
}
|
|
||||||
|
|
||||||
fun mergeFromWithSize (input: CodedInputStream, expectedSize: Int) {
|
|
||||||
val builder = LocationResponse.BuilderLocationResponse()
|
|
||||||
mergeWith(builder.parseFromWithSize(input, expectedSize).build())}
|
|
||||||
|
|
||||||
fun mergeFrom (input: CodedInputStream) {
|
|
||||||
val builder = LocationResponse.BuilderLocationResponse()
|
|
||||||
mergeWith(builder.parseFrom(input).build())}
|
|
||||||
fun getSize(fieldNumber: Int): Int {
|
|
||||||
var size = 0
|
|
||||||
if (locationResponseData != LocationResponse.LocationData.BuilderLocationData().build()) {
|
|
||||||
size += locationResponseData.getSize(1)
|
|
||||||
}
|
|
||||||
if (code != 0) {
|
|
||||||
size += WireFormat.getInt32Size(2, code)
|
|
||||||
}
|
|
||||||
if (errorMsg != "") {
|
|
||||||
size += WireFormat.getStringSize(3, errorMsg)
|
|
||||||
}
|
|
||||||
size += WireFormat.getVarint32Size(size) + WireFormat.getTagSize(fieldNumber, WireType.LENGTH_DELIMITED)
|
|
||||||
return size
|
|
||||||
}
|
|
||||||
fun getSizeNoTag(): Int {
|
|
||||||
var size = 0
|
|
||||||
if (locationResponseData != LocationResponse.LocationData.BuilderLocationData().build()) {
|
|
||||||
size += locationResponseData.getSize(1)
|
|
||||||
}
|
|
||||||
if (code != 0) {
|
|
||||||
size += WireFormat.getInt32Size(2, code)
|
|
||||||
}
|
|
||||||
if (errorMsg != "") {
|
|
||||||
size += WireFormat.getStringSize(3, errorMsg)
|
|
||||||
}
|
|
||||||
return size
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,469 +0,0 @@
|
|||||||
class RouteRequest private constructor (way_points: MutableList <RouteRequest.WayPoint> = mutableListOf()) {
|
|
||||||
var way_points : MutableList <RouteRequest.WayPoint>
|
|
||||||
private set
|
|
||||||
|
|
||||||
|
|
||||||
init {
|
|
||||||
this.way_points = way_points
|
|
||||||
}
|
|
||||||
class WayPoint private constructor (distance: Double = 0.0, angle_delta: Double = 0.0) {
|
|
||||||
var distance : Double
|
|
||||||
private set
|
|
||||||
|
|
||||||
var angle_delta : Double
|
|
||||||
private set
|
|
||||||
|
|
||||||
|
|
||||||
init {
|
|
||||||
this.distance = distance
|
|
||||||
this.angle_delta = angle_delta
|
|
||||||
}
|
|
||||||
|
|
||||||
fun writeTo (output: CodedOutputStream) {
|
|
||||||
if (distance != 0.0) {
|
|
||||||
output.writeDouble (2, distance)
|
|
||||||
}
|
|
||||||
if (angle_delta != 0.0) {
|
|
||||||
output.writeDouble (3, angle_delta)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class BuilderWayPoint constructor (distance: Double = 0.0, angle_delta: Double = 0.0) {
|
|
||||||
var distance : Double
|
|
||||||
private set
|
|
||||||
fun setDistance(value: Double): RouteRequest.WayPoint.BuilderWayPoint {
|
|
||||||
distance = value
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
var angle_delta : Double
|
|
||||||
private set
|
|
||||||
fun setAngle_delta(value: Double): RouteRequest.WayPoint.BuilderWayPoint {
|
|
||||||
angle_delta = value
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
init {
|
|
||||||
this.distance = distance
|
|
||||||
this.angle_delta = angle_delta
|
|
||||||
}
|
|
||||||
|
|
||||||
fun writeTo (output: CodedOutputStream) {
|
|
||||||
if (distance != 0.0) {
|
|
||||||
output.writeDouble (2, distance)
|
|
||||||
}
|
|
||||||
if (angle_delta != 0.0) {
|
|
||||||
output.writeDouble (3, angle_delta)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun build(): RouteRequest.WayPoint {
|
|
||||||
return RouteRequest.WayPoint(distance, angle_delta)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun parseFieldFrom(input: CodedInputStream): Boolean {
|
|
||||||
if (input.isAtEnd()) { return false }
|
|
||||||
val tag = input.readInt32NoTag()
|
|
||||||
if (tag == 0) { return false }
|
|
||||||
val fieldNumber = WireFormat.getTagFieldNumber(tag)
|
|
||||||
val wireType = WireFormat.getTagWireType(tag)
|
|
||||||
when(fieldNumber) {
|
|
||||||
2 -> {
|
|
||||||
if (wireType != WireType.FIX_64) {
|
|
||||||
throw InvalidProtocolBufferException("Error: Field number 2 has wire type WireType.FIX_64 but read ${wireType.toString()}")}
|
|
||||||
distance = input.readDoubleNoTag()
|
|
||||||
}
|
|
||||||
3 -> {
|
|
||||||
if (wireType != WireType.FIX_64) {
|
|
||||||
throw InvalidProtocolBufferException("Error: Field number 3 has wire type WireType.FIX_64 but read ${wireType.toString()}")}
|
|
||||||
angle_delta = input.readDoubleNoTag()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true}
|
|
||||||
fun parseFromWithSize(input: CodedInputStream, expectedSize: Int): RouteRequest.WayPoint.BuilderWayPoint {
|
|
||||||
while(getSizeNoTag() < expectedSize) {
|
|
||||||
parseFieldFrom(input)
|
|
||||||
}
|
|
||||||
if (getSizeNoTag() > expectedSize) { throw InvalidProtocolBufferException("Error: expected size of message $expectedSize, but have read at least ${getSizeNoTag()}") }
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
fun parseFrom(input: CodedInputStream): RouteRequest.WayPoint.BuilderWayPoint {
|
|
||||||
while(parseFieldFrom(input)) {}
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
fun getSize(fieldNumber: Int): Int {
|
|
||||||
var size = 0
|
|
||||||
if (distance != 0.0) {
|
|
||||||
size += WireFormat.getDoubleSize(2, distance)
|
|
||||||
}
|
|
||||||
if (angle_delta != 0.0) {
|
|
||||||
size += WireFormat.getDoubleSize(3, angle_delta)
|
|
||||||
}
|
|
||||||
size += WireFormat.getVarint32Size(size) + WireFormat.getTagSize(fieldNumber, WireType.LENGTH_DELIMITED)
|
|
||||||
return size
|
|
||||||
}
|
|
||||||
fun getSizeNoTag(): Int {
|
|
||||||
var size = 0
|
|
||||||
if (distance != 0.0) {
|
|
||||||
size += WireFormat.getDoubleSize(2, distance)
|
|
||||||
}
|
|
||||||
if (angle_delta != 0.0) {
|
|
||||||
size += WireFormat.getDoubleSize(3, angle_delta)
|
|
||||||
}
|
|
||||||
return size
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
fun mergeWith (other: RouteRequest.WayPoint) {
|
|
||||||
distance = other.distance
|
|
||||||
angle_delta = other.angle_delta
|
|
||||||
}
|
|
||||||
|
|
||||||
fun mergeFromWithSize (input: CodedInputStream, expectedSize: Int) {
|
|
||||||
val builder = RouteRequest.WayPoint.BuilderWayPoint()
|
|
||||||
mergeWith(builder.parseFromWithSize(input, expectedSize).build())}
|
|
||||||
|
|
||||||
fun mergeFrom (input: CodedInputStream) {
|
|
||||||
val builder = RouteRequest.WayPoint.BuilderWayPoint()
|
|
||||||
mergeWith(builder.parseFrom(input).build())}
|
|
||||||
fun getSize(fieldNumber: Int): Int {
|
|
||||||
var size = 0
|
|
||||||
if (distance != 0.0) {
|
|
||||||
size += WireFormat.getDoubleSize(2, distance)
|
|
||||||
}
|
|
||||||
if (angle_delta != 0.0) {
|
|
||||||
size += WireFormat.getDoubleSize(3, angle_delta)
|
|
||||||
}
|
|
||||||
size += WireFormat.getVarint32Size(size) + WireFormat.getTagSize(fieldNumber, WireType.LENGTH_DELIMITED)
|
|
||||||
return size
|
|
||||||
}
|
|
||||||
fun getSizeNoTag(): Int {
|
|
||||||
var size = 0
|
|
||||||
if (distance != 0.0) {
|
|
||||||
size += WireFormat.getDoubleSize(2, distance)
|
|
||||||
}
|
|
||||||
if (angle_delta != 0.0) {
|
|
||||||
size += WireFormat.getDoubleSize(3, angle_delta)
|
|
||||||
}
|
|
||||||
return size
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
fun writeTo (output: CodedOutputStream) {
|
|
||||||
if (way_points.size > 0) {
|
|
||||||
for (item in way_points) {
|
|
||||||
if (item != RouteRequest.WayPoint.BuilderWayPoint().build()) {
|
|
||||||
output.writeTag(1, WireType.LENGTH_DELIMITED)
|
|
||||||
output.writeInt32NoTag(item.getSizeNoTag())
|
|
||||||
item.writeTo(output)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class BuilderRouteRequest constructor (way_points: MutableList <RouteRequest.WayPoint> = mutableListOf()) {
|
|
||||||
var way_points : MutableList <RouteRequest.WayPoint>
|
|
||||||
private set
|
|
||||||
fun setWay_points(value: MutableList <RouteRequest.WayPoint>): RouteRequest.BuilderRouteRequest {
|
|
||||||
way_points = value
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
fun setWayPoint(index: Int, value: WayPoint): RouteRequest.BuilderRouteRequest {
|
|
||||||
way_points[index] = value
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
fun addWayPoint(value: WayPoint): RouteRequest.BuilderRouteRequest {
|
|
||||||
way_points.add(value)
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
fun addAllWayPoint(value: Iterable<WayPoint>): RouteRequest.BuilderRouteRequest {
|
|
||||||
for (item in value) {
|
|
||||||
way_points.add(item)
|
|
||||||
}
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
init {
|
|
||||||
this.way_points = way_points
|
|
||||||
}
|
|
||||||
|
|
||||||
fun writeTo (output: CodedOutputStream) {
|
|
||||||
if (way_points.size > 0) {
|
|
||||||
for (item in way_points) {
|
|
||||||
if (item != RouteRequest.WayPoint.BuilderWayPoint().build()) {
|
|
||||||
output.writeTag(1, WireType.LENGTH_DELIMITED)
|
|
||||||
output.writeInt32NoTag(item.getSizeNoTag())
|
|
||||||
item.writeTo(output)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun build(): RouteRequest {
|
|
||||||
return RouteRequest(way_points)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun parseFieldFrom(input: CodedInputStream): Boolean {
|
|
||||||
if (input.isAtEnd()) { return false }
|
|
||||||
val tag = input.readInt32NoTag()
|
|
||||||
if (tag == 0) { return false }
|
|
||||||
val fieldNumber = WireFormat.getTagFieldNumber(tag)
|
|
||||||
val wireType = WireFormat.getTagWireType(tag)
|
|
||||||
when(fieldNumber) {
|
|
||||||
1 -> {
|
|
||||||
if (wireType != WireType.LENGTH_DELIMITED) {
|
|
||||||
throw InvalidProtocolBufferException("Error: Field number 1 has wire type WireType.LENGTH_DELIMITED but read ${wireType.toString()}")}
|
|
||||||
var readSize = 0
|
|
||||||
var tmp: RouteRequest.WayPoint = RouteRequest.WayPoint.BuilderWayPoint().build()
|
|
||||||
run {
|
|
||||||
val expectedSize = input.readInt32NoTag()
|
|
||||||
tmp.mergeFromWithSize(input, expectedSize)
|
|
||||||
if (expectedSize != tmp.getSizeNoTag()) { throw InvalidProtocolBufferException ("Expected size ${expectedSize} got ${tmp.getSizeNoTag()}") }
|
|
||||||
}
|
|
||||||
if (tmp != RouteRequest.WayPoint.BuilderWayPoint().build()) {
|
|
||||||
readSize += tmp.getSizeNoTag()
|
|
||||||
}
|
|
||||||
way_points.add(tmp)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true}
|
|
||||||
fun parseFromWithSize(input: CodedInputStream, expectedSize: Int): RouteRequest.BuilderRouteRequest {
|
|
||||||
while(getSizeNoTag() < expectedSize) {
|
|
||||||
parseFieldFrom(input)
|
|
||||||
}
|
|
||||||
if (getSizeNoTag() > expectedSize) { throw InvalidProtocolBufferException("Error: expected size of message $expectedSize, but have read at least ${getSizeNoTag()}") }
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
fun parseFrom(input: CodedInputStream): RouteRequest.BuilderRouteRequest {
|
|
||||||
while(parseFieldFrom(input)) {}
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
fun getSize(fieldNumber: Int): Int {
|
|
||||||
var size = 0
|
|
||||||
if (way_points.size != 0) {
|
|
||||||
run {
|
|
||||||
var arraySize = 0
|
|
||||||
for (item in way_points) {
|
|
||||||
if (item != RouteRequest.WayPoint.BuilderWayPoint().build()) {
|
|
||||||
arraySize += item.getSize(1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
size += arraySize
|
|
||||||
}
|
|
||||||
}
|
|
||||||
size += WireFormat.getVarint32Size(size) + WireFormat.getTagSize(fieldNumber, WireType.LENGTH_DELIMITED)
|
|
||||||
return size
|
|
||||||
}
|
|
||||||
fun getSizeNoTag(): Int {
|
|
||||||
var size = 0
|
|
||||||
if (way_points.size != 0) {
|
|
||||||
run {
|
|
||||||
var arraySize = 0
|
|
||||||
for (item in way_points) {
|
|
||||||
if (item != RouteRequest.WayPoint.BuilderWayPoint().build()) {
|
|
||||||
arraySize += item.getSize(1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
size += arraySize
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return size
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
fun mergeWith (other: RouteRequest) {
|
|
||||||
way_points.addAll(other.way_points)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun mergeFromWithSize (input: CodedInputStream, expectedSize: Int) {
|
|
||||||
val builder = RouteRequest.BuilderRouteRequest()
|
|
||||||
mergeWith(builder.parseFromWithSize(input, expectedSize).build())}
|
|
||||||
|
|
||||||
fun mergeFrom (input: CodedInputStream) {
|
|
||||||
val builder = RouteRequest.BuilderRouteRequest()
|
|
||||||
mergeWith(builder.parseFrom(input).build())}
|
|
||||||
fun getSize(fieldNumber: Int): Int {
|
|
||||||
var size = 0
|
|
||||||
if (way_points.size != 0) {
|
|
||||||
run {
|
|
||||||
var arraySize = 0
|
|
||||||
for (item in way_points) {
|
|
||||||
if (item != RouteRequest.WayPoint.BuilderWayPoint().build()) {
|
|
||||||
arraySize += item.getSize(1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
size += arraySize
|
|
||||||
}
|
|
||||||
}
|
|
||||||
size += WireFormat.getVarint32Size(size) + WireFormat.getTagSize(fieldNumber, WireType.LENGTH_DELIMITED)
|
|
||||||
return size
|
|
||||||
}
|
|
||||||
fun getSizeNoTag(): Int {
|
|
||||||
var size = 0
|
|
||||||
if (way_points.size != 0) {
|
|
||||||
run {
|
|
||||||
var arraySize = 0
|
|
||||||
for (item in way_points) {
|
|
||||||
if (item != RouteRequest.WayPoint.BuilderWayPoint().build()) {
|
|
||||||
arraySize += item.getSize(1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
size += arraySize
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return size
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class RouteResponse private constructor (code: Int = 0, errorMsg: String = "") {
|
|
||||||
var code : Int
|
|
||||||
private set
|
|
||||||
|
|
||||||
var errorMsg : String
|
|
||||||
private set
|
|
||||||
|
|
||||||
|
|
||||||
init {
|
|
||||||
this.code = code
|
|
||||||
this.errorMsg = errorMsg
|
|
||||||
}
|
|
||||||
|
|
||||||
fun writeTo (output: CodedOutputStream) {
|
|
||||||
if (code != 0) {
|
|
||||||
output.writeInt32 (1, code)
|
|
||||||
}
|
|
||||||
if (errorMsg != "") {
|
|
||||||
output.writeString (2, errorMsg)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class BuilderRouteResponse constructor (code: Int = 0, errorMsg: String = "") {
|
|
||||||
var code : Int
|
|
||||||
private set
|
|
||||||
fun setCode(value: Int): RouteResponse.BuilderRouteResponse {
|
|
||||||
code = value
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
var errorMsg : String
|
|
||||||
private set
|
|
||||||
fun setErrorMsg(value: String): RouteResponse.BuilderRouteResponse {
|
|
||||||
errorMsg = value
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
init {
|
|
||||||
this.code = code
|
|
||||||
this.errorMsg = errorMsg
|
|
||||||
}
|
|
||||||
|
|
||||||
fun writeTo (output: CodedOutputStream) {
|
|
||||||
if (code != 0) {
|
|
||||||
output.writeInt32 (1, code)
|
|
||||||
}
|
|
||||||
if (errorMsg != "") {
|
|
||||||
output.writeString (2, errorMsg)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun build(): RouteResponse {
|
|
||||||
return RouteResponse(code, errorMsg)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun parseFieldFrom(input: CodedInputStream): Boolean {
|
|
||||||
if (input.isAtEnd()) { return false }
|
|
||||||
val tag = input.readInt32NoTag()
|
|
||||||
if (tag == 0) { return false }
|
|
||||||
val fieldNumber = WireFormat.getTagFieldNumber(tag)
|
|
||||||
val wireType = WireFormat.getTagWireType(tag)
|
|
||||||
when(fieldNumber) {
|
|
||||||
1 -> {
|
|
||||||
if (wireType != WireType.VARINT) {
|
|
||||||
throw InvalidProtocolBufferException("Error: Field number 1 has wire type WireType.VARINT but read ${wireType.toString()}")}
|
|
||||||
code = input.readInt32NoTag()
|
|
||||||
}
|
|
||||||
2 -> {
|
|
||||||
if (wireType != WireType.LENGTH_DELIMITED) {
|
|
||||||
throw InvalidProtocolBufferException("Error: Field number 2 has wire type WireType.LENGTH_DELIMITED but read ${wireType.toString()}")}
|
|
||||||
errorMsg = input.readStringNoTag()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true}
|
|
||||||
fun parseFromWithSize(input: CodedInputStream, expectedSize: Int): RouteResponse.BuilderRouteResponse {
|
|
||||||
while(getSizeNoTag() < expectedSize) {
|
|
||||||
parseFieldFrom(input)
|
|
||||||
}
|
|
||||||
if (getSizeNoTag() > expectedSize) { throw InvalidProtocolBufferException("Error: expected size of message $expectedSize, but have read at least ${getSizeNoTag()}") }
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
fun parseFrom(input: CodedInputStream): RouteResponse.BuilderRouteResponse {
|
|
||||||
while(parseFieldFrom(input)) {}
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
fun getSize(fieldNumber: Int): Int {
|
|
||||||
var size = 0
|
|
||||||
if (code != 0) {
|
|
||||||
size += WireFormat.getInt32Size(1, code)
|
|
||||||
}
|
|
||||||
if (errorMsg != "") {
|
|
||||||
size += WireFormat.getStringSize(2, errorMsg)
|
|
||||||
}
|
|
||||||
size += WireFormat.getVarint32Size(size) + WireFormat.getTagSize(fieldNumber, WireType.LENGTH_DELIMITED)
|
|
||||||
return size
|
|
||||||
}
|
|
||||||
fun getSizeNoTag(): Int {
|
|
||||||
var size = 0
|
|
||||||
if (code != 0) {
|
|
||||||
size += WireFormat.getInt32Size(1, code)
|
|
||||||
}
|
|
||||||
if (errorMsg != "") {
|
|
||||||
size += WireFormat.getStringSize(2, errorMsg)
|
|
||||||
}
|
|
||||||
return size
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
fun mergeWith (other: RouteResponse) {
|
|
||||||
code = other.code
|
|
||||||
errorMsg = other.errorMsg
|
|
||||||
}
|
|
||||||
|
|
||||||
fun mergeFromWithSize (input: CodedInputStream, expectedSize: Int) {
|
|
||||||
val builder = RouteResponse.BuilderRouteResponse()
|
|
||||||
mergeWith(builder.parseFromWithSize(input, expectedSize).build())}
|
|
||||||
|
|
||||||
fun mergeFrom (input: CodedInputStream) {
|
|
||||||
val builder = RouteResponse.BuilderRouteResponse()
|
|
||||||
mergeWith(builder.parseFrom(input).build())}
|
|
||||||
fun getSize(fieldNumber: Int): Int {
|
|
||||||
var size = 0
|
|
||||||
if (code != 0) {
|
|
||||||
size += WireFormat.getInt32Size(1, code)
|
|
||||||
}
|
|
||||||
if (errorMsg != "") {
|
|
||||||
size += WireFormat.getStringSize(2, errorMsg)
|
|
||||||
}
|
|
||||||
size += WireFormat.getVarint32Size(size) + WireFormat.getTagSize(fieldNumber, WireType.LENGTH_DELIMITED)
|
|
||||||
return size
|
|
||||||
}
|
|
||||||
fun getSizeNoTag(): Int {
|
|
||||||
var size = 0
|
|
||||||
if (code != 0) {
|
|
||||||
size += WireFormat.getInt32Size(1, code)
|
|
||||||
}
|
|
||||||
if (errorMsg != "") {
|
|
||||||
size += WireFormat.getStringSize(2, errorMsg)
|
|
||||||
}
|
|
||||||
return size
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,256 +0,0 @@
|
|||||||
class RouteDoneRequest private constructor (uid: Int = 0) {
|
|
||||||
var uid : Int
|
|
||||||
private set
|
|
||||||
|
|
||||||
|
|
||||||
init {
|
|
||||||
this.uid = uid
|
|
||||||
}
|
|
||||||
|
|
||||||
fun writeTo (output: CodedOutputStream) {
|
|
||||||
if (uid != 0) {
|
|
||||||
output.writeInt32 (1, uid)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class BuilderRouteDoneRequest constructor (uid: Int = 0) {
|
|
||||||
var uid : Int
|
|
||||||
private set
|
|
||||||
fun setUid(value: Int): RouteDoneRequest.BuilderRouteDoneRequest {
|
|
||||||
uid = value
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
init {
|
|
||||||
this.uid = uid
|
|
||||||
}
|
|
||||||
|
|
||||||
fun writeTo (output: CodedOutputStream) {
|
|
||||||
if (uid != 0) {
|
|
||||||
output.writeInt32 (1, uid)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun build(): RouteDoneRequest {
|
|
||||||
return RouteDoneRequest(uid)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun parseFieldFrom(input: CodedInputStream): Boolean {
|
|
||||||
if (input.isAtEnd()) { return false }
|
|
||||||
val tag = input.readInt32NoTag()
|
|
||||||
if (tag == 0) { return false }
|
|
||||||
val fieldNumber = WireFormat.getTagFieldNumber(tag)
|
|
||||||
val wireType = WireFormat.getTagWireType(tag)
|
|
||||||
when(fieldNumber) {
|
|
||||||
1 -> {
|
|
||||||
if (wireType != WireType.VARINT) {
|
|
||||||
throw InvalidProtocolBufferException("Error: Field number 1 has wire type WireType.VARINT but read ${wireType.toString()}")}
|
|
||||||
uid = input.readInt32NoTag()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true}
|
|
||||||
fun parseFromWithSize(input: CodedInputStream, expectedSize: Int): RouteDoneRequest.BuilderRouteDoneRequest {
|
|
||||||
while(getSizeNoTag() < expectedSize) {
|
|
||||||
parseFieldFrom(input)
|
|
||||||
}
|
|
||||||
if (getSizeNoTag() > expectedSize) { throw InvalidProtocolBufferException("Error: expected size of message $expectedSize, but have read at least ${getSizeNoTag()}") }
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
fun parseFrom(input: CodedInputStream): RouteDoneRequest.BuilderRouteDoneRequest {
|
|
||||||
while(parseFieldFrom(input)) {}
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
fun getSize(fieldNumber: Int): Int {
|
|
||||||
var size = 0
|
|
||||||
if (uid != 0) {
|
|
||||||
size += WireFormat.getInt32Size(1, uid)
|
|
||||||
}
|
|
||||||
size += WireFormat.getVarint32Size(size) + WireFormat.getTagSize(fieldNumber, WireType.LENGTH_DELIMITED)
|
|
||||||
return size
|
|
||||||
}
|
|
||||||
fun getSizeNoTag(): Int {
|
|
||||||
var size = 0
|
|
||||||
if (uid != 0) {
|
|
||||||
size += WireFormat.getInt32Size(1, uid)
|
|
||||||
}
|
|
||||||
return size
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
fun mergeWith (other: RouteDoneRequest) {
|
|
||||||
uid = other.uid
|
|
||||||
}
|
|
||||||
|
|
||||||
fun mergeFromWithSize (input: CodedInputStream, expectedSize: Int) {
|
|
||||||
val builder = RouteDoneRequest.BuilderRouteDoneRequest()
|
|
||||||
mergeWith(builder.parseFromWithSize(input, expectedSize).build())}
|
|
||||||
|
|
||||||
fun mergeFrom (input: CodedInputStream) {
|
|
||||||
val builder = RouteDoneRequest.BuilderRouteDoneRequest()
|
|
||||||
mergeWith(builder.parseFrom(input).build())}
|
|
||||||
fun getSize(fieldNumber: Int): Int {
|
|
||||||
var size = 0
|
|
||||||
if (uid != 0) {
|
|
||||||
size += WireFormat.getInt32Size(1, uid)
|
|
||||||
}
|
|
||||||
size += WireFormat.getVarint32Size(size) + WireFormat.getTagSize(fieldNumber, WireType.LENGTH_DELIMITED)
|
|
||||||
return size
|
|
||||||
}
|
|
||||||
fun getSizeNoTag(): Int {
|
|
||||||
var size = 0
|
|
||||||
if (uid != 0) {
|
|
||||||
size += WireFormat.getInt32Size(1, uid)
|
|
||||||
}
|
|
||||||
return size
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class RouteDoneResponse private constructor (code: Int = 0, errorMsg: String = "") {
|
|
||||||
var code : Int
|
|
||||||
private set
|
|
||||||
|
|
||||||
var errorMsg : String
|
|
||||||
private set
|
|
||||||
|
|
||||||
|
|
||||||
init {
|
|
||||||
this.code = code
|
|
||||||
this.errorMsg = errorMsg
|
|
||||||
}
|
|
||||||
|
|
||||||
fun writeTo (output: CodedOutputStream) {
|
|
||||||
if (code != 0) {
|
|
||||||
output.writeInt32 (1, code)
|
|
||||||
}
|
|
||||||
if (errorMsg != "") {
|
|
||||||
output.writeString (2, errorMsg)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class BuilderRouteDoneResponse constructor (code: Int = 0, errorMsg: String = "") {
|
|
||||||
var code : Int
|
|
||||||
private set
|
|
||||||
fun setCode(value: Int): RouteDoneResponse.BuilderRouteDoneResponse {
|
|
||||||
code = value
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
var errorMsg : String
|
|
||||||
private set
|
|
||||||
fun setErrorMsg(value: String): RouteDoneResponse.BuilderRouteDoneResponse {
|
|
||||||
errorMsg = value
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
init {
|
|
||||||
this.code = code
|
|
||||||
this.errorMsg = errorMsg
|
|
||||||
}
|
|
||||||
|
|
||||||
fun writeTo (output: CodedOutputStream) {
|
|
||||||
if (code != 0) {
|
|
||||||
output.writeInt32 (1, code)
|
|
||||||
}
|
|
||||||
if (errorMsg != "") {
|
|
||||||
output.writeString (2, errorMsg)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun build(): RouteDoneResponse {
|
|
||||||
return RouteDoneResponse(code, errorMsg)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun parseFieldFrom(input: CodedInputStream): Boolean {
|
|
||||||
if (input.isAtEnd()) { return false }
|
|
||||||
val tag = input.readInt32NoTag()
|
|
||||||
if (tag == 0) { return false }
|
|
||||||
val fieldNumber = WireFormat.getTagFieldNumber(tag)
|
|
||||||
val wireType = WireFormat.getTagWireType(tag)
|
|
||||||
when(fieldNumber) {
|
|
||||||
1 -> {
|
|
||||||
if (wireType != WireType.VARINT) {
|
|
||||||
throw InvalidProtocolBufferException("Error: Field number 1 has wire type WireType.VARINT but read ${wireType.toString()}")}
|
|
||||||
code = input.readInt32NoTag()
|
|
||||||
}
|
|
||||||
2 -> {
|
|
||||||
if (wireType != WireType.LENGTH_DELIMITED) {
|
|
||||||
throw InvalidProtocolBufferException("Error: Field number 2 has wire type WireType.LENGTH_DELIMITED but read ${wireType.toString()}")}
|
|
||||||
errorMsg = input.readStringNoTag()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true}
|
|
||||||
fun parseFromWithSize(input: CodedInputStream, expectedSize: Int): RouteDoneResponse.BuilderRouteDoneResponse {
|
|
||||||
while(getSizeNoTag() < expectedSize) {
|
|
||||||
parseFieldFrom(input)
|
|
||||||
}
|
|
||||||
if (getSizeNoTag() > expectedSize) { throw InvalidProtocolBufferException("Error: expected size of message $expectedSize, but have read at least ${getSizeNoTag()}") }
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
fun parseFrom(input: CodedInputStream): RouteDoneResponse.BuilderRouteDoneResponse {
|
|
||||||
while(parseFieldFrom(input)) {}
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
fun getSize(fieldNumber: Int): Int {
|
|
||||||
var size = 0
|
|
||||||
if (code != 0) {
|
|
||||||
size += WireFormat.getInt32Size(1, code)
|
|
||||||
}
|
|
||||||
if (errorMsg != "") {
|
|
||||||
size += WireFormat.getStringSize(2, errorMsg)
|
|
||||||
}
|
|
||||||
size += WireFormat.getVarint32Size(size) + WireFormat.getTagSize(fieldNumber, WireType.LENGTH_DELIMITED)
|
|
||||||
return size
|
|
||||||
}
|
|
||||||
fun getSizeNoTag(): Int {
|
|
||||||
var size = 0
|
|
||||||
if (code != 0) {
|
|
||||||
size += WireFormat.getInt32Size(1, code)
|
|
||||||
}
|
|
||||||
if (errorMsg != "") {
|
|
||||||
size += WireFormat.getStringSize(2, errorMsg)
|
|
||||||
}
|
|
||||||
return size
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
fun mergeWith (other: RouteDoneResponse) {
|
|
||||||
code = other.code
|
|
||||||
errorMsg = other.errorMsg
|
|
||||||
}
|
|
||||||
|
|
||||||
fun mergeFromWithSize (input: CodedInputStream, expectedSize: Int) {
|
|
||||||
val builder = RouteDoneResponse.BuilderRouteDoneResponse()
|
|
||||||
mergeWith(builder.parseFromWithSize(input, expectedSize).build())}
|
|
||||||
|
|
||||||
fun mergeFrom (input: CodedInputStream) {
|
|
||||||
val builder = RouteDoneResponse.BuilderRouteDoneResponse()
|
|
||||||
mergeWith(builder.parseFrom(input).build())}
|
|
||||||
fun getSize(fieldNumber: Int): Int {
|
|
||||||
var size = 0
|
|
||||||
if (code != 0) {
|
|
||||||
size += WireFormat.getInt32Size(1, code)
|
|
||||||
}
|
|
||||||
if (errorMsg != "") {
|
|
||||||
size += WireFormat.getStringSize(2, errorMsg)
|
|
||||||
}
|
|
||||||
size += WireFormat.getVarint32Size(size) + WireFormat.getTagSize(fieldNumber, WireType.LENGTH_DELIMITED)
|
|
||||||
return size
|
|
||||||
}
|
|
||||||
fun getSizeNoTag(): Int {
|
|
||||||
var size = 0
|
|
||||||
if (code != 0) {
|
|
||||||
size += WireFormat.getInt32Size(1, code)
|
|
||||||
}
|
|
||||||
if (errorMsg != "") {
|
|
||||||
size += WireFormat.getStringSize(2, errorMsg)
|
|
||||||
}
|
|
||||||
return size
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user