本文整理汇总了C#中OSD.AsBinary方法的典型用法代码示例。如果您正苦于以下问题:C# OSD.AsBinary方法的具体用法?C# OSD.AsBinary怎么用?C# OSD.AsBinary使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OSD
的用法示例。
在下文中一共展示了OSD.AsBinary方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ToIP
public static IPAddress ToIP(OSD osd)
{
byte[] binary = osd.AsBinary();
if (binary != null && binary.Length == 4)
return new IPAddress(binary);
else
return IPAddress.Any;
}
示例2: SerializeJson
public static JsonData SerializeJson(OSD osd)
{
switch (osd.Type)
{
case OSDType.Boolean:
return new JsonData(osd.AsBoolean());
case OSDType.Integer:
return new JsonData(osd.AsInteger());
case OSDType.Real:
return new JsonData(osd.AsReal());
case OSDType.String:
case OSDType.Date:
case OSDType.URI:
case OSDType.UUID:
return new JsonData(osd.AsString());
case OSDType.Binary:
byte[] binary = osd.AsBinary();
JsonData jsonbinarray = new JsonData();
jsonbinarray.SetJsonType(JsonType.Array);
for (int i = 0; i < binary.Length; i++)
jsonbinarray.Add(new JsonData(binary[i]));
return jsonbinarray;
case OSDType.Array:
JsonData jsonarray = new JsonData();
jsonarray.SetJsonType(JsonType.Array);
OSDArray array = (OSDArray)osd;
for (int i = 0; i < array.Count; i++)
jsonarray.Add(SerializeJson(array[i]));
return jsonarray;
case OSDType.Map:
JsonData jsonmap = new JsonData();
jsonmap.SetJsonType(JsonType.Object);
OSDMap map = (OSDMap)osd;
foreach (KeyValuePair<string, OSD> kvp in map)
jsonmap[kvp.Key] = SerializeJson(kvp.Value);
return jsonmap;
case OSDType.Unknown:
default:
return new JsonData();
}
}
示例3: SerializeLisp
public static object SerializeLisp(OSD osd)
{
switch (osd.Type)
{
case OSDType.Unknown:
throw new InvalidCastException();
case OSDType.Boolean:
return osd.AsBoolean();
case OSDType.Integer:
return osd.AsInteger();
case OSDType.Real:
return osd.AsReal();
case OSDType.String:
return osd.AsString();
case OSDType.Date:
return osd.AsDate();
case OSDType.URI:
return osd.AsUri();
case OSDType.UUID:
return osd.AsUUID();
case OSDType.Binary:
return osd.AsBinary();
case OSDType.Array:
OSDArray args = (OSDArray) osd;
Cons ret = null;
for (int i = args.Count - 1; i >= 0; --i)
{
ret = new Cons(args[i], ret);
}
return ret;
case OSDType.Map:
Cons list = null;
OSDMap map = (OSDMap) osd;
foreach (KeyValuePair<string, OSD> kvp in map)
{
Cons kv = new Cons(kvp.Key, new Cons(SerializeLisp(kvp.Value)));
list = new Cons(kv,list);
}
return Cons.Reverse(list);
default:
return osd;
}
}
示例4: SerializeLLSDBinaryElement
private static void SerializeLLSDBinaryElement(MemoryStream stream, OSD osd)
{
switch (osd.Type)
{
case OSDType.Unknown:
stream.WriteByte(undefBinaryValue);
break;
case OSDType.Boolean:
stream.Write(osd.AsBinary(), 0, 1);
break;
case OSDType.Integer:
stream.WriteByte(integerBinaryMarker);
stream.Write(osd.AsBinary(), 0, int32Length);
break;
case OSDType.Real:
stream.WriteByte(realBinaryMarker);
stream.Write(osd.AsBinary(), 0, doubleLength);
break;
case OSDType.UUID:
stream.WriteByte(uuidBinaryMarker);
stream.Write(osd.AsBinary(), 0, 16);
break;
case OSDType.String:
stream.WriteByte(stringBinaryMarker);
byte[] rawString = osd.AsBinary();
byte[] stringLengthNetEnd = HostToNetworkIntBytes(rawString.Length);
stream.Write(stringLengthNetEnd, 0, int32Length);
stream.Write(rawString, 0, rawString.Length);
break;
case OSDType.Binary:
stream.WriteByte(binaryBinaryMarker);
byte[] rawBinary = osd.AsBinary();
byte[] binaryLengthNetEnd = HostToNetworkIntBytes(rawBinary.Length);
stream.Write(binaryLengthNetEnd, 0, int32Length);
stream.Write(rawBinary, 0, rawBinary.Length);
break;
case OSDType.Date:
stream.WriteByte(dateBinaryMarker);
stream.Write(osd.AsBinary(), 0, doubleLength);
break;
case OSDType.URI:
stream.WriteByte(uriBinaryMarker);
byte[] rawURI = osd.AsBinary();
byte[] uriLengthNetEnd = HostToNetworkIntBytes(rawURI.Length);
stream.Write(uriLengthNetEnd, 0, int32Length);
stream.Write(rawURI, 0, rawURI.Length);
break;
case OSDType.Array:
SerializeLLSDBinaryArray(stream, (OSDArray)osd);
break;
case OSDType.Map:
SerializeLLSDBinaryMap(stream, (OSDMap)osd);
break;
default:
throw new OSDException("Binary serialization: Not existing element discovered.");
}
}
示例5: readuintval
private uint readuintval(OSD obj)
{
byte[] tmp = obj.AsBinary();
if (BitConverter.IsLittleEndian)
Array.Reverse(tmp);
return OpenMetaverse.Utils.BytesToUInt(tmp);
}
示例6: SerializeJsonNoDefaults
private static JsonData SerializeJsonNoDefaults(OSD osd)
{
switch (osd.Type)
{
case OSDType.Boolean:
bool b = osd.AsBoolean();
if (!b)
return null;
return new JsonData(b);
case OSDType.Integer:
int v = osd.AsInteger();
if (v == 0)
return null;
return new JsonData(v);
case OSDType.Real:
double d = osd.AsReal();
if (d == 0.0d)
return null;
return new JsonData(d);
case OSDType.String:
case OSDType.Date:
case OSDType.URI:
string str = osd.AsString();
if (String.IsNullOrEmpty(str))
return null;
return new JsonData(str);
case OSDType.UUID:
UUID uuid = osd.AsUUID();
if (uuid == UUID.Zero)
return null;
return new JsonData(uuid.ToString());
case OSDType.Binary:
byte[] binary = osd.AsBinary();
if (binary == Utils.EmptyBytes)
return null;
JsonData jsonbinarray = new JsonData();
jsonbinarray.SetJsonType(JsonType.Array);
for (int i = 0; i < binary.Length; i++)
jsonbinarray.Add(new JsonData(binary[i]));
return jsonbinarray;
case OSDType.Array:
JsonData jsonarray = new JsonData();
jsonarray.SetJsonType(JsonType.Array);
OSDArray array = (OSDArray)osd;
for (int i = 0; i < array.Count; i++)
jsonarray.Add(SerializeJson(array[i]));
return jsonarray;
case OSDType.Map:
JsonData jsonmap = new JsonData();
jsonmap.SetJsonType(JsonType.Object);
OSDMap map = (OSDMap)osd;
foreach (KeyValuePair<string, OSD> kvp in map)
{
JsonData data = SerializeJsonNoDefaults(kvp.Value);
if (data != null)
jsonmap[kvp.Key] = data;
}
return jsonmap;
case OSDType.Unknown:
default:
return null;
}
}
示例7: SerializeJson
public static JsonData SerializeJson(OSD osd)
{
switch (osd.Type)
{
case OSDType.Boolean:
return new JsonData(osd.AsBoolean());
case OSDType.Integer:
return new JsonData(osd.AsInteger());
case OSDType.Real:
return new JsonData(osd.AsReal());
case OSDType.String:
return new JsonData(osd.AsString());
case OSDType.Date:
return new JsonData("date::" + osd.AsString());
case OSDType.URI:
return new JsonData("uri::" + osd.AsString());
case OSDType.UUID:
return new JsonData("uuid::" + osd.AsString());
case OSDType.Binary:
return new JsonData("b64::" + Convert.ToBase64String(osd.AsBinary()));
case OSDType.Array:
JsonData jsonarray = new JsonData();
jsonarray.SetJsonType(JsonType.Array);
OSDArray array = (OSDArray)osd;
for (int i = 0; i < array.Count; i++)
jsonarray.Add(SerializeJson(array[i]));
return jsonarray;
case OSDType.Map:
JsonData jsonmap = new JsonData();
jsonmap.SetJsonType(JsonType.Object);
OSDMap map = (OSDMap)osd;
foreach (KeyValuePair<string, OSD> kvp in map)
jsonmap[kvp.Key] = SerializeJson(kvp.Value);
return jsonmap;
case OSDType.Unknown:
default:
return new JsonData();
}
}