Line data Source code
1 : // Copyright (C) 2018 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.entities.converter; 16 : 17 : import com.google.errorprone.annotations.Immutable; 18 : import com.google.gerrit.entities.Change; 19 : import com.google.gerrit.entities.ChangeMessage; 20 : import com.google.gerrit.proto.Entities; 21 : import com.google.protobuf.Parser; 22 : 23 2 : @Immutable 24 2 : public enum ChangeMessageKeyProtoConverter 25 : implements ProtoConverter<Entities.ChangeMessage_Key, ChangeMessage.Key> { 26 2 : INSTANCE; 27 : 28 2 : private final ProtoConverter<Entities.Change_Id, Change.Id> changeIdConverter = 29 : ChangeIdProtoConverter.INSTANCE; 30 : 31 : @Override 32 : public Entities.ChangeMessage_Key toProto(ChangeMessage.Key messageKey) { 33 2 : return Entities.ChangeMessage_Key.newBuilder() 34 2 : .setChangeId(changeIdConverter.toProto(messageKey.changeId())) 35 2 : .setUuid(messageKey.uuid()) 36 2 : .build(); 37 : } 38 : 39 : @Override 40 : public ChangeMessage.Key fromProto(Entities.ChangeMessage_Key proto) { 41 2 : return ChangeMessage.key(changeIdConverter.fromProto(proto.getChangeId()), proto.getUuid()); 42 : } 43 : 44 : @Override 45 : public Parser<Entities.ChangeMessage_Key> getParser() { 46 0 : return Entities.ChangeMessage_Key.parser(); 47 : } 48 : }