github.com/apache/beam/sdks/v2@v2.48.2/python/apache_beam/testing/benchmarks/nexmark/models/auction_bid.py (about) 1 # 2 # Licensed to the Apache Software Foundation (ASF) under one or more 3 # contributor license agreements. See the NOTICE file distributed with 4 # this work for additional information regarding copyright ownership. 5 # The ASF licenses this file to You under the Apache License, Version 2.0 6 # (the "License"); you may not use this file except in compliance with 7 # the License. You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 # 17 18 """Result of WinningBid transform.""" 19 from apache_beam.coders import coder_impl 20 from apache_beam.coders.coders import FastCoder 21 from apache_beam.testing.benchmarks.nexmark import nexmark_util 22 from apache_beam.testing.benchmarks.nexmark.models import nexmark_model 23 24 25 class AuctionBidCoder(FastCoder): 26 def to_type_hint(self): 27 return AuctionBid 28 29 def _create_impl(self): 30 return AuctionBidCoderImpl() 31 32 def is_deterministic(self): 33 return True 34 35 36 class AuctionBid(object): 37 CODER = AuctionBidCoder() 38 39 def __init__(self, auction, bid): 40 self.auction = auction 41 self.bid = bid 42 43 def __repr__(self): 44 return nexmark_util.model_to_json(self) 45 46 47 class AuctionBidCoderImpl(coder_impl.StreamCoderImpl): 48 _auction_coder_impl = nexmark_model.AuctionCoderImpl() 49 _bid_coder_Impl = nexmark_model.BidCoderImpl() 50 51 def encode_to_stream(self, value, stream, nested): 52 self._auction_coder_impl.encode_to_stream(value.auction, stream, True) 53 self._bid_coder_Impl.encode_to_stream(value.bid, stream, True) 54 55 def decode_from_stream(self, stream, nested): 56 auction = self._auction_coder_impl.decode_from_stream(stream, True) 57 bid = self._bid_coder_Impl.decode_from_stream(stream, True) 58 return AuctionBid(auction, bid)