|
| 1 | +/* |
| 2 | + * Copyright (c) 2008-2022, Hazelcast, Inc. All Rights Reserved. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +/** |
| 17 | + * Auto-generated by Hazelcast Client Protocol Code Generator. |
| 18 | + * |
| 19 | + * @generated Hazelcast Client Protocol Code Generator @e5b5a6b |
| 20 | + * @see <a href="https://github.com/hazelcast/hazelcast-client-protocol">Protocol Generator</a> |
| 21 | + * DO NOT MODIFY. Changes to this file will be lost when the code is regenerated. |
| 22 | + */ |
| 23 | + |
| 24 | +/* eslint-disable max-len */ |
| 25 | +import {BitsUtil} from '../util/BitsUtil'; |
| 26 | +import {FixSizedTypesCodec} from './builtin/FixSizedTypesCodec'; |
| 27 | +import {ClientMessage, Frame, RESPONSE_BACKUP_ACKS_OFFSET, PARTITION_ID_OFFSET} from '../protocol/ClientMessage'; |
| 28 | +import {StringCodec} from './builtin/StringCodec'; |
| 29 | +import {UUID} from '../core/UUID'; |
| 30 | +import * as Long from 'long'; |
| 31 | +import {Data} from '../serialization/Data'; |
| 32 | +import {DataCodec} from './builtin/DataCodec'; |
| 33 | + |
| 34 | +// hex: 0x040200 |
| 35 | +const REQUEST_MESSAGE_TYPE = 262656; |
| 36 | +// hex: 0x040201 |
| 37 | +// RESPONSE_MESSAGE_TYPE = 262657 |
| 38 | +// hex: 0x040202 |
| 39 | +const EVENT_TOPIC_MESSAGE_TYPE = 262658; |
| 40 | + |
| 41 | +const REQUEST_LOCAL_ONLY_OFFSET = PARTITION_ID_OFFSET + BitsUtil.INT_SIZE_IN_BYTES; |
| 42 | +const REQUEST_INITIAL_FRAME_SIZE = REQUEST_LOCAL_ONLY_OFFSET + BitsUtil.BOOLEAN_SIZE_IN_BYTES; |
| 43 | +const RESPONSE_RESPONSE_OFFSET = RESPONSE_BACKUP_ACKS_OFFSET + BitsUtil.BYTE_SIZE_IN_BYTES; |
| 44 | +const EVENT_TOPIC_PUBLISH_TIME_OFFSET = PARTITION_ID_OFFSET + BitsUtil.INT_SIZE_IN_BYTES; |
| 45 | +const EVENT_TOPIC_UUID_OFFSET = EVENT_TOPIC_PUBLISH_TIME_OFFSET + BitsUtil.LONG_SIZE_IN_BYTES; |
| 46 | + |
| 47 | +/** @internal */ |
| 48 | +export class TopicAddMessageListenerCodec { |
| 49 | + static encodeRequest(name: string, localOnly: boolean): ClientMessage { |
| 50 | + const clientMessage = ClientMessage.createForEncode(); |
| 51 | + clientMessage.setRetryable(false); |
| 52 | + |
| 53 | + const initialFrame = Frame.createInitialFrame(REQUEST_INITIAL_FRAME_SIZE); |
| 54 | + FixSizedTypesCodec.encodeBoolean(initialFrame.content, REQUEST_LOCAL_ONLY_OFFSET, localOnly); |
| 55 | + clientMessage.addFrame(initialFrame); |
| 56 | + clientMessage.setMessageType(REQUEST_MESSAGE_TYPE); |
| 57 | + clientMessage.setPartitionId(-1); |
| 58 | + |
| 59 | + StringCodec.encode(clientMessage, name); |
| 60 | + return clientMessage; |
| 61 | + } |
| 62 | + |
| 63 | + static decodeResponse(clientMessage: ClientMessage): UUID { |
| 64 | + const initialFrame = clientMessage.nextFrame(); |
| 65 | + |
| 66 | + return FixSizedTypesCodec.decodeUUID(initialFrame.content, RESPONSE_RESPONSE_OFFSET); |
| 67 | + } |
| 68 | + |
| 69 | + static handle(clientMessage: ClientMessage, handleTopicEvent: (item: Data, publishTime: Long, uuid: UUID) => void = null): void { |
| 70 | + const messageType = clientMessage.getMessageType(); |
| 71 | + if (messageType === EVENT_TOPIC_MESSAGE_TYPE && handleTopicEvent !== null) { |
| 72 | + const initialFrame = clientMessage.nextFrame(); |
| 73 | + const publishTime = FixSizedTypesCodec.decodeLong(initialFrame.content, EVENT_TOPIC_PUBLISH_TIME_OFFSET); |
| 74 | + const uuid = FixSizedTypesCodec.decodeUUID(initialFrame.content, EVENT_TOPIC_UUID_OFFSET); |
| 75 | + const item = DataCodec.decode(clientMessage); |
| 76 | + handleTopicEvent(item, publishTime, uuid); |
| 77 | + return; |
| 78 | + } |
| 79 | + } |
| 80 | +} |
0 commit comments