summaryrefslogtreecommitdiff
path: root/src/tiff/entry.rs
blob: b5b2319ee5540939a0b064695d2535f082615d72 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
// SPDX-License-Identifier: LGPL-3.0-or-later
/*
 * libopenraw - tiff/entry.rs
 *
 * Copyright (C) 2022-2023 Hubert Figuière
 *
 * This library is free software: you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation, either version 3 of
 * the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library.  If not, see
 * <http://www.gnu.org/licenses/>.
 */

//! IFD entries.

#[cfg(feature = "dump")]
use std::collections::HashMap;
use std::convert::TryFrom;
use std::io::{Read, Seek, SeekFrom};

use byteorder::{BigEndian, ByteOrder, LittleEndian, NativeEndian};
use log::debug;

use crate::container::Endian;
use crate::io::View;
use crate::{Error, Result};

use super::exif;
use super::exif::{ExifValue, Rational, SRational, TagType};

#[derive(Clone, Debug)]
/// Represent the data bytes, either the 4 bytes read,
/// the read bytes from the view or the offset.
enum DataBytes {
    /// Inline data. In the IFD byte order.
    Inline([u8; 4]),
    /// External data loaded from the contain in the IFD byte order.
    External(Vec<u8>),
    /// Offset of the data in the container. This is only for
    /// `Undefined` entry types. Use `Entry::offset()` to retrieve it.
    Offset(u32, Vec<u8>),
}

impl DataBytes {
    /// Convert the data buffer into a slice
    pub fn as_slice(&self) -> &[u8] {
        match *self {
            Self::Inline(ref b) => b,
            Self::External(ref v) => v.as_slice(),
            Self::Offset(_, ref v) => v.as_slice(),
        }
    }
}

#[derive(Clone, Debug)]
/// IFD entry
pub struct Entry {
    /// The tag
    pub(crate) id: u16,
    /// The type. See `exif::TagType`, use `exif::TagType::try_from()`
    /// to get the enum.
    pub(crate) type_: i16,
    pub(crate) count: u32,
    data: DataBytes,
}

impl Entry {
    pub fn new(id: u16, type_: i16, count: u32, data: [u8; 4]) -> Self {
        Entry {
            id,
            type_,
            count,
            data: DataBytes::Inline(data),
        }
    }

    pub fn new_with_data(id: u16, type_: i16, count: u32, data: Vec<u8>) -> Self {
        Entry {
            id,
            type_,
            count,
            data: DataBytes::External(data),
        }
    }

    pub fn from_string(id: u16, string: &str) -> Self {
        Entry {
            id,
            type_: TagType::Ascii as i16,
            count: string.as_bytes().len() as u32,
            data: DataBytes::External(string.as_bytes().to_vec()),
        }
    }

    /// Return wether the entry is inline.
    pub fn is_inline(&self) -> bool {
        let tag_type = TagType::try_from(self.type_).unwrap_or(TagType::Invalid);
        let data_size = exif::tag_unit_size(tag_type) * self.count as usize;
        data_size <= 4
    }

    /// Set the entry as containing an offset.
    pub(crate) fn set_offset(&mut self, offset: u32, data: Vec<u8>) {
        self.data = DataBytes::Offset(offset, data);
    }

    /// Get the offset if it exists
    pub(crate) fn offset(&self) -> Option<u32> {
        match self.data {
            DataBytes::Offset(offset, _) => Some(offset),
            _ => None,
        }
    }

    pub(crate) fn data(&self) -> &[u8] {
        self.data.as_slice()
    }

    /// monomorphic implementation of `load_data<E>`
    fn load_data_impl(&self, offset: u64, view: &mut View) -> Result<Vec<u8>> {
        let tag_type = TagType::try_from(self.type_).unwrap_or(TagType::Invalid);
        let data_size = exif::tag_unit_size(tag_type) * self.count as usize;
        debug!("Loading data at {}: {} bytes", offset, data_size);

        view.seek(SeekFrom::Start(offset))?;
        if data_size > (view.len() - offset) as usize {
            log::error!("TIFFEntry: data size too large");
            return Err(Error::FormatError);
        }
        let mut data = uninit_vec!(data_size);
        view.read_exact(&mut data)?;

        Ok(data)
    }

    /// Load the data for the entry from the `io::View`.
    /// It doesn't check if the value is inline.
    pub(crate) fn load_data<E>(&mut self, base_offset: u32, view: &mut View) -> Result<usize>
    where
        E: ByteOrder,
    {
        if let DataBytes::External(_) = self.data {
            return Err(Error::AlreadyInited);
        }

        let offset = E::read_u32(self.data.as_slice());
        let actual_offset = offset as u64 + base_offset as u64;
        let data = self.load_data_impl(actual_offset, view)?;

        let bytes = data.len();
        if self.type_ == TagType::Undefined as i16 {
            self.set_offset(offset, data);
        } else {
            self.data = DataBytes::External(data);
        }

        Ok(bytes)
    }

    /// Get the value at index.
    pub(crate) fn value_at_index<T, E>(&self, index: u32) -> Option<T>
    where
        T: ExifValue,
        E: ByteOrder,
    {
        self.value_at_index_::<T, E>(index, false)
    }

    /// Get the value at index. Ignore typing if `untyped` is true.
    fn value_at_index_<T, E>(&self, index: u32, untyped: bool) -> Option<T>
    where
        T: ExifValue,
        E: ByteOrder,
    {
        if untyped
            || self.type_ == exif::TagType::Undefined as i16
            || (self.type_ == T::exif_type() as i16)
        {
            if index >= self.count {
                log::error!("index {} is >= {}", index, self.count);
                return None;
            }
            return Some(T::read::<E>(
                &self.data.as_slice()[T::unit_size() * index as usize..],
            ));
        }
        log::error!(
            "Entry {:x}({}) incorrect type {} for {:?}",
            self.id,
            self.id,
            self.type_,
            T::exif_type()
        );
        None
    }

    /// Get the uint value at index. Ignore typing between SHORT, LONG
    /// and RATIONAL. Also in case of RATIONAL it will calculate it.
    fn uint_value_at_index<E>(&self, index: u32) -> Option<u32>
    where
        E: ByteOrder,
    {
        if index >= self.count {
            log::error!("index {} is >= {}", index, self.count);
            return None;
        }
        exif::TagType::try_from(self.type_)
            .ok()
            .and_then(|typ| match typ {
                TagType::Short => Some(u16::read::<E>(
                    &self.data.as_slice()[u16::unit_size() * index as usize..],
                ) as u32),
                TagType::Long => Some(u32::read::<E>(
                    &self.data.as_slice()[u32::unit_size() * index as usize..],
                )),
                TagType::Rational => self.value::<Rational, E>().map(|r| r.num / r.denom),
                _ => {
                    log::error!("incorrect type {} for uint {}", self.type_, self.id);
                    None
                }
            })
    }

    /// Get the signed int value at index. Ignore typing between SSHORT
    /// and SLONG
    fn int_value_at_index<E>(&self, index: u32) -> Option<i32>
    where
        E: ByteOrder,
    {
        if index >= self.count {
            log::error!("index {} is >= {}", index, self.count);
            return None;
        }
        exif::TagType::try_from(self.type_)
            .ok()
            .and_then(|typ| match typ {
                TagType::SShort => Some(i16::read::<E>(
                    &self.data.as_slice()[i16::unit_size() * index as usize..],
                ) as i32),
                TagType::SLong => Some(i32::read::<E>(
                    &self.data.as_slice()[i32::unit_size() * index as usize..],
                )),
                _ => {
                    log::error!("incorrect type {} for uint {}", self.type_, self.id);
                    None
                }
            })
    }

    /// Get the value out of the entry, ignoring the type.
    pub(crate) fn value_untyped<T, E>(&self) -> Option<T>
    where
        T: ExifValue,
        E: ByteOrder,
    {
        self.value_at_index_::<T, E>(0, true)
    }

    /// Get an uint value out of the entry
    pub fn uint_value<E>(&self) -> Option<u32>
    where
        E: ByteOrder,
    {
        self.uint_value_at_index::<E>(0)
    }

    /// Get an int value out of the entry
    pub fn int_value<E>(&self) -> Option<i32>
    where
        E: ByteOrder,
    {
        self.int_value_at_index::<E>(0)
    }

    /// Get the string value out of the entry.
    pub fn string_value(&self) -> Option<String> {
        if self.type_ == exif::TagType::Ascii as i16 {
            return Some(String::read::<NativeEndian>(self.data.as_slice()));
        }
        log::error!(
            "Entry {:x}({}) incorrect type {} for {:?}",
            self.id,
            self.id,
            self.type_,
            exif::TagType::Ascii
        );
        None
    }

    /// Get the value out of the entry.
    pub(crate) fn value<T, E>(&self) -> Option<T>
    where
        T: ExifValue,
        E: ByteOrder,
    {
        self.value_at_index_::<T, E>(0, false)
    }

    /// Get the value array out of the entry, using `endian`.
    pub fn uint_value_array(&self, endian: Endian) -> Option<Vec<u32>> {
        let type_ = match exif::TagType::try_from(self.type_) {
            Ok(t @ TagType::Short) | Ok(t @ TagType::Long) => t,
            Ok(TagType::Rational) => {
                return self
                    .value_array::<Rational>(endian)
                    .map(|v| v.iter().map(|r| r.into()).collect())
            }
            _ => {
                log::error!("incorrect type {} for uint {}", self.type_, self.id);
                return None;
            }
        };
        let unit_size = match type_ {
            TagType::Short => u16::unit_size(),
            TagType::Long => u32::unit_size(),
            _ => unreachable!(),
        };

        let data_slice = self.data.as_slice();
        let count = self.count as usize;
        let mut values = Vec::with_capacity(count);
        for index in 0..count {
            let slice = &data_slice[unit_size * index..];
            let v = match type_ {
                TagType::Short => {
                    (match endian {
                        Endian::Big => u16::read::<BigEndian>(slice),
                        Endian::Little => u16::read::<LittleEndian>(slice),
                        _ => unreachable!(),
                    }) as u32
                }
                TagType::Long => match endian {
                    Endian::Big => u32::read::<BigEndian>(slice),
                    Endian::Little => u32::read::<LittleEndian>(slice),
                    _ => unreachable!(),
                },
                _ => unreachable!(),
            };
            values.push(v);
        }
        Some(values)
    }

    /// Get the value array out of the entry, using `endian`.
    pub fn float_value_array(&self, endian: Endian) -> Option<Vec<f64>> {
        let type_ = match exif::TagType::try_from(self.type_) {
            Ok(TagType::Short) | Ok(TagType::Long) => {
                return self
                    .uint_value_array(endian)
                    .map(|v| v.iter().map(|v| *v as f64).collect())
            }
            Ok(TagType::Rational) => {
                return self
                    .value_array::<Rational>(endian)
                    .map(|v| v.iter().map(|r| r.into()).collect())
            }
            Ok(TagType::SRational) => {
                return self
                    .value_array::<SRational>(endian)
                    .map(|v| v.iter().map(|r| r.into()).collect())
            }
            Ok(t @ TagType::Float) | Ok(t @ TagType::Double) => t,
            _ => {
                log::error!("incorrect type {} for uint {}", self.type_, self.id);
                return None;
            }
        };
        let unit_size = match type_ {
            TagType::Float => f32::unit_size(),
            TagType::Double => f64::unit_size(),
            _ => unreachable!(),
        };

        let data_slice = self.data.as_slice();
        let count = self.count as usize;
        let mut values = Vec::with_capacity(count);
        for index in 0..count {
            let slice = &data_slice[unit_size * index..];
            let v = match type_ {
                TagType::Float => {
                    (match endian {
                        Endian::Big => f32::read::<BigEndian>(slice),
                        Endian::Little => f32::read::<LittleEndian>(slice),
                        _ => unreachable!(),
                    }) as f64
                }
                TagType::Double => match endian {
                    Endian::Big => f64::read::<BigEndian>(slice),
                    Endian::Little => f64::read::<LittleEndian>(slice),
                    _ => unreachable!(),
                },
                _ => unreachable!(),
            };
            values.push(v);
        }
        Some(values)
    }

    /// Get the value array out of the entry, using `endian`.
    pub fn int_value_array(&self, endian: Endian) -> Option<Vec<i32>> {
        let type_ = match exif::TagType::try_from(self.type_) {
            Ok(t @ TagType::SShort) | Ok(t @ TagType::SLong) => t,
            _ => {
                log::error!("incorrect type {} for uint {}", self.type_, self.id);
                return None;
            }
        };
        let unit_size = match type_ {
            TagType::SShort => i16::unit_size(),
            TagType::SLong => i32::unit_size(),
            _ => unreachable!(),
        };

        let data_slice = self.data.as_slice();
        let count = self.count as usize;
        let mut values = Vec::with_capacity(count);
        for index in 0..count {
            let slice = &data_slice[unit_size * index..];
            let v = match type_ {
                TagType::SShort => {
                    (match endian {
                        Endian::Big => i16::read::<BigEndian>(slice),
                        Endian::Little => i16::read::<LittleEndian>(slice),
                        _ => unreachable!(),
                    }) as i32
                }
                TagType::SLong => match endian {
                    Endian::Big => i32::read::<BigEndian>(slice),
                    Endian::Little => i32::read::<LittleEndian>(slice),
                    _ => unreachable!(),
                },
                _ => unreachable!(),
            };
            values.push(v);
        }
        Some(values)
    }

    /// Get the value array out of the entry, using `endian`.
    pub(crate) fn value_array<T>(&self, endian: Endian) -> Option<Vec<T>>
    where
        T: ExifValue,
    {
        let data_slice = self.data.as_slice();
        let count = if self.type_ == TagType::Undefined as i16 {
            // count is in bytes
            self.count as usize / T::unit_size()
        } else {
            self.count as usize
        };
        if !T::is_array()
            && ((self.type_ == T::exif_type() as i16) || (self.type_ == TagType::Undefined as i16))
        {
            let mut values = Vec::with_capacity(count);
            for index in 0..count {
                let slice = &data_slice[T::unit_size() * index..];
                let v = match endian {
                    Endian::Big => T::read::<BigEndian>(slice),
                    Endian::Little => T::read::<LittleEndian>(slice),
                    _ => unreachable!(),
                };
                values.push(v);
            }
            Some(values)
        } else {
            log::error!("incorrect type {} for {:?}", self.type_, T::exif_type());
            None
        }
    }

    #[cfg(feature = "dump")]
    pub(crate) fn write_dump_entry<W>(
        &self,
        out: &mut W,
        indent: u32,
        endian: Endian,
        args: HashMap<&str, String>,
    ) where
        W: std::io::Write + ?Sized,
    {
        fn array_to_str<V>(array: &[V]) -> String
        where
            V: ToString,
        {
            if array.len() == 1 {
                array[0].to_string()
            } else {
                let mut s = String::from("[ ");
                for (i, v) in array.iter().enumerate() {
                    if i > 0 {
                        s.push_str(", ");
                    }
                    if i > 5 {
                        s.push_str("...");
                        break;
                    }
                    s.push_str(&v.to_string());
                }
                s.push_str(" ]");

                s
            }
        }

        fn value(e: &Entry, endian: Endian) -> String {
            match TagType::try_from(e.type_) {
                Ok(TagType::Ascii) => e.string_value().map(|v| format!("\"{v}\"")),
                Ok(TagType::Byte) => e
                    .value_array::<u8>(endian)
                    .as_ref()
                    .map(|v| array_to_str(v)),
                Ok(TagType::SByte) => e
                    .value_array::<i8>(endian)
                    .as_ref()
                    .map(|v| array_to_str(v)),
                Ok(TagType::Short) | Ok(TagType::Long) => {
                    e.uint_value_array(endian).as_ref().map(|v| array_to_str(v))
                }
                Ok(TagType::SShort) | Ok(TagType::SLong) => {
                    e.int_value_array(endian).as_ref().map(|v| array_to_str(v))
                }
                Ok(TagType::Rational) => e
                    .value_array::<Rational>(endian)
                    .as_ref()
                    .map(|v| array_to_str(v)),
                Ok(TagType::SRational) => e
                    .value_array::<SRational>(endian)
                    .as_ref()
                    .map(|v| array_to_str(v)),
                Ok(TagType::Float) => e
                    .value_array::<f32>(endian)
                    .as_ref()
                    .map(|v| array_to_str(v)),
                Ok(TagType::Double) => e
                    .value_array::<f64>(endian)
                    .as_ref()
                    .map(|v| array_to_str(v)),
                Ok(TagType::Undefined) => Some(
                    e.value_array::<u8>(endian)
                        .as_ref()
                        .map_or_else(|| array_to_str(e.data()), |d| array_to_str(d)),
                ),
                Err(_) => None,
                _ => Some("VALUE".to_string()),
            }
            .or_else(|| Some("ERROR".to_string()))
            .unwrap()
        }

        let type_: &str = TagType::try_from(self.type_)
            .map(|t| t.into())
            .unwrap_or("ERROR");
        let tag_name = args.get("tag_name").cloned().unwrap_or_default();
        let value = value(self, endian);
        dump_writeln!(
            out,
            indent,
            "<0x{:04x}={:>5}> {:<30} [{:>2}={:<10} {}] = {}",
            self.id,
            self.id,
            tag_name,
            self.type_,
            type_,
            self.count,
            value
        );
    }
}

#[cfg(test)]
mod test {
    use byteorder::{BigEndian, ByteOrder, LittleEndian};

    use super::Entry;

    use crate::container::Endian;
    use crate::tiff::exif::TagType;
    use crate::Error;

    #[test]
    fn test_entry_get_value() {
        let e = Entry::new(0, TagType::Byte as i16, 3, [10, 20, 30, 0]);
        assert_eq!(e.value_at_index::<u8, LittleEndian>(3), None);
        assert_eq!(e.value::<u16, LittleEndian>(), None);
        assert_eq!(e.value_at_index::<u8, LittleEndian>(2), Some(30));
        // testing value_array
        assert_eq!(
            e.value_array::<u8>(Endian::Little),
            Some(vec![10_u8, 20, 30])
        );
        assert_eq!(e.value_array::<u16>(Endian::Little), None);

        // test Ascii to `String`
        let e = Entry::new(0, TagType::Ascii as i16, 4, *b"asci");
        assert_eq!(e.string_value(), Some(String::from("asci")));

        // test Ascii with trailing NUL to `String`
        let e = Entry::new(0, TagType::Ascii as i16, 4, *b"asc\0");
        assert_eq!(e.string_value(), Some(String::from("asc")));

        let mut buf = [0_u8; 4];
        LittleEndian::write_f32(&mut buf, 3.15);
        let e = Entry::new(0, TagType::Float as i16, 1, buf);
        assert_eq!(e.value::<f32, LittleEndian>(), Some(3.15));

        BigEndian::write_f32(&mut buf, 3.15);
        let e = Entry::new(0, TagType::Float as i16, 1, buf);
        assert_eq!(e.value::<f32, BigEndian>(), Some(3.15));
    }

    #[test]
    fn test_load_value() {
        use crate::io;

        let buf = Vec::from(b"abcdedfgijkl".as_slice());
        let length = buf.len() as u64;

        let cursor = Box::new(std::io::Cursor::new(buf));
        let viewer = std::rc::Rc::new(io::Viewer::new(cursor, length));

        let view = io::Viewer::create_view(&viewer, 0);
        assert!(view.is_ok());
        let mut view = view.unwrap();

        // Little endian

        let mut e = Entry::new(0, TagType::Ascii as i16, 8, [4, 0, 0, 0]);
        let r = e.load_data::<LittleEndian>(0, &mut view);
        assert!(matches!(r, Ok(8)));
        assert_eq!(e.string_value(), Some(String::from("edfgijkl")));
        // Trying to load again should fail.
        let r = e.load_data::<LittleEndian>(0, &mut view);
        assert!(matches!(r, Err(Error::AlreadyInited)));

        // Big endian
        let mut e = Entry::new(0, TagType::Ascii as i16, 8, [0, 0, 0, 4]);
        let r = e.load_data::<BigEndian>(0, &mut view);
        assert!(matches!(r, Ok(8)));
        assert_eq!(e.string_value(), Some(String::from("edfgijkl")));
        assert_eq!(e.uint_value::<LittleEndian>(), None);

        // Undefined
        let e = Entry::new(0, TagType::Undefined as i16, 4, [4, 0, 8, 0]);
        let r = e.value_array::<u16>(Endian::Little);
        assert_eq!(r, Some(vec![4_u16, 8]));
        // Testing round of data
        let e = Entry::new(0, TagType::Undefined as i16, 3, [4, 0, 0, 0]);
        let r = e.value_array::<u16>(Endian::Little);
        assert_eq!(r, Some(vec![4_u16]));
    }

    #[test]
    fn test_uint_value() {
        // uint_value
        let e = Entry::new(0, TagType::Short as i16, 2, [4, 0, 3, 0]);
        assert_eq!(e.uint_value::<LittleEndian>(), Some(4));
        assert_eq!(e.uint_value_at_index::<LittleEndian>(1), Some(3));
        // out of range
        assert_eq!(e.uint_value_at_index::<LittleEndian>(2), None);
        assert_eq!(e.uint_value_array(Endian::Little), Some(vec![4, 3]),);

        let e = Entry::new(0, TagType::Long as i16, 1, [4, 0, 0, 0]);
        assert_eq!(e.uint_value::<LittleEndian>(), Some(4));
        // incorrect type
        let e = Entry::new(0, TagType::SLong as i16, 1, [4, 0, 0, 0]);
        assert_eq!(e.uint_value::<LittleEndian>(), None);
    }
}