-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update to recent Kotlin naming conventions #90
Conversation
- Rename "marshal"/"unmarshal" to "encode"/"decode" in all methods and classes - Standardize encoding/decoding methods to be named `encodeTo*` and `decodeFrom*`, similar to naming used in the standard libraries - Rename the low-level `marshal(MessageMarshaller)` and `unmarshal(MessageUnmarshaller)` methods to `encodeWith(MessageEncoder)` and `decodeWith(MessageDecoder)` Fixes #89
6e4c0e7
to
962ce2b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great. I'm happy to see the marshal and unmarshal language get updated. Thanks for doing this!
I saw a bunch of files needing a new line. I added comments on them, but maybe it should just be a TODO for us to run Kotlin lint on the codebase in the future? Feel free to take or leave the comments.
companion object { | ||
fun allocate(size: Int) = KotlinBinaryMessageEncoder(ByteArrayWireWriter.allocate(size)) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔧 Need a new line after }
data: String, | ||
jsonConfig: JsonConfig = JsonConfig.DEFAULT | ||
): T = decodeWith(JsonMessageDecoder.fromString(data, jsonConfig)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔧 Needs new line at the end
assertEquals((byteArrayOf(10, 12) + "Hello world!".map { it.toByte() }.toByteArray()).asList(), bytes.asList()) | ||
assertEquals(foo, Foo.protoUnmarshal(bytes)) | ||
assertEquals(foo, Foo.decodeFromByteArray(bytes)) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔧 Add new line
|
||
internal actual fun BinaryMessageEncoder.Companion.allocate(size: Int): ByteArrayMessageEncoder { | ||
return ProtobufjsBinaryMessageEncoder.allocate(size) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔧 Add new line
companion object { | ||
fun allocate(size: Int) = ProtobufjsBinaryMessageEncoder(Writer.create(), size) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔧 Add new line
|
||
internal fun BinaryMessageDecoder.Companion.fromByteBuffer(buffer: ByteBuffer): MessageDecoder { | ||
return BinaryMessageDecoder(CodedStreamBinaryWireDecoder(CodedInputStream.newInstance(buffer))) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔧 Add a new line
|
||
internal actual fun BinaryMessageEncoder.Companion.allocate(size: Int): ByteArrayMessageEncoder { | ||
return ByteArrayCodedStreamBinaryMessageEncoder.allocate(size) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔧 Add a new line
|
||
override fun toByteArray() = backingBytes | ||
|
||
companion object { | ||
fun allocate(size: Int) = ByteArrayCodedStreamBinaryMessageMarshaller(ByteArray(size)) | ||
fun allocate(size: Int) = ByteArrayCodedStreamBinaryMessageEncoder(ByteArray(size)) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔧 Add a new line
assertEquals(builtJavaObj, gendJavaObj) | ||
assertEquals(builtKotlinObj, gendKotlinObj) | ||
|
||
// Check that map-with-size | ||
assertTrue(gendKotlinObj.map is MessageMap) | ||
assertEquals(builtKotlinObj.protoSize, gendKotlinObj.protoSize) | ||
assertEquals(builtKotlinBytes.toList(), gendKotlinObj.protoMarshal().toList()) | ||
assertEquals(builtKotlinBytes.toList(), gendKotlinObj.encodeToByteArray().toList()) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔧 Add a new line
|
||
internal actual fun BinaryMessageEncoder.Companion.allocate(size: Int): ByteArrayMessageEncoder { | ||
return KotlinBinaryMessageEncoder.allocate(size) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔧 Add a new line
Hmm, yeah. We should probably add the |
Kotlin is starting to standardize on some naming patterns in its standard library and related libraries (like kotlinx-serialization and kotlinx-coroutines). This change implements similar naming conventions so that pbandk's API feels more idiomatic and familiar to Kotlin developers.
Replace "marshal"/"unmarshal" terminology with "encode"/"decode" in all methods and classes
Standardize encoding/decoding methods to be named
encodeTo*
anddecodeFrom*
, similar to naming used in the standard librariesRename the low-level
marshal(MessageMarshaller)
andunmarshal(MessageUnmarshaller)
methods toencodeWith(MessageEncoder)
anddecodeWith(MessageDecoder)
Fixes #89