opcua_types/
basic_types.rs1use std::io::{Read, Write};
7
8use crate::encoding::*;
9
10impl SimpleBinaryEncodable for bool {
27 fn byte_len(&self) -> usize {
28 1
29 }
30
31 fn encode<S: Write + ?Sized>(&self, stream: &mut S) -> EncodingResult<()> {
32 write_u8(stream, if *self { 1 } else { 0 })
34 }
35}
36
37impl SimpleBinaryDecodable for bool {
38 fn decode<S: Read + ?Sized>(
39 stream: &mut S,
40 _decoding_options: &DecodingOptions,
41 ) -> EncodingResult<Self> {
42 Ok(read_u8(stream)? == 1)
43 }
44}
45
46impl SimpleBinaryEncodable for i8 {
47 fn byte_len(&self) -> usize {
48 1
49 }
50
51 fn encode<S: Write + ?Sized>(&self, stream: &mut S) -> EncodingResult<()> {
52 write_u8(stream, *self as u8)
53 }
54}
55
56impl SimpleBinaryDecodable for i8 {
57 fn decode<S: Read + ?Sized>(
58 stream: &mut S,
59 _decoding_options: &DecodingOptions,
60 ) -> EncodingResult<Self> {
61 Ok(read_u8(stream)? as i8)
62 }
63}
64
65impl SimpleBinaryEncodable for u8 {
67 fn byte_len(&self) -> usize {
68 1
69 }
70
71 fn encode<S: Write + ?Sized>(&self, stream: &mut S) -> EncodingResult<()> {
72 write_u8(stream, *self)
73 }
74}
75
76impl SimpleBinaryDecodable for u8 {
77 fn decode<S: Read + ?Sized>(
78 stream: &mut S,
79 _decoding_options: &DecodingOptions,
80 ) -> EncodingResult<Self> {
81 read_u8(stream)
82 }
83}
84
85impl SimpleBinaryEncodable for i16 {
87 fn byte_len(&self) -> usize {
88 2
89 }
90
91 fn encode<S: Write + ?Sized>(&self, stream: &mut S) -> EncodingResult<()> {
92 write_i16(stream, *self)
93 }
94}
95
96impl SimpleBinaryDecodable for i16 {
97 fn decode<S: Read + ?Sized>(
98 stream: &mut S,
99 _decoding_options: &DecodingOptions,
100 ) -> EncodingResult<Self> {
101 read_i16(stream)
102 }
103}
104
105impl SimpleBinaryEncodable for u16 {
107 fn byte_len(&self) -> usize {
108 2
109 }
110
111 fn encode<S: Write + ?Sized>(&self, stream: &mut S) -> EncodingResult<()> {
112 write_u16(stream, *self)
113 }
114}
115
116impl SimpleBinaryDecodable for u16 {
117 fn decode<S: Read + ?Sized>(
118 stream: &mut S,
119 _decoding_options: &DecodingOptions,
120 ) -> EncodingResult<Self> {
121 read_u16(stream)
122 }
123}
124
125impl SimpleBinaryEncodable for i32 {
127 fn byte_len(&self) -> usize {
128 4
129 }
130
131 fn encode<S: Write + ?Sized>(&self, stream: &mut S) -> EncodingResult<()> {
132 write_i32(stream, *self)
133 }
134}
135
136impl SimpleBinaryDecodable for i32 {
137 fn decode<S: Read + ?Sized>(
138 stream: &mut S,
139 _decoding_options: &DecodingOptions,
140 ) -> EncodingResult<Self> {
141 read_i32(stream)
142 }
143}
144
145impl SimpleBinaryEncodable for u32 {
147 fn byte_len(&self) -> usize {
148 4
149 }
150
151 fn encode<S: Write + ?Sized>(&self, stream: &mut S) -> EncodingResult<()> {
152 write_u32(stream, *self)
153 }
154}
155impl SimpleBinaryDecodable for u32 {
156 fn decode<S: Read + ?Sized>(
157 stream: &mut S,
158 _decoding_options: &DecodingOptions,
159 ) -> EncodingResult<Self> {
160 read_u32(stream)
161 }
162}
163
164impl SimpleBinaryEncodable for i64 {
166 fn byte_len(&self) -> usize {
167 8
168 }
169
170 fn encode<S: Write + ?Sized>(&self, stream: &mut S) -> EncodingResult<()> {
171 write_i64(stream, *self)
172 }
173}
174
175impl SimpleBinaryDecodable for i64 {
176 fn decode<S: Read + ?Sized>(
177 stream: &mut S,
178 _decoding_options: &DecodingOptions,
179 ) -> EncodingResult<Self> {
180 read_i64(stream)
181 }
182}
183
184impl SimpleBinaryEncodable for u64 {
186 fn byte_len(&self) -> usize {
187 8
188 }
189
190 fn encode<S: Write + ?Sized>(&self, stream: &mut S) -> EncodingResult<()> {
191 write_u64(stream, *self)
192 }
193}
194
195impl SimpleBinaryDecodable for u64 {
196 fn decode<S: Read + ?Sized>(
197 stream: &mut S,
198 _decoding_options: &DecodingOptions,
199 ) -> EncodingResult<Self> {
200 read_u64(stream)
201 }
202}
203
204impl SimpleBinaryEncodable for f32 {
206 fn byte_len(&self) -> usize {
207 4
208 }
209
210 fn encode<S: Write + ?Sized>(&self, stream: &mut S) -> EncodingResult<()> {
211 write_f32(stream, *self)
212 }
213}
214
215impl SimpleBinaryDecodable for f32 {
216 fn decode<S: Read + ?Sized>(
217 stream: &mut S,
218 _decoding_options: &DecodingOptions,
219 ) -> EncodingResult<Self> {
220 read_f32(stream)
221 }
222}
223
224impl SimpleBinaryEncodable for f64 {
226 fn byte_len(&self) -> usize {
227 8
228 }
229
230 fn encode<S: Write + ?Sized>(&self, stream: &mut S) -> EncodingResult<()> {
231 write_f64(stream, *self)
232 }
233}
234
235impl SimpleBinaryDecodable for f64 {
236 fn decode<S: Read + ?Sized>(
237 stream: &mut S,
238 _decoding_options: &DecodingOptions,
239 ) -> EncodingResult<Self> {
240 read_f64(stream)
241 }
242}