1 /* SPDX-License-Identifier: GPL-2.0-only */
11 size_t bgets(struct buffer
*input
, void *output
, size_t len
)
13 len
= input
->size
< len
? input
->size
: len
;
14 memmove(output
, input
->data
, len
);
20 size_t bputs(struct buffer
*b
, const void *data
, size_t len
)
22 memmove(&b
->data
[b
->size
], data
, len
);
27 /* The assumption in all this code is that we're given a pointer to enough data.
28 * Hence, we do not check for underflow.
30 static uint8_t get8(struct buffer
*input
)
32 uint8_t ret
= *input
->data
++;
37 static uint16_t get16be(struct buffer
*input
)
40 ret
= get8(input
) << 8;
45 static uint32_t get32be(struct buffer
*input
)
48 ret
= get16be(input
) << 16;
49 ret
|= get16be(input
);
53 static uint64_t get64be(struct buffer
*input
)
58 ret
|= get32be(input
);
62 static void put8(struct buffer
*input
, uint8_t val
)
64 input
->data
[input
->size
] = val
;
68 static void put16be(struct buffer
*input
, uint16_t val
)
70 put8(input
, val
>> 8);
74 static void put32be(struct buffer
*input
, uint32_t val
)
76 put16be(input
, val
>> 16);
80 static void put64be(struct buffer
*input
, uint64_t val
)
82 put32be(input
, val
>> 32);
86 static uint16_t get16le(struct buffer
*input
)
90 ret
|= get8(input
) << 8;
94 static uint32_t get32le(struct buffer
*input
)
98 ret
|= get16le(input
) << 16;
102 static uint64_t get64le(struct buffer
*input
)
106 low
= get32le(input
);
107 ret
= get32le(input
);
113 static void put16le(struct buffer
*input
, uint16_t val
)
116 put8(input
, val
>> 8);
119 static void put32le(struct buffer
*input
, uint32_t val
)
122 put16le(input
, val
>> 16);
125 static void put64le(struct buffer
*input
, uint64_t val
)
128 put32le(input
, val
>> 32);
131 struct xdr xdr_be
= {
132 get8
, get16be
, get32be
, get64be
,
133 put8
, put16be
, put32be
, put64be
136 struct xdr xdr_le
= {
137 get8
, get16le
, get32le
, get64le
,
138 put8
, put16le
, put32le
, put64le