2022-01-04 19:04:12 +08:00
|
|
|
// Licensed to the LF AI & Data foundation under one
|
|
|
|
// or more contributor license agreements. See the NOTICE file
|
|
|
|
// distributed with this work for additional information
|
|
|
|
// regarding copyright ownership. The ASF licenses this file
|
|
|
|
// to you under the Apache License, Version 2.0 (the
|
|
|
|
// "License"); you may not use this file except in compliance
|
2021-04-19 13:42:47 +08:00
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
2022-01-04 19:04:12 +08:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2021-04-19 13:42:47 +08:00
|
|
|
//
|
2022-01-04 19:04:12 +08:00
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
2021-04-19 13:42:47 +08:00
|
|
|
|
2021-04-02 10:01:11 +08:00
|
|
|
package mqclient
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/apache/pulsar-client-go/pulsar"
|
|
|
|
)
|
|
|
|
|
|
|
|
type pulsarID struct {
|
|
|
|
messageID pulsar.MessageID
|
|
|
|
}
|
|
|
|
|
2021-09-15 18:13:49 +08:00
|
|
|
// Check if pulsarID implements pulsar.MessageID and MessageID interface
|
|
|
|
var _ pulsar.MessageID = &pulsarID{}
|
|
|
|
var _ MessageID = &pulsarID{}
|
|
|
|
|
2021-04-02 10:01:11 +08:00
|
|
|
func (pid *pulsarID) Serialize() []byte {
|
|
|
|
return pid.messageID.Serialize()
|
|
|
|
}
|
|
|
|
|
2021-09-15 18:13:49 +08:00
|
|
|
func (pid *pulsarID) LedgerID() int64 {
|
|
|
|
return pid.messageID.LedgerID()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (pid *pulsarID) EntryID() int64 {
|
|
|
|
return pid.messageID.EntryID()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (pid *pulsarID) BatchIdx() int32 {
|
|
|
|
return pid.messageID.BatchIdx()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (pid *pulsarID) PartitionIdx() int32 {
|
|
|
|
return pid.messageID.PartitionIdx()
|
|
|
|
}
|
|
|
|
|
2021-10-04 23:48:10 +08:00
|
|
|
// SerializePulsarMsgID returns the serialized message ID
|
2021-04-02 10:01:11 +08:00
|
|
|
func SerializePulsarMsgID(messageID pulsar.MessageID) []byte {
|
|
|
|
return messageID.Serialize()
|
|
|
|
}
|
|
|
|
|
2021-10-04 23:48:10 +08:00
|
|
|
// DeserializePulsarMsgID returns the deserialized message ID
|
2021-04-02 10:01:11 +08:00
|
|
|
func DeserializePulsarMsgID(messageID []byte) (pulsar.MessageID, error) {
|
|
|
|
return pulsar.DeserializeMessageID(messageID)
|
|
|
|
}
|
|
|
|
|
2021-10-04 23:48:10 +08:00
|
|
|
// PulsarMsgIDToString is used to convert a message ID to string
|
2021-04-02 10:01:11 +08:00
|
|
|
func PulsarMsgIDToString(messageID pulsar.MessageID) string {
|
|
|
|
return strings.ToValidUTF8(string(messageID.Serialize()), "")
|
|
|
|
}
|
|
|
|
|
2021-10-04 23:48:10 +08:00
|
|
|
// StringToPulsarMsgID is used to convert a string to message ID
|
2021-04-02 10:01:11 +08:00
|
|
|
func StringToPulsarMsgID(msgString string) (pulsar.MessageID, error) {
|
|
|
|
return pulsar.DeserializeMessageID([]byte(msgString))
|
|
|
|
}
|