GamepadCodec Arduino Lib 1.0.1
Loading...
Searching...
No Matches
gamepad_codec_encoder.h
Go to the documentation of this file.
1#pragma once
2
3#ifndef _GAMEPAD_CODEC_ENCODER_H_
4#define _GAMEPAD_CODEC_ENCODER_H_
5
6#include <stddef.h>
7#include <stdint.h>
8
10#include "gamepad_input_tracker.h"
11#include "robust_frame.h"
12
13/**
14 * @file gamepad_codec_encoder.h
15 */
16
17namespace gamepad::codec {
18/**
19 * @~English
20 * @brief Encode a gamepad::input::State into a RobustFrame.
21 * @param[in] state The input state to encode.
22 * @return ByteBuffer containing the encoded frame. The buffer is automatically
23 * sized to accommodate the maximum possible frame length.
24 * @note Use this function when you need to send the frame later or via custom
25 * transport. For direct sending via Stream, use the Stream overload.
26 */
27/**
28 * @~Chinese
29 * @brief 将 gamepad::input::State 编码为 RobustFrame 帧。
30 * @param[in] state 待编码的输入状态。
31 * @return 包含编码后帧数据的 ByteBuffer。缓冲区会自动分配足够的空间以容纳最大可能的帧长度。
32 * @note 当需要稍后发送帧或通过自定义传输方式发送时,使用此函数。如需直接通过 Stream 发送,
33 * 请使用 Stream 重载版本。
34 */
35ByteBuffer Encode(const gamepad::input::State &state) noexcept;
36
37/**
38 * @~English
39 * @brief Encode a gamepad::input::State into a robust frame and send directly to a Stream.
40 * @param[in] state The input state to encode.
41 * @param[in] stream The output stream, to write the frame to.
42 * @note This function is suitable for scenarios where frames are sent directly via Stream without requiring an intermediate
43 * buffer
44 */
45/**
46 * @~Chinese
47 * @brief 将 gamepad::input::State 编码为 RobustFrame 帧并直接发送到 Stream。
48 * @param[in] state 待编码的输入状态。
49 * @param[in] stream 输出流,用于写入帧数据。
50 * @note 此函数适用于无需中间缓冲区,直接通过 Stream 发送帧的场景。
51 */
52void Encode(const gamepad::input::State &state, Stream &stream) noexcept;
53} // namespace gamepad::codec
54#endif
ByteBuffer Encode(const gamepad::input::State &state) noexcept
Encode a gamepad::input::State into a RobustFrame.