36af614a4fb1c9a8061f7cb0f4069ae78461a1f8
[vxquery.git] / vxquery-core / src / main / java / org / apache / vxquery / datamodel / accessors / atomic / XSBinaryPointable.java
1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package org.apache.vxquery.datamodel.accessors.atomic;
18
19 import org.apache.hyracks.api.dataflow.value.ITypeTraits;
20 import org.apache.hyracks.data.std.api.AbstractPointable;
21 import org.apache.hyracks.data.std.api.IPointable;
22 import org.apache.hyracks.data.std.api.IPointableFactory;
23
24 public class XSBinaryPointable extends AbstractPointable {
25 public static final ITypeTraits TYPE_TRAITS = new ITypeTraits() {
26 private static final long serialVersionUID = 1L;
27
28 @Override
29 public boolean isFixedLength() {
30 return false;
31 }
32
33 @Override
34 public int getFixedLength() {
35 return 0;
36 }
37 };
38
39 public static final IPointableFactory FACTORY = new IPointableFactory() {
40 private static final long serialVersionUID = 1L;
41
42 @Override
43 public IPointable createPointable() {
44 return new XSBinaryPointable();
45 }
46
47 @Override
48 public ITypeTraits getTypeTraits() {
49 return TYPE_TRAITS;
50 }
51 };
52
53 /**
54 * Gets the length of the binary value in bytes.
55 *
56 * @return length of binary value in bytes
57 */
58 public int getBinaryLength() {
59 return getBinaryLength(bytes, start);
60 }
61
62 public static int getBinaryLength(byte[] b, int s) {
63 return ((b[s] & 0xff) << 8) + ((b[s + 1] & 0xff) << 0);
64 }
65
66 public int getBinaryStart() {
67 return getBinaryStart(start);
68 }
69
70 public static int getBinaryStart(int start) {
71 return start + 2;
72 }
73 }

Copyright 2016, The Apache Software Foundation.