@InterfaceAudience.Private public final class ProtobufUtil extends Object
ProtobufUtil
Modifier and Type | Method and Description |
---|---|
static AdminProtos.GetServerInfoRequest |
buildGetServerInfoRequest()
Create a new GetServerInfoRequest
|
static HBaseProtos.RegionSpecifier |
buildRegionSpecifier(HBaseProtos.RegionSpecifier.RegionSpecifierType type,
byte[] value)
Convert a byte array to a protocol buffer RegionSpecifier
|
static HBaseProtos.SnapshotDescription.Type |
createProtosSnapShotDescType(SnapshotType type)
Creates
HBaseProtos.SnapshotDescription.Type
from SnapshotType |
static void |
expectPBMagicPrefix(byte[] bytes) |
static KeyValue.Type |
fromDeleteType(ClientProtos.MutationProto.DeleteType type)
Convert a protocol buffer DeleteType to delete KeyValue type.
|
static IOException |
getRemoteException(com.google.protobuf.ServiceException se)
Return the IOException thrown by the remote server wrapped in
ServiceException as cause.
|
static AdminProtos.ServerInfo |
getServerInfo(com.google.protobuf.RpcController controller,
AdminProtos.AdminService.BlockingInterface admin)
A helper to get the info of a region server using admin protocol.
|
static IOException |
getServiceException(org.apache.hbase.thirdparty.com.google.protobuf.ServiceException e)
Return the Exception thrown by the remote server wrapped in
ServiceException as cause.
|
static IOException |
handleRemoteException(Exception e)
Like
getRemoteException(ServiceException) but more generic, able to handle more than
just ServiceException . |
static boolean |
isPBMagicPrefix(byte[] bytes) |
static boolean |
isPBMagicPrefix(byte[] bytes,
int offset,
int len) |
static int |
lengthOfPBMagic() |
static void |
mergeFrom(com.google.protobuf.Message.Builder builder,
byte[] b)
This version of protobuf's mergeFrom avoids the hard-coded 64MB limit for decoding
buffers when working with byte arrays
|
static void |
mergeFrom(com.google.protobuf.Message.Builder builder,
byte[] b,
int offset,
int length)
This version of protobuf's mergeFrom avoids the hard-coded 64MB limit for decoding
buffers when working with byte arrays
|
static <T extends com.google.protobuf.Service> |
newServiceStub(Class<T> service,
com.google.protobuf.RpcChannel channel) |
static byte[] |
prependPBMagic(byte[] bytes)
Prepend the passed bytes with four bytes of magic,
ProtobufMagic.PB_MAGIC ,
to flag what follows as a protobuf in hbase. |
static Append |
toAppend(ClientProtos.MutationProto proto,
CellScanner cellScanner)
Convert a protocol buffer Mutate to an Append
|
static CellProtos.Cell |
toCell(Cell kv) |
static Cell |
toCell(ExtendedCellBuilder cellBuilder,
CellProtos.Cell cell) |
static ComparatorProtos.Comparator |
toComparator(ByteArrayComparable comparator)
Convert a ByteArrayComparable to a protocol buffer Comparator
|
static ByteArrayComparable |
toComparator(ComparatorProtos.Comparator proto)
Convert a protocol buffer Comparator to a ByteArrayComparable
|
static Consistency |
toConsistency(ClientProtos.Consistency consistency) |
static ClientProtos.Consistency |
toConsistency(Consistency consistency) |
static Delete |
toDelete(ClientProtos.MutationProto proto)
Convert a protocol buffer Mutate to a Delete
|
static Delete |
toDelete(ClientProtos.MutationProto proto,
CellScanner cellScanner)
Convert a protocol buffer Mutate to a Delete
|
static ClientProtos.MutationProto.DeleteType |
toDeleteType(KeyValue.Type type)
Convert a delete KeyValue type to protocol buffer DeleteType.
|
static Durability |
toDurability(ClientProtos.MutationProto.Durability proto)
Convert a protobuf Durability into a client Durability
|
static ClientProtos.MutationProto.Durability |
toDurability(Durability d)
Convert a client Durability into a protbuf Durability
|
static Throwable |
toException(HBaseProtos.NameBytesPair parameter)
Convert a stringified protocol buffer exception Parameter to a Java Exception
|
static FilterProtos.Filter |
toFilter(Filter filter)
Convert a client Filter to a protocol buffer Filter
|
static Filter |
toFilter(FilterProtos.Filter proto)
Convert a protocol buffer Filter to a client Filter
|
static Get |
toGet(ClientProtos.Get proto)
Convert a protocol buffer Get to a client Get
|
static Get |
toGet(ClientProtos.MutationProto proto,
CellScanner cellScanner)
Convert a protocol buffer Mutate to a Get.
|
static ClientProtos.Get |
toGet(Get get)
Create a protocol buffer Get based on a client Get.
|
static RSGroupInfo |
toGroupInfo(RSGroupProtos.RSGroupInfo proto) |
static Increment |
toIncrement(ClientProtos.MutationProto proto,
CellScanner cellScanner)
Convert a protocol buffer Mutate to an Increment
|
static void |
toIOException(com.google.protobuf.ServiceException se)
Unwraps an exception from a protobuf service into the underlying (expected) IOException.
|
static ClientProtos.MutationProto |
toMutation(ClientProtos.MutationProto.MutationType type,
Mutation mutation) |
static ClientProtos.MutationProto |
toMutation(ClientProtos.MutationProto.MutationType type,
Mutation mutation,
ClientProtos.MutationProto.Builder builder) |
static ClientProtos.MutationProto |
toMutation(ClientProtos.MutationProto.MutationType type,
Mutation mutation,
ClientProtos.MutationProto.Builder builder,
long nonce) |
static ClientProtos.MutationProto |
toMutation(ClientProtos.MutationProto.MutationType type,
Mutation mutation,
long nonce)
Create a protocol buffer Mutate based on a client Mutation
|
static Mutation |
toMutation(ClientProtos.MutationProto proto)
Convert a MutateRequest to Mutation
|
static ClientProtos.MutationProto |
toMutationNoData(ClientProtos.MutationProto.MutationType type,
Mutation mutation)
Create a protocol buffer MutationProto based on a client Mutation.
|
static ClientProtos.MutationProto |
toMutationNoData(ClientProtos.MutationProto.MutationType type,
Mutation mutation,
ClientProtos.MutationProto.Builder builder)
Create a protocol buffer MutationProto based on a client Mutation.
|
static ClientProtos.MutationProto |
toMutationNoData(ClientProtos.MutationProto.MutationType type,
Mutation mutation,
ClientProtos.MutationProto.Builder builder,
long nonce) |
static TableProtos.TableName |
toProtoTableName(TableName tableName) |
static Put |
toPut(ClientProtos.MutationProto proto)
Convert a protocol buffer Mutate to a Put.
|
static Put |
toPut(ClientProtos.MutationProto proto,
CellScanner cellScanner)
Convert a protocol buffer Mutate to a Put.
|
static Scan.ReadType |
toReadType(ClientProtos.Scan.ReadType readType) |
static ClientProtos.Scan.ReadType |
toReadType(Scan.ReadType readType) |
static ClientProtos.Result |
toResult(boolean existence,
boolean stale)
Convert a client Result to a protocol buffer Result
|
static Result |
toResult(ClientProtos.Result proto)
Convert a protocol buffer Result to a client Result
|
static Result |
toResult(ClientProtos.Result proto,
CellScanner scanner)
Convert a protocol buffer Result to a client Result
|
static ClientProtos.Result |
toResult(Result result)
Convert a client Result to a protocol buffer Result
|
static ClientProtos.Result |
toResultNoData(Result result)
Convert a client Result to a protocol buffer Result.
|
static Scan |
toScan(ClientProtos.Scan proto)
Convert a protocol buffer Scan to a client Scan
|
static ClientProtos.Scan |
toScan(Scan scan)
Convert a client Scan to a protocol buffer Scan
|
static ScanMetrics |
toScanMetrics(byte[] bytes) |
static ServerName |
toServerName(byte[] data)
Get a ServerName from the passed in data bytes.
|
static ServerName |
toServerName(HBaseProtos.ServerName proto)
Convert a protocol buffer ServerName to a ServerName
|
static HBaseProtos.ServerName |
toServerName(ServerName serverName)
Convert a ServerName to a protocol buffer ServerName
|
static TableName |
toTableName(TableProtos.TableName tableNamePB) |
static HBaseProtos.TimeRange |
toTimeRange(TimeRange timeRange) |
public static byte[] prependPBMagic(byte[] bytes)
ProtobufMagic.PB_MAGIC
,
to flag what follows as a protobuf in hbase. Prepend these bytes to all content written to
znodes, etc.bytes
- Bytes to decoratebytes
with magic prepended (Creates a new
byte array that is bytes.length
plus ProtobufMagic.PB_MAGIC
.length.public static boolean isPBMagicPrefix(byte[] bytes)
bytes
- Bytes to check.bytes
has ProtobufMagic.PB_MAGIC
for a prefix.public static boolean isPBMagicPrefix(byte[] bytes, int offset, int len)
bytes
- Bytes to check.offset
- offset to start atlen
- length to usebytes
has ProtobufMagic.PB_MAGIC
for a prefix.public static void expectPBMagicPrefix(byte[] bytes) throws DeserializationException
bytes
- bytes to checkDeserializationException
- if we are missing the pb magic prefixpublic static int lengthOfPBMagic()
ProtobufMagic.lengthOfPBMagic()
public static IOException getRemoteException(com.google.protobuf.ServiceException se)
se
- ServiceException that wraps IO exception thrown by the serverpublic static IOException getServiceException(org.apache.hbase.thirdparty.com.google.protobuf.ServiceException e)
e
- ServiceException that wraps IO exception thrown by the serverpublic static IOException handleRemoteException(Exception e)
getRemoteException(ServiceException)
but more generic, able to handle more than
just ServiceException
. Prefer this method to
getRemoteException(ServiceException)
because trying to
contain direct protobuf references.e
- public static HBaseProtos.ServerName toServerName(ServerName serverName)
serverName
- the ServerName to converttoServerName(org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.ServerName)
public static ServerName toServerName(HBaseProtos.ServerName proto)
proto
- the protocol buffer ServerName to convertpublic static Durability toDurability(ClientProtos.MutationProto.Durability proto)
public static ClientProtos.MutationProto.Durability toDurability(Durability d)
public static Get toGet(ClientProtos.Get proto) throws IOException
proto
- the protocol buffer Get to convertIOException
public static Consistency toConsistency(ClientProtos.Consistency consistency)
public static ClientProtos.Consistency toConsistency(Consistency consistency)
public static Put toPut(ClientProtos.MutationProto proto) throws IOException
proto
- The protocol buffer MutationProto to convertIOException
public static Put toPut(ClientProtos.MutationProto proto, CellScanner cellScanner) throws IOException
proto
- The protocol buffer MutationProto to convertcellScanner
- If non-null, the Cell data that goes with this proto.IOException
public static Delete toDelete(ClientProtos.MutationProto proto) throws IOException
proto
- the protocol buffer Mutate to convertIOException
public static Delete toDelete(ClientProtos.MutationProto proto, CellScanner cellScanner) throws IOException
proto
- the protocol buffer Mutate to convertcellScanner
- if non-null, the data that goes with this delete.IOException
public static Append toAppend(ClientProtos.MutationProto proto, CellScanner cellScanner) throws IOException
cellScanner
- proto
- the protocol buffer Mutate to convertIOException
public static Increment toIncrement(ClientProtos.MutationProto proto, CellScanner cellScanner) throws IOException
proto
- the protocol buffer Mutate to convertIOException
public static Mutation toMutation(ClientProtos.MutationProto proto) throws IOException
proto
- the protocol buffer Mutate to convertIOException
public static Get toGet(ClientProtos.MutationProto proto, CellScanner cellScanner) throws IOException
proto
- the protocol buffer Mutate to convert.cellScanner
- IOException
public static ClientProtos.Scan.ReadType toReadType(Scan.ReadType readType)
public static Scan.ReadType toReadType(ClientProtos.Scan.ReadType readType)
public static ClientProtos.Scan toScan(Scan scan) throws IOException
scan
- the client Scan to convertIOException
public static Scan toScan(ClientProtos.Scan proto) throws IOException
proto
- the protocol buffer Scan to convertIOException
public static ClientProtos.Get toGet(Get get) throws IOException
get
- the client GetIOException
public static ClientProtos.MutationProto toMutation(ClientProtos.MutationProto.MutationType type, Mutation mutation) throws IOException
IOException
public static ClientProtos.MutationProto toMutation(ClientProtos.MutationProto.MutationType type, Mutation mutation, long nonce) throws IOException
type
- mutation
- IOException
public static ClientProtos.MutationProto toMutation(ClientProtos.MutationProto.MutationType type, Mutation mutation, ClientProtos.MutationProto.Builder builder) throws IOException
IOException
public static ClientProtos.MutationProto toMutation(ClientProtos.MutationProto.MutationType type, Mutation mutation, ClientProtos.MutationProto.Builder builder, long nonce) throws IOException
IOException
public static ClientProtos.MutationProto toMutationNoData(ClientProtos.MutationProto.MutationType type, Mutation mutation, ClientProtos.MutationProto.Builder builder) throws IOException
type
- mutation
- builder
- IOException
public static ClientProtos.MutationProto toMutationNoData(ClientProtos.MutationProto.MutationType type, Mutation mutation) throws IOException
type
- mutation
- IOException
public static ClientProtos.MutationProto toMutationNoData(ClientProtos.MutationProto.MutationType type, Mutation mutation, ClientProtos.MutationProto.Builder builder, long nonce) throws IOException
IOException
public static ClientProtos.Result toResult(Result result)
result
- the client Result to convertpublic static ClientProtos.Result toResult(boolean existence, boolean stale)
existence
- the client existence to sendpublic static ClientProtos.Result toResultNoData(Result result)
result
- the client Result to convertpublic static Result toResult(ClientProtos.Result proto)
proto
- the protocol buffer Result to convertpublic static Result toResult(ClientProtos.Result proto, CellScanner scanner) throws IOException
proto
- the protocol buffer Result to convertscanner
- Optional cell scanner.IOException
public static ComparatorProtos.Comparator toComparator(ByteArrayComparable comparator)
comparator
- the ByteArrayComparable to convertpublic static ByteArrayComparable toComparator(ComparatorProtos.Comparator proto) throws IOException
proto
- the protocol buffer Comparator to convertIOException
public static Filter toFilter(FilterProtos.Filter proto) throws IOException
proto
- the protocol buffer Filter to convertIOException
public static FilterProtos.Filter toFilter(Filter filter) throws IOException
filter
- the Filter to convertIOException
public static ClientProtos.MutationProto.DeleteType toDeleteType(KeyValue.Type type) throws IOException
type
- IOException
public static KeyValue.Type fromDeleteType(ClientProtos.MutationProto.DeleteType type) throws IOException
type
- The DeleteTypeIOException
public static Throwable toException(HBaseProtos.NameBytesPair parameter) throws IOException
parameter
- the protocol buffer Parameter to convertIOException
- if failed to deserialize the parameterpublic static <T extends com.google.protobuf.Service> T newServiceStub(Class<T> service, com.google.protobuf.RpcChannel channel) throws Exception
Exception
public static AdminProtos.ServerInfo getServerInfo(com.google.protobuf.RpcController controller, AdminProtos.AdminService.BlockingInterface admin) throws IOException
IOException
public static AdminProtos.GetServerInfoRequest buildGetServerInfoRequest()
public static ScanMetrics toScanMetrics(byte[] bytes)
public static void toIOException(com.google.protobuf.ServiceException se) throws IOException
se
- the ServiceException
instance to convert into an IOException
IOException
public static CellProtos.Cell toCell(Cell kv)
public static Cell toCell(ExtendedCellBuilder cellBuilder, CellProtos.Cell cell)
public static TableName toTableName(TableProtos.TableName tableNamePB)
public static TableProtos.TableName toProtoTableName(TableName tableName)
public static void mergeFrom(com.google.protobuf.Message.Builder builder, byte[] b) throws IOException
builder
- current message builderb
- byte arrayIOException
public static void mergeFrom(com.google.protobuf.Message.Builder builder, byte[] b, int offset, int length) throws IOException
builder
- current message builderb
- byte arrayoffset
- length
- IOException
public static HBaseProtos.SnapshotDescription.Type createProtosSnapShotDescType(SnapshotType type)
HBaseProtos.SnapshotDescription.Type
from SnapshotType
type
- the SnapshotDescription typepublic static HBaseProtos.RegionSpecifier buildRegionSpecifier(HBaseProtos.RegionSpecifier.RegionSpecifierType type, byte[] value)
type
- the region specifier typevalue
- the region specifier byte array valuepublic static ServerName toServerName(byte[] data) throws DeserializationException
data
- Data with a serialize server name in it; can handle the old style
servername where servername was host and port. Works too with data that
begins w/ the pb 'PBUF' magic and that is then followed by a protobuf that
has a serialized ServerName
in it.data
is null else converts passed data
to a ServerName instance.DeserializationException
public static RSGroupInfo toGroupInfo(RSGroupProtos.RSGroupInfo proto)
public static HBaseProtos.TimeRange toTimeRange(TimeRange timeRange)
Copyright © 2007–2019 Cloudera. All rights reserved.