简体   繁体   English

如何将我的结构放入 Rust 中 AWS Kinesis 的 PutRecordInput?

[英]How do I put my struct into a PutRecordInput for AWS Kinesis in Rust?

I am very new to Rust and trying to get a bit of code working that can push a record to a kinesis firehose stream.我对 Rust 非常陌生,并试图获得一些可以将记录推送到 kinesis firehose stream 的代码。

struct AuditRecord{
    user_id : String,
    request : Value,
    request_id : String,
    timestamp_raw : i64,
}
...
let client = KinesisClient::new(Region::UsEast1);
let record = PutRecordInput{
    partition_key : requestId.to_string(),
    stream_name : streamName,
    data : auditRecord
};

When I tried this it wants the data in bytes::bytes::Bytes but I am unclear as to how to convert my struct to a bytes::bytes::Bytes representation.当我尝试这个时,它需要bytes::bytes::Bytes中的数据,但我不清楚如何将我的结构转换为bytes::bytes::Bytes表示。 Any examples of how to go about this would be appreciated.任何有关如何 go 的示例将不胜感激。

For clarification I am using为了澄清我正在使用

rusoto = "0.24.2"
rusoto_kinesis = "0.43.0"
rusoto_core = "0.43.0"

Also if anyone know of a good place to see real examples of how to use rusoto to talk with varios AWS entities that would be appreciated.此外,如果有人知道一个很好的地方可以查看如何使用 rusoto 与各种 AWS 实体交谈的真实示例,那将不胜感激。

As other people have stated, It really depends on your choice of serialization.正如其他人所说,这实际上取决于您选择的序列化。 If you chose a string based encoding like xml or json, then you could use something like:如果您选择了基于字符串的编码,例如 xml 或 json,那么您可以使用以下代码:

let msg: String = "some message".to_string();

let record = PutRecordInput{
    partition_key : requestId.to_string(),
    stream_name : streamName,
    data : msg.into()
};

// or it could be 
let record = PutRecordInput{
    partition_key : requestId.to_string(),
    stream_name : streamName,
    data : Bytes::from(msg)
};

Where you replace "some message" with your string sterilization of choice.用您选择的字符串灭菌替换“一些消息”。

Though technically, using some binary encoding like protobuf or something are usually a lot more compact, but then whatever is on the other side must be able to interpret the format.虽然从技术上讲,使用像 protobuf 之类的二进制编码通常要紧凑得多,但是另一方面必须能够解释格式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM