1 // Copyright 2001,2007 Alan Donovan. All rights reserved.
3 // Author: Alan Donovan <adonovan@google.com>
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
17 // common.h -- common definitions.
20 #ifndef INCLUDED_DEVTOOLS_IJAR_COMMON_H
21 #define INCLUDED_DEVTOOLS_IJAR_COMMON_H
27 namespace devtools_ijar
{
29 typedef unsigned long long u8
;
34 // be = big endian, le = little endian
36 inline u1
get_u1(const u1
*&p
) {
40 inline u2
get_u2be(const u1
*&p
) {
41 u4 x
= (p
[0] << 8) | p
[1];
46 inline u2
get_u2le(const u1
*&p
) {
47 u4 x
= (p
[1] << 8) | p
[0];
52 inline u4
get_u4be(const u1
*&p
) {
53 u4 x
= (p
[0] << 24) | (p
[1] << 16) | (p
[2] << 8) | p
[3];
58 inline u4
get_u4le(const u1
*&p
) {
59 u4 x
= (p
[3] << 24) | (p
[2] << 16) | (p
[1] << 8) | p
[0];
64 inline void put_u1(u1
*&p
, u1 x
) {
68 inline void put_u2be(u1
*&p
, u2 x
) {
73 inline void put_u2le(u1
*&p
, u2 x
) {
78 inline void put_u4be(u1
*&p
, u4 x
) {
80 *p
++ = (x
>> 16) & 0xff;
81 *p
++ = (x
>> 8) & 0xff;
85 inline void put_u4le(u1
*&p
, u4 x
) {
87 *p
++ = (x
>> 8) & 0xff;
88 *p
++ = (x
>> 16) & 0xff;
92 // Copy n bytes from src to p, and advance p.
93 inline void put_n(u1
*&p
, const u1
*src
, size_t n
) {
100 } // namespace devtools_ijar
102 #endif // INCLUDED_DEVTOOLS_IJAR_COMMON_H