Line data Source code
1 : // Copyright (C) 2020 The Android Open Source Project 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 : package com.google.gerrit.server.cache.serialize.entities; 16 : 17 : import com.google.gerrit.entities.Project; 18 : import com.google.gerrit.entities.SubscribeSection; 19 : import com.google.gerrit.server.cache.proto.Cache; 20 : 21 : /** Helper to (de)serialize values for caches. */ 22 : public class SubscribeSectionSerializer { 23 : public static SubscribeSection deserialize(Cache.SubscribeSectionProto proto) { 24 1 : SubscribeSection.Builder builder = 25 1 : SubscribeSection.builder(Project.nameKey(proto.getProjectName())); 26 1 : proto.getMatchingRefSpecsList().forEach(rs -> builder.addMatchingRefSpec(rs)); 27 1 : proto.getMultiMatchRefSpecsList().forEach(rs -> builder.addMultiMatchRefSpec(rs)); 28 1 : return builder.build(); 29 : } 30 : 31 : public static Cache.SubscribeSectionProto serialize(SubscribeSection autoValue) { 32 : Cache.SubscribeSectionProto.Builder builder = 33 1 : Cache.SubscribeSectionProto.newBuilder().setProjectName(autoValue.project().get()); 34 1 : autoValue.multiMatchRefSpecsAsString().forEach(rs -> builder.addMultiMatchRefSpecs(rs)); 35 1 : autoValue.matchingRefSpecsAsString().forEach(rs -> builder.addMatchingRefSpecs(rs)); 36 1 : return builder.build(); 37 : } 38 : 39 : private SubscribeSectionSerializer() {} 40 : }