예제 #1
0
class PersonCoderImpl(coder_impl.StreamCoderImpl):
  _int_coder_impl = coder_impl.VarIntCoderImpl()
  _str_coder_impl = StrUtf8Coder().get_impl()
  _time_coder_impl = coder_impl.TimestampCoderImpl()

  def encode_to_stream(self, value, stream, nested):
    self._int_coder_impl.encode_to_stream(value.id, stream, True)
    self._str_coder_impl.encode_to_stream(value.name, stream, True)
    self._str_coder_impl.encode_to_stream(value.email_address, stream, True)
    self._str_coder_impl.encode_to_stream(value.credit_card, stream, True)
    self._str_coder_impl.encode_to_stream(value.city, stream, True)
    self._str_coder_impl.encode_to_stream(value.state, stream, True)
    self._time_coder_impl.encode_to_stream(value.date_time, stream, True)
    self._str_coder_impl.encode_to_stream(value.extra, stream, True)

  def decode_from_stream(self, stream, nested):
    id = self._int_coder_impl.decode_from_stream(stream, True)
    name = self._str_coder_impl.decode_from_stream(stream, True)
    email = self._str_coder_impl.decode_from_stream(stream, True)
    credit_card = self._str_coder_impl.decode_from_stream(stream, True)
    city = self._str_coder_impl.decode_from_stream(stream, True)
    state = self._str_coder_impl.decode_from_stream(stream, True)
    date_time = self._time_coder_impl.decode_from_stream(stream, True)
    extra = self._str_coder_impl.decode_from_stream(stream, True)
    return Person(id, name, email, credit_card, city, state, date_time, extra)
예제 #2
0
class AuctionCoderImpl(coder_impl.StreamCoderImpl):
    _int_coder_impl = coder_impl.VarIntCoderImpl()
    _str_coder_impl = StrUtf8Coder().get_impl()
    _time_coder_impl = coder_impl.TimestampCoderImpl()

    def encode_to_stream(self, value, stream, nested):
        self._int_coder_impl.encode_to_stream(value.id, stream, True)
        self._str_coder_impl.encode_to_stream(value.item_name, stream, True)
        self._str_coder_impl.encode_to_stream(value.description, stream, True)
        self._int_coder_impl.encode_to_stream(value.initial_bid, stream, True)
        self._int_coder_impl.encode_to_stream(value.reserve, stream, True)
        self._time_coder_impl.encode_to_stream(value.date_time, stream, True)
        self._time_coder_impl.encode_to_stream(value.expires, stream, True)
        self._int_coder_impl.encode_to_stream(value.seller, stream, True)
        self._int_coder_impl.encode_to_stream(value.category, stream, True)
        self._str_coder_impl.encode_to_stream(value.extra, stream, True)

    def decode_from_stream(self, stream, nested):
        id = self._int_coder_impl.decode_from_stream(stream, True)
        item_name = self._str_coder_impl.decode_from_stream(stream, True)
        description = self._str_coder_impl.decode_from_stream(stream, True)
        initial_bid = self._int_coder_impl.decode_from_stream(stream, True)
        reserve = self._int_coder_impl.decode_from_stream(stream, True)
        date_time = self._time_coder_impl.decode_from_stream(stream, True)
        expires = self._time_coder_impl.decode_from_stream(stream, True)
        seller = self._int_coder_impl.decode_from_stream(stream, True)
        category = self._int_coder_impl.decode_from_stream(stream, True)
        extra = self._str_coder_impl.decode_from_stream(stream, True)
        return Auction(id, item_name, description, initial_bid, reserve,
                       date_time, expires, seller, category, extra)
예제 #3
0
class AuctionPriceCoderImpl(coder_impl.StreamCoderImpl):
    _int_coder_impl = coder_impl.VarIntCoderImpl()

    def encode_to_stream(self, value, stream, nested):
        self._int_coder_impl.encode_to_stream(value.auction, stream, True)
        self._int_coder_impl.encode_to_stream(value.price, stream, True)

    def decode_from_stream(self, stream, nested):

        auction = self._int_coder_impl.decode_from_stream(stream, True)
        price = self._int_coder_impl.decode_from_stream(stream, True)
        return AuctionPrice(auction, price)
예제 #4
0
class AuctionOrBidWindowCoderImpl(coder_impl.StreamCoderImpl):
  _super_coder_impl = coder_impl.IntervalWindowCoderImpl()
  _id_coder_impl = coder_impl.VarIntCoderImpl()
  _bool_coder_impl = coder_impl.BooleanCoderImpl()

  def encode_to_stream(self, value, stream, nested):
    self._super_coder_impl.encode_to_stream(value, stream, True)
    self._id_coder_impl.encode_to_stream(value.auction, stream, True)
    self._bool_coder_impl.encode_to_stream(
        value.is_auction_window, stream, True)

  def decode_from_stream(self, stream, nested):
    super_window = self._super_coder_impl.decode_from_stream(stream, True)
    auction = self._id_coder_impl.decode_from_stream(stream, True)
    is_auction = self._bool_coder_impl.decode_from_stream(stream, True)
    return AuctionOrBidWindow(
        super_window.start, super_window.end, auction, is_auction)
예제 #5
0
class BidCoderImpl(coder_impl.StreamCoderImpl):
  _int_coder_impl = coder_impl.VarIntCoderImpl()
  _str_coder_impl = StrUtf8Coder().get_impl()
  _time_coder_impl = coder_impl.TimestampCoderImpl()

  def encode_to_stream(self, value, stream, nested):
    self._int_coder_impl.encode_to_stream(value.auction, stream, True)
    self._int_coder_impl.encode_to_stream(value.bidder, stream, True)
    self._int_coder_impl.encode_to_stream(value.price, stream, True)
    self._time_coder_impl.encode_to_stream(value.date_time, stream, True)
    self._str_coder_impl.encode_to_stream(value.extra, stream, True)

  def decode_from_stream(self, stream, nested):
    auction = self._int_coder_impl.decode_from_stream(stream, True)
    bidder = self._int_coder_impl.decode_from_stream(stream, True)
    price = self._int_coder_impl.decode_from_stream(stream, True)
    date_time = self._time_coder_impl.decode_from_stream(stream, True)
    extra = self._str_coder_impl.decode_from_stream(stream, True)
    return Bid(auction, bidder, price, date_time, extra)
예제 #6
0
파일: coders.py 프로젝트: zoltan-kski/beam
 def _create_impl(self):
     return coder_impl.VarIntCoderImpl()