/*
(non-Javadoc)

@see
com.impetus.kundera.property.PropertyAccessor#toBytes(java.lang.Object)
16447
@Override
    public byte[] toBytes(Object object)
    {
        if (object != null)
        {
            Boolean b = (Boolean) object;

            return new byte[] { (byte) (b ? 0x01 : 0x00) }; // bool -> {1 byte}
        }
        return null;
    }
1193094
public static byte[] toBytes(byte[] s) throws SQLException {
    if (s == null) {
      return null;
    }

    // Starting with PG 9.0, a new hex format is supported
    // that starts with "\x". Figure out which format we're
    // dealing with here.
    //
    if (s.length < 2 || s[0] != '\\' || s[1] != 'x') {
      return toBytesOctalEscaped(s);
    }
    return toBytesHexEscaped(s);
  }
649022
@Override
    public byte[] toBytes(Object object)
    {
        if (object == null)
        {
            return null;
        }
        BigInteger b = (BigInteger) object;
        return b.toByteArray();
    }
678900
public static byte[] toBytes(BigDecimal val) {
    byte[] valueBytes = val.unscaledValue().toByteArray();
    byte[] result = new byte[valueBytes.length + SIZEOF_INT];
    int offset = putInt(result, 0, val.scale());
    putBytes(result, offset, valueBytes, 0, valueBytes.length);
    return result;
  }
742935
@Override
    public byte[] toBytes(Object object)
    {
        if (object == null)
        {
            return null;
        }
        Calendar cal = (Calendar) object;
        // return
        // DateAccessor.getFormattedObect(cal.getTime().toString()).getBytes();
        LongAccessor longAccessor = new LongAccessor();
        return longAccessor.toBytes(cal.getTime().getTime());
    }
665116
public static byte[] toBytes(ServerStats stats) {
    // Should this be optimized to not include invalid values?

    ByteBuffer bb = ByteBuffer.allocate(ServerStatsFieldEnums.getTotalSize() + 1);
    bb.order(ByteOrder.LITTLE_ENDIAN);

    // put version
    bb.put(CURRENT_VERSION);

    bb.put((byte) ServerStatsFieldEnums.Id.SERVER_STATS_LB_LATENCY_ID.value());
    bb.putLong(stats.getLbLatencyNs());

    bb.put((byte) ServerStatsFieldEnums.Id.SERVER_STATS_SERVICE_LATENCY_ID.value());
    bb.putLong(stats.getServiceLatencyNs());

    bb.put((byte) ServerStatsFieldEnums.Id.SERVER_STATS_TRACE_OPTION_ID.value());
    bb.put(stats.getTraceOption());
    return bb.array();
  }
53553
public void toBytesDense(ByteBuffer buf)
  {
    buf.putInt(size);
    buf.putInt(binCount);

    buf.asFloatBuffer().put(positions);
    buf.position(buf.position() + Float.BYTES * positions.length);
    buf.asLongBuffer().put(bins);
    buf.position(buf.position() + Long.BYTES * bins.length);

    buf.putFloat(min);
    buf.putFloat(max);
  }
42691
private void marshalFields() {
    Collection<PropertyMetadata> propertyMetadataCollection = entityMetadata
        .getPropertyMetadataCollection();
    for (PropertyMetadata propertyMetadata : propertyMetadataCollection) {
      marshalField(propertyMetadata, entity);
    }
  }
412072
public byte[] toBytes() throws IOException {
    final ByteArrayOutputStream outBuffer = new ByteArrayOutputStream();
    final BitOutputStream out = new BitOutputStream(outBuffer);
    this.write(out);
    out.flush();
    return outBuffer.toByteArray();
  }
948573
public static byte[] toByte(Object object, Charset charset) {
        ObjectMetaData objectMap = getObjectMap(object.getClass());
        try {
            return convertFieldToByte(objectMap, object, charset);
        } catch (NoSuchMethodException ie) {
            LOGGER.debug("Cannot invoke get methed: ", ie);
            throw new FdfsColumnMapException(ie);
        } catch (IllegalAccessException iae) {
            LOGGER.debug("Illegal access: ", iae);
            throw new FdfsColumnMapException(iae);
        } catch (InvocationTargetException ite) {
            LOGGER.debug("Cannot invoke method: ", ite);
            throw new FdfsColumnMapException(ite);
        }

    }
370112
@Override
  public Set<ByteBuffer> toBytesSet(List<T> list) {
    Set<ByteBuffer> bytesList = new HashSet<ByteBuffer>(
        computeInitialHashSize(list.size()));
    for (T s : list) {
      bytesList.add(toByteBuffer(s));
    }
    return bytesList;
  }
1340396
private byte[] toByteArray(char[] chars, Charset charset) {
        assert chars != null;

        CharBuffer charBuffer = CharBuffer.wrap(chars);
        ByteBuffer byteBuffer = charset.encode(charBuffer);
        byte[] bytes = Arrays.copyOfRange(byteBuffer.array(),
                byteBuffer.position(), byteBuffer.limit());
        Arrays.fill(byteBuffer.array(), (byte) 0); // clear sensitive data
        return bytes;
    }
797172
@Override
    public final byte[] toBytes(Object val)
    {
        if (val != null)
        {
            Integer value = (Integer) (val);
            return new byte[] { (byte) (value >>> 24), (byte) (value >>> 16), (byte) (value >>> 8),
                    (byte) value.intValue() };
        }
        return null;
    }
1041668
public byte[] toByteArray(final ArrayOfItemsSerDe<? super T> serDe) {
    if (itemsSeen_ == 0) {
      // null class is ok since empty -- no need to call serDe
      return toByteArray(serDe, null);
    } else {
      return toByteArray(serDe, data_.get(0).getClass());
    }
  }
475895
public byte[] toByteArray() throws IOException {
    // TODO: in the future actual serialization here should be done using protobufs
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    write(new DataOutputStream(bos));
    return bos.toByteArray();
  }
567791
public static byte[] toBytes(ByteBuffer bb) {
    int length = bb.limit();
    byte [] result = new byte[length];
    System.arraycopy(bb.array(), bb.arrayOffset(), result, 0, length);
    return result;
  }
202439
@Override
	byte[] toByteArray(final ByteArrayOutputStream os)
	{
		os.write(4);
		os.write(state);
		os.write(lost >> 8);
		os.write(lost);
		return os.toByteArray();
	}