Home | History | Annotate | Download | only in HidUtils
      1 /*
      2  * Copyright (C) 2017 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 #ifndef HIDUTIL_HIDITEM_H_
     17 #define HIDUTIL_HIDITEM_H_
     18 
     19 #include <cstdlib>
     20 #include <vector>
     21 #include <istream>
     22 #include <ostream>
     23 
     24 namespace HidUtil {
     25 
     26 struct HidItem {
     27     bool valid;
     28     unsigned int type;
     29     unsigned int tag;
     30     ssize_t offset;
     31     ssize_t byteSize;
     32     std::vector<uint8_t> data;
     33 
     34     bool dataAsUnsigned(unsigned int *out) const;
     35     bool dataAsSigned(int *out) const;
     36 
     37     // friend stream functions
     38     friend std::istream& operator>>(std::istream &is, HidItem &h);
     39     friend std::ostream& operator<<(std::ostream &os, const HidItem &h);
     40 
     41     // tokenize from a unsigned char vector
     42     static std::vector<HidItem> tokenize(const std::vector<uint8_t> &descriptor);
     43     static std::vector<HidItem> tokenize(const uint8_t *begin, size_t size);
     44     static std::vector<HidItem> tokenize(std::istream &is);
     45 };
     46 
     47 // parsing in from binary stream
     48 std::istream& operator>>(std::istream &is, HidUtil::HidItem &h);
     49 
     50 // output as human readable string to stream
     51 std::ostream& operator<<(std::ostream &os, const HidUtil::HidItem &h);
     52 } //namespace HidUtil
     53 
     54 #endif // HIDUTIL_HIDITEM_H_
     55