fix: oops

This commit is contained in:
Orion Kindel 2023-04-20 11:33:12 -05:00
parent f3c8c02296
commit c71993ba24
Signed by untrusted user who does not match committer: orion
GPG Key ID: 6D4165AE4C928719
6 changed files with 52 additions and 10 deletions

View File

@ -3,7 +3,7 @@ pub mod owned;
pub mod ref_;
mod ty;
use toad_jni::java;
pub use ty::Type;
mod payload;
@ -17,3 +17,21 @@ pub use id::Id;
mod token;
pub use token::Token;
pub struct Message(pub java::lang::Object);
java::object_newtype!(Message);
impl java::Class for Message {
const PATH: &'static str = package!(dev.toad.msg.Message);
}
pub struct Option(pub java::lang::Object);
java::object_newtype!(Option);
impl java::Class for Option {
const PATH: &'static str = package!(dev.toad.msg.Option);
}
pub struct OptionValue(pub java::lang::Object);
java::object_newtype!(OptionValue);
impl java::Class for OptionValue {
const PATH: &'static str = package!(dev.toad.msg.OptionValue);
}

View File

@ -1,7 +1,5 @@
use toad_jni::java;
use super::owned::Opt;
pub struct ContentFormat(java::lang::Object);
java::object_newtype!(ContentFormat);
impl java::Class for ContentFormat {
@ -9,8 +7,8 @@ impl java::Class for ContentFormat {
}
impl ContentFormat {
pub fn new(e: &mut java::Env, o: Opt) -> Self {
static CTOR: java::Constructor<ContentFormat, fn(Opt)> = java::Constructor::new();
pub fn new(e: &mut java::Env, o: super::Option) -> Self {
static CTOR: java::Constructor<ContentFormat, fn(super::Option)> = java::Constructor::new();
CTOR.invoke(e, o)
}
}

View File

@ -12,6 +12,11 @@ impl java::Class for Opt {
}
impl Opt {
pub fn new(e: &mut java::Env, num: i64, vals: ArrayList<OptValue>) -> Self {
static CTOR: java::Constructor<Opt, fn(i64, ArrayList<OptValue>)> = java::Constructor::new();
CTOR.invoke(e, num, vals)
}
pub fn number(&self, e: &mut java::Env) -> OptNumber {
static NUMBER: java::Field<Opt, crate::dev::toad::ffi::u32> = java::Field::new("number");
OptNumber(NUMBER.get(e, self).to_rust(e))

View File

@ -7,6 +7,14 @@ impl java::Class for OptValue {
}
impl OptValue {
pub fn new(e: &mut java::Env, bytes: impl IntoIterator<Item = u8>) -> Self {
static CTOR: java::Constructor<OptValue, fn(Vec<i8>)> = java::Constructor::new();
CTOR.invoke(e,
bytes.into_iter()
.map(|b| i8::from_be_bytes(b.to_be_bytes()))
.collect())
}
pub fn bytes(&self, e: &mut java::Env) -> Vec<u8> {
static BYTES: java::Field<OptValue, Vec<i8>> = java::Field::new("bytes");
BYTES.get(e, self)

View File

@ -17,7 +17,10 @@ impl Payload {
.collect())
}
pub fn new_content_format(e: &mut java::Env, bytes: Vec<u8>, f: ContentFormat) -> Self {
pub fn new_content_format(e: &mut java::Env,
bytes: impl IntoIterator<Item = u8>,
f: ContentFormat)
-> Self {
static CTOR: java::Constructor<Payload, fn(ContentFormat, Vec<i8>)> = java::Constructor::new();
CTOR.invoke(e,
f,

View File

@ -5,10 +5,13 @@ use jni::sys::jobject;
use toad::net::Addrd;
use toad_jni::java::lang::Throwable;
use toad_jni::java::net::InetSocketAddress;
use toad_jni::java::{self, ResultYieldToJavaOrThrow};
use toad_jni::java::util::ArrayList;
use toad_jni::java::{self, Object, ResultYieldToJavaOrThrow};
use toad_msg::no_repeat::CONTENT_FORMAT;
use toad_msg::MessageOptions;
use crate::dev::toad::ffi::Ptr;
use crate::dev::toad::msg::option::ContentFormat;
use crate::dev::toad::msg::ref_::Opt;
use crate::dev::toad::msg::{Code, Id, Payload, Token, Type};
use crate::mem::{Shared, SharedMemoryRegion};
@ -137,8 +140,15 @@ pub extern "system" fn Java_dev_toad_msg_ref_Message_payload<'local>(mut env: ja
.map(|msg| {
msg.data()
.content_format()
.map(|_f| {
Payload::new(e, msg.data().payload.0.iter().copied())
.map(|f| {
use crate::dev::toad::msg::owned::{Opt, OptValue};
let arr = ArrayList::<OptValue>::new(e);
let val = OptValue::new(e, f.bytes());
arr.append(e, val);
let o = Opt::new(e, CONTENT_FORMAT.0.into(), arr).downcast(e);
let f = ContentFormat::new(e, crate::dev::toad::msg::Option(o));
Payload::new_content_format(e, msg.data().payload.0.iter().copied(), f)
})
.unwrap_or_else(|| {
Payload::new(e, msg.data().payload.0.iter().copied())
@ -204,7 +214,7 @@ pub extern "system" fn Java_dev_toad_msg_ref_Message_optionRefs<'local>(mut env:
#[cfg(test)]
mod tests {
use toad_jni::java::Signature;
use toad_jni::java::{Object, Signature};
use toad_msg::{MessageOptions, Payload};
use super::*;