def encode_request(name, entries): buf = create_initial_buffer(_REQUEST_INITIAL_FRAME_SIZE, _REQUEST_MESSAGE_TYPE) StringCodec.encode(buf, name) EntryListCodec.encode(buf, entries, DataCodec.encode, DataCodec.encode, True) return OutboundMessage(buf, False)
def encode(buf, anchor_data_list_holder, is_final=False): buf.extend(BEGIN_FRAME_BUF) ListIntegerCodec.encode(buf, anchor_data_list_holder.anchor_page_list) EntryListCodec.encode(buf, anchor_data_list_holder.anchor_data_list, DataCodec.encode, DataCodec.encode) if is_final: buf.extend(END_FINAL_FRAME_BUF) else: buf.extend(END_FRAME_BUF)
def encode_request(name, entries, trigger_map_loader): buf = create_initial_buffer(_REQUEST_INITIAL_FRAME_SIZE, _REQUEST_MESSAGE_TYPE) FixSizedTypesCodec.encode_boolean(buf, _REQUEST_TRIGGER_MAP_LOADER_OFFSET, trigger_map_loader) StringCodec.encode(buf, name) EntryListCodec.encode(buf, entries, DataCodec.encode, DataCodec.encode, True) return OutboundMessage(buf, False)
def test_entry_list(self): self.mark_initial_frame_as_non_final() entries = [("a", "1"), ("b", "2"), ("c", "3")] EntryListCodec.encode(self.buf, entries, StringCodec.encode, StringCodec.encode) EntryListCodec.encode_nullable(self.buf, entries, StringCodec.encode, StringCodec.encode) EntryListCodec.encode_nullable(self.buf, None, StringCodec.encode, StringCodec.encode, True) message = self.write_and_decode() message.next_frame() # initial frame self.assertEqual(entries, EntryListCodec.decode(message, StringCodec.decode, StringCodec.decode)) self.assertEqual(entries, EntryListCodec.decode_nullable(message, StringCodec.decode, StringCodec.decode)) self.assertIsNone(EntryListCodec.decode_nullable(message, StringCodec.decode, StringCodec.decode))
def decode_response(msg): msg.next_frame() response = dict() response["response"] = EntryListCodec.decode(msg, DataCodec.decode, DataCodec.decode) response["anchor_data_list"] = AnchorDataListHolderCodec.decode(msg) return response
def decode(msg): msg.next_frame() anchor_page_list = ListIntegerCodec.decode(msg) anchor_data_list = EntryListCodec.decode(msg, DataCodec.decode, DataCodec.decode) CodecUtil.fast_forward_to_end_frame(msg) return AnchorDataListHolder(anchor_page_list, anchor_data_list)
def decode_response(msg): msg.next_frame() return EntryListCodec.decode(msg, DataCodec.decode, DataCodec.decode)