1// Copyright 2015 Google Inc. All rights reserved
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//      http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15// +build ignore
16
17#include "io.h"
18
19#include "log.h"
20
21void DumpInt(FILE* fp, int v) {
22  size_t r = fwrite(&v, sizeof(v), 1, fp);
23  CHECK(r == 1);
24}
25
26void DumpString(FILE* fp, StringPiece s) {
27  DumpInt(fp, s.size());
28  size_t r = fwrite(s.data(), 1, s.size(), fp);
29  CHECK(r == s.size());
30}
31
32int LoadInt(FILE* fp) {
33  int v;
34  size_t r = fread(&v, sizeof(v), 1, fp);
35  if (r != 1)
36    return -1;
37  return v;
38}
39
40bool LoadString(FILE* fp, string* s) {
41  int len = LoadInt(fp);
42  if (len < 0)
43    return false;
44  s->resize(len);
45  size_t r = fread(&(*s)[0], 1, s->size(), fp);
46  if (r != s->size())
47    return false;
48  return true;
49}
50