2020-12-12 08:00:42 +00:00
|
|
|
// Copyright 2020 Google LLC
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// https://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
use std::fmt::Debug;
|
|
|
|
use std::path::PathBuf;
|
|
|
|
|
2022-11-02 16:35:56 +00:00
|
|
|
use crate::op_store::{OpStore, OpStoreResult, Operation, OperationId, View, ViewId};
|
|
|
|
use crate::proto_op_store::ProtoOpStore;
|
2020-12-12 08:00:42 +00:00
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct SimpleOpStore {
|
2022-11-02 16:35:56 +00:00
|
|
|
delegate: ProtoOpStore,
|
2020-12-12 08:00:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl SimpleOpStore {
|
|
|
|
pub fn init(store_path: PathBuf) -> Self {
|
2022-11-02 16:35:56 +00:00
|
|
|
let delegate = ProtoOpStore::init(store_path);
|
|
|
|
SimpleOpStore { delegate }
|
2020-12-12 08:00:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn load(store_path: PathBuf) -> Self {
|
2022-11-02 16:35:56 +00:00
|
|
|
let delegate = ProtoOpStore::load(store_path);
|
|
|
|
SimpleOpStore { delegate }
|
2020-12-12 08:00:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl OpStore for SimpleOpStore {
|
|
|
|
fn read_view(&self, id: &ViewId) -> OpStoreResult<View> {
|
2022-11-02 16:35:56 +00:00
|
|
|
self.delegate.read_view(id)
|
2020-12-12 08:00:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn write_view(&self, view: &View) -> OpStoreResult<ViewId> {
|
2022-11-02 16:35:56 +00:00
|
|
|
self.delegate.write_view(view)
|
2020-12-12 08:00:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn read_operation(&self, id: &OperationId) -> OpStoreResult<Operation> {
|
2022-11-02 16:35:56 +00:00
|
|
|
self.delegate.read_operation(id)
|
2020-12-12 08:00:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn write_operation(&self, operation: &Operation) -> OpStoreResult<OperationId> {
|
2022-11-02 16:35:56 +00:00
|
|
|
self.delegate.write_operation(operation)
|
2021-07-31 00:47:30 +00:00
|
|
|
}
|
|
|
|
}
|