From 4615e774e1b2cb7bb1db615962c1b99e0853fe50 Mon Sep 17 00:00:00 2001 From: Samuel Freilich Date: Fri, 22 May 2026 12:19:28 -0700 Subject: [PATCH] Simplify StrokeInputBatch JNI interface PiperOrigin-RevId: 919800316 --- .../stroke_input_batch_serialization_jni.cc | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/ink/storage/internal/jni/stroke_input_batch_serialization_jni.cc b/ink/storage/internal/jni/stroke_input_batch_serialization_jni.cc index 74e9dfa0..3bb64809 100644 --- a/ink/storage/internal/jni/stroke_input_batch_serialization_jni.cc +++ b/ink/storage/internal/jni/stroke_input_batch_serialization_jni.cc @@ -26,32 +26,28 @@ #include "ink/strokes/input/stroke_input_batch.h" #include "ink/strokes/internal/jni/stroke_input_batch_native_helper.h" -namespace { - using ::ink::DecodeStrokeInputBatch; using ::ink::EncodeStrokeInputBatch; using ::ink::StrokeInputBatch; -using ::ink::jni::ParseProtoFromEither; +using ::ink::jni::ParseProtoFromByteArray; using ::ink::jni::SerializeProto; using ::ink::jni::ThrowExceptionFromStatus; using ::ink::native::CastToStrokeInputBatch; using ::ink::native::NewNativeStrokeInputBatch; using ::ink::proto::CodedStrokeInputBatch; -} // namespace - extern "C" { // Constructs a `StrokeInputBatch` from a serialized `CodedStrokeInputBatch`, // which can be passed in as either a direct `ByteBuffer` or as an array of // bytes. This returns the address of a heap-allocated `StrokeInputBatch`, which // must later be freed by the caller. -JNI_METHOD(storage, StrokeInputBatchSerializationNative, jlong, newFromProto) -(JNIEnv* env, jclass klass, jobject direct_byte_buffer, jbyteArray byte_array, - jint offset, jint length) { +JNI_METHOD(storage, StrokeInputBatchSerializationNative, jlong, createFromProto) +(JNIEnv* env, jclass klass, jbyteArray byte_array, jint length) { CodedStrokeInputBatch coded_input; - if (absl::Status status = ParseProtoFromEither( - env, direct_byte_buffer, byte_array, offset, length, coded_input); + constexpr int kOffset = 0; + if (absl::Status status = ParseProtoFromByteArray(env, byte_array, kOffset, + length, coded_input); !status.ok()) { ThrowExceptionFromStatus(env, status); return 0; @@ -64,7 +60,7 @@ JNI_METHOD(storage, StrokeInputBatchSerializationNative, jlong, newFromProto) return NewNativeStrokeInputBatch(*std::move(input)); } -JNI_METHOD(storage, StrokeInputBatchSerializationNative, jbyteArray, serialize) +JNI_METHOD(storage, StrokeInputBatchSerializationNative, jbyteArray, encode) (JNIEnv* env, jclass klass, jlong stroke_input_batch_native_pointer) { CodedStrokeInputBatch coded_input; EncodeStrokeInputBatch(