Converts intermediate representation of aggregate to byte[].

@param val intermediate representation of aggregate

@return serialized intermediate representation of aggregate in byte[]
325977
public byte[] toBytes(@Nullable Object val)
  {
    if (val != null) {
      byte[] bytes = getObjectStrategy().toBytes(val);
      return bytes != null ? bytes : ByteArrays.EMPTY_ARRAY;
    } else {
      return ByteArrays.EMPTY_ARRAY;
    }
  }
1364537
public Collection<?> toCollection(Object val) {

    if (val == null) {
      return Collections.emptyList();
    }
    else if (val instanceof Collection<?>) {
      return (Collection<?>) val;
    }
    else if (val.getClass().isArray()) {
      return newArrayList((Object[]) val);
    }
    else if (val instanceof Map<?,?>) {
      return ((Map<?,?>)val).entrySet();
    }
    else {
      return newArrayList(val);
    }
  }
254313
@Override
    public final byte[] toBytes(Object o)
    {

        try
        {
            if (o != null)
            {
                if (o instanceof byte[])
                {
                    return (byte[]) o;
                }

                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                ObjectOutputStream oos = new ObjectOutputStream(baos);
                oos.writeObject(o);
                oos.close();
                return baos.toByteArray();
            }
        }
        catch (IOException e)
        {
            log.error("IO exception, Caused by {}.", e);
            throw new PropertyAccessException(e);
        }
        return null;
    }
625210
public static String encodeArray(final String[] val){
    if (val == null) {
      return null;
    }

    int len = val.length;

    if (len == 0) {
      return "";
    }

    StringBuffer sb = new StringBuffer();

    for (int i = 0; i < len; i++) {
      if (i > 0) {
        sb.append(" ");
      }

      String s = val[i];

      try {
        if (s == null) {
          sb.append("\t");
        } else {
          sb.append(URLEncoder.encode(s, "UTF-8"));
        }
      } catch (Throwable t) {
        throw new RuntimeException(t);
      }
    }

    return sb.toString();
  }
1246784
public void getBytes(byte[] val) throws IOException {
        if ((val.length != 0) && (buffer.read(val) != val.length)) {
            throw new IOException("short read of DER octet string");
        }
    }
248621
public static byte[] getBytes(long val, long size) {
        byte[] res = new byte[(int) size];
        long bv = val;
        for (int i = (int) size - 1; i >= 0; --i) {
            res[i] = (byte) (bv & 0xFF);
            bv >>= BIT_IN_BYTE;
        }
        return res;
    }
1023232
public static byte[] toBytes(short val) {
    byte[] b = new byte[SIZEOF_SHORT];
    b[1] = (byte) val;
    val >>= 8;
    b[0] = (byte) val;
    return b;
  }
1359665
public static final int[] getBitsSet(final long val) {
    long tmp = val;
    int[] retVal = new int[Long.bitCount(val)];
    for (int i = 0; i < retVal.length; i++) {
      retVal[i] = Long.numberOfTrailingZeros(tmp);
      tmp = tmp ^ Long.lowestOneBit(tmp);
    }
    return retVal;
  }
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;
  }
1017996
public static byte[] toByteArray(double d, ByteOrder bo) {
    return ByteBuffer.allocate(8).order(bo).putDouble(d).array();
  }
601543
private int getByteLength(final Object val) {
		if (val == null) {
			return 4;
		}
		String str = val.toString();
		try {
			int len = str.getBytes(ENCODING_SHIFT_JIS).length;
			return len <= 200 ? len : 200;
		} catch (UnsupportedEncodingException ex) {
			return 1;
		}
	}
1373093
public byte[] serializeToBytes(final Serializable o) {
        byte[] bytes = null;
        try (final ByteArrayOutputStream baos = new ByteArrayOutputStream();
             final ObjectOutputStream oos = new ObjectOutputStream(baos)) {
            oos.writeObject(o);
            oos.flush();
            bytes = baos.toByteArray();
        } catch (final IOException e) {
            logger.warn("cannot Java serialize object", e);
        }
        return bytes;
    }
413129
def _serialize_value(val, raw: false)
      if !raw && @desc.write_processors?
        val= @desc.pre_process(val)
      end
      val.unpack('C*')
    end
855473
public void cdataValue(final String val) throws IOException {
    if (val == null) {
      return;
    }

    int start = 0;

    while (start < val.length()) {
      int end = val.indexOf("]]", start);
      boolean lastSeg = end < 0;
      String seg;

      if (lastSeg) {
        seg = val.substring(start);
      } else {
        seg = val.substring(start, end);
      }

      out("<![CDATA[");
      out(seg);
      out("]]>");

      if (lastSeg) {
        break;
      }

      out("]]");
      start = end + 2;
    }
  }
691727
public BigDecimal toBigDecimal(Object val) {
    if (val instanceof BigDecimal) {
      return roundBigDecimal((BigDecimal) val);
    }
    else if (val == null) {
      return BigDecimal.ZERO;
    }
    else if (val instanceof String) {
      String string = ((String) val).trim();
      if ("".equals(string)) {
        return BigDecimal.ZERO;
      }
      return roundBigDecimal(new BigDecimal(string, getMathContext()));
    }
    else if (val instanceof Double) {
      if (!Double.isNaN(((Double) val).doubleValue())) {
        return roundBigDecimal(new BigDecimal(val.toString(), getMathContext()));
      }
      else {
        return BigDecimal.ZERO;
      }
    }
    else if (val instanceof Number) {
      return roundBigDecimal(new BigDecimal(val.toString(), getMathContext()));
    }
    else if (val instanceof Character) {
      int i = ((Character) val).charValue();
      return new BigDecimal(i);
    }

    throw new ArithmeticException("BigDecimal coercion: " + val.getClass().getName() + ":(" + val + ")");
  }
1089720
@GwtIncompatible("java.io.ByteArrayOutputStream")
  public byte[] toBytes() {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    Writer writer = new OutputStreamWriter(baos, UTF_8);
    try {
      // The output order should be stable.
      for (Map.Entry<String, String> entry :
          ImmutableSortedSet.copyOf(comparingByKey(), map.entrySet())) {
        writer.write(escape(entry.getKey()));
        writer.write(SEPARATOR);
        writer.write(escape(entry.getValue()));
        writer.write('\n');
      }
      writer.close();
    } catch (IOException e) {
      // Note: A ByteArrayOutputStream never throws IOException. This try/catch
      // is just here to appease the Java compiler.
      throw new RuntimeException(e);
    }
    return baos.toByteArray();
  }
173077
def from_val(val_schema):
    """"""
    definition = getattr(val_schema, "definition", val_schema) if isinstance(
        val_schema, BaseSchema) else val_schema
    if isinstance(definition, dict):
        return _dict_to_teleport(definition)

    if isinstance(definition, list):
        # teleport only supports a single type by default
        if len(definition) == 1:
            return {"Array": from_val(definition[0])}

    if definition in VAL_PRIMITIVES:
        return VAL_PRIMITIVES[definition]

    raise SerializationError(
        "Serializing %r not (yet) supported." % definition)