]>
git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/thrift/lib/java/src/org/apache/thrift/protocol/TTupleProtocol.java
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
19 package org
.apache
.thrift
.protocol
;
21 import java
.util
.BitSet
;
23 import org
.apache
.thrift
.TException
;
24 import org
.apache
.thrift
.scheme
.IScheme
;
25 import org
.apache
.thrift
.scheme
.TupleScheme
;
26 import org
.apache
.thrift
.transport
.TTransport
;
28 public final class TTupleProtocol
extends TCompactProtocol
{
29 public static class Factory
implements TProtocolFactory
{
32 public TProtocol
getProtocol(TTransport trans
) {
33 return new TTupleProtocol(trans
);
37 public TTupleProtocol(TTransport transport
) {
42 public Class
<?
extends IScheme
> getScheme() {
43 return TupleScheme
.class;
46 public void writeBitSet(BitSet bs
, int vectorWidth
) throws TException
{
47 byte[] bytes
= toByteArray(bs
, vectorWidth
);
48 for (byte b
: bytes
) {
53 public BitSet
readBitSet(int i
) throws TException
{
54 int length
= (int) Math
.ceil(i
/8.0);
55 byte[] bytes
= new byte[length
];
56 for (int j
= 0; j
< length
; j
++) {
57 bytes
[j
] = readByte();
59 BitSet bs
= fromByteArray(bytes
);
64 * Returns a bitset containing the values in bytes. The byte-ordering must be
67 public static BitSet
fromByteArray(byte[] bytes
) {
68 BitSet bits
= new BitSet();
69 for (int i
= 0; i
< bytes
.length
* 8; i
++) {
70 if ((bytes
[bytes
.length
- i
/ 8 - 1] & (1 << (i
% 8))) > 0) {
78 * Returns a byte array of at least length 1. The most significant bit in the
79 * result is guaranteed not to be a 1 (since BitSet does not support sign
80 * extension). The byte-ordering of the result is big-endian which means the
81 * most significant bit is in element 0. The bit at index 0 of the bit set is
82 * assumed to be the least significant bit.
86 * @return a byte array of at least length 1
88 public static byte[] toByteArray(BitSet bits
, int vectorWidth
) {
89 byte[] bytes
= new byte[(int) Math
.ceil(vectorWidth
/8.0)];
90 for (int i
= 0; i
< bits
.length(); i
++) {
92 bytes
[bytes
.length
- i
/ 8 - 1] |= 1 << (i
% 8);