blob: 6c8fb510b438b024023507b008a4e4be9270b44f (
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
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "sync/api/attachments/attachment_id.h"
#include <stddef.h>
#include <stdint.h>
#include "base/logging.h"
#include "sync/internal_api/public/base/attachment_id_proto.h"
#include "sync/protocol/sync.pb.h"
namespace syncer {
void AttachmentId::ImmutableAttachmentIdProtoTraits::InitializeWrapper(
Wrapper* wrapper) {
*wrapper = new sync_pb::AttachmentIdProto();
}
void AttachmentId::ImmutableAttachmentIdProtoTraits::DestroyWrapper(
Wrapper* wrapper) {
delete *wrapper;
}
const sync_pb::AttachmentIdProto&
AttachmentId::ImmutableAttachmentIdProtoTraits::Unwrap(const Wrapper& wrapper) {
return *wrapper;
}
sync_pb::AttachmentIdProto*
AttachmentId::ImmutableAttachmentIdProtoTraits::UnwrapMutable(
Wrapper* wrapper) {
return *wrapper;
}
void AttachmentId::ImmutableAttachmentIdProtoTraits::Swap(
sync_pb::AttachmentIdProto* t1,
sync_pb::AttachmentIdProto* t2) {
t1->Swap(t2);
}
AttachmentId::~AttachmentId() {}
bool AttachmentId::operator==(const AttachmentId& other) const {
return proto_.Get().unique_id() == other.proto_.Get().unique_id();
}
bool AttachmentId::operator!=(const AttachmentId& other) const {
return !operator==(other);
}
bool AttachmentId::operator<(const AttachmentId& other) const {
return proto_.Get().unique_id() < other.proto_.Get().unique_id();
}
// Static.
AttachmentId AttachmentId::Create(size_t size, uint32_t crc32c) {
sync_pb::AttachmentIdProto proto = CreateAttachmentIdProto(size, crc32c);
return AttachmentId(&proto);
}
// Static.
AttachmentId AttachmentId::CreateFromProto(
const sync_pb::AttachmentIdProto& proto) {
sync_pb::AttachmentIdProto copy_of_proto(proto);
return AttachmentId(©_of_proto);
}
const sync_pb::AttachmentIdProto& AttachmentId::GetProto() const {
return proto_.Get();
}
AttachmentId::AttachmentId(sync_pb::AttachmentIdProto* proto)
: proto_(proto) {}
AttachmentId::AttachmentId(const AttachmentId& other) = default;
size_t AttachmentId::GetSize() const {
return proto_.Get().size_bytes();
}
uint32_t AttachmentId::GetCrc32c() const {
return proto_.Get().crc32c();
}
} // namespace syncer
|