public override UInt32 Serialize(Object instance, Byte[] array, UInt32 offset) { Object valueAsObject = fieldInfo.GetValue(instance); if (valueAsObject == null) { array[offset] = 0; array[offset + 1] = 0; array[offset + 2] = 0; array[offset + 3] = 0; return(offset + 4); } String valueAsString = (String)valueAsObject; array[offset] = (Byte)(valueAsString.Length >> 24); array[offset + 1] = (Byte)(valueAsString.Length >> 16); array[offset + 2] = (Byte)(valueAsString.Length >> 8); array[offset + 3] = (Byte)(valueAsString.Length); offset += 4; for (int i = 0; i < valueAsString.Length; i++) { array[offset++] = (Byte)valueAsString[i]; } UInt32 valueAsArrayMod4Length = Xdr.UpToNearestMod4((UInt32)valueAsString.Length); for (UInt32 i = (UInt32)valueAsString.Length; i < valueAsArrayMod4Length; i++) { array[offset++] = 0; } return(offset); }
public override UInt32 Serialize(Object instance, Byte[] array, UInt32 offset) { Object valueAsObject = fieldInfo.GetValue(instance); if (valueAsObject == null) { array[offset] = 0; array[offset + 1] = 0; array[offset + 2] = 0; array[offset + 3] = 0; return(offset + 4); } Byte[] valueAsArray = (Byte[])valueAsObject; array[offset] = (Byte)(valueAsArray.Length >> 24); array[offset + 1] = (Byte)(valueAsArray.Length >> 16); array[offset + 2] = (Byte)(valueAsArray.Length >> 8); array[offset + 3] = (Byte)(valueAsArray.Length); offset += 4; ArrayCopier.Copy(valueAsArray, 0, array, offset, valueAsArray.Length); UInt32 valueAsArrayMod4Length = Xdr.UpToNearestMod4((UInt32)valueAsArray.Length); for (UInt32 i = (UInt32)valueAsArray.Length; i < valueAsArrayMod4Length; i++) { array[offset + i] = 0; } return(offset + valueAsArrayMod4Length); }
public override UInt32 SerializationLength(Object instance) { Object valueAsObject = fieldInfo.GetValue(instance); if (valueAsObject == null) { return(0); } return(4 + Xdr.UpToNearestMod4((UInt32)((String)valueAsObject).Length)); }
public override UInt32 Deserialize(Object instance, Byte[] array, UInt32 offset, UInt32 maxOffset) { UInt32 length = array.BigEndianReadUInt32(offset); offset += 4; if (length == 0) { fieldInfo.SetValue(instance, new Slice <Byte>(null, 0, 0)); return(offset); } fieldInfo.SetValue(instance, new Slice <Byte>(array, offset, length)); UInt32 lengthMod4 = Xdr.UpToNearestMod4(length); return(offset + lengthMod4); }
public override UInt32 Deserialize(Object instance, Byte[] array, UInt32 offset, UInt32 maxOffset) { UInt32 length = array.BigEndianReadUInt32(offset); offset += 4; if (length == 0) { fieldInfo.SetValue(instance, null); return(offset); } String data = Encoding.UTF8.GetString(array, (Int32)offset, (Int32)length); fieldInfo.SetValue(instance, data); UInt32 lengthMod4 = Xdr.UpToNearestMod4(length); return(offset + lengthMod4); }
public override UInt32 Deserialize(Object instance, Byte[] array, UInt32 offset, UInt32 maxOffset) { UInt32 length = array.BigEndianReadUInt32(offset); offset += 4; if (length == 0) { fieldInfo.SetValue(instance, null); return(offset); } Byte[] data = new Byte[length]; ArrayCopier.Copy(array, offset, data, 0, length); fieldInfo.SetValue(instance, data); UInt32 lengthMod4 = Xdr.UpToNearestMod4(length); return(offset + lengthMod4); }
public override UInt32 Serialize(Object instance, Byte[] array, UInt32 offset) { Slice <Byte> segment = (Slice <Byte>)fieldInfo.GetValue(instance); array[offset] = (Byte)(segment.length >> 24); array[offset + 1] = (Byte)(segment.length >> 16); array[offset + 2] = (Byte)(segment.length >> 8); array[offset + 3] = (Byte)(segment.length); offset += 4; ArrayCopier.Copy(segment.array, segment.offset, array, offset, segment.length); UInt32 valueAsArrayMod4Length = Xdr.UpToNearestMod4(segment.length); for (UInt32 i = segment.length; i < valueAsArrayMod4Length; i++) { array[offset + i] = 0; } return(offset + valueAsArrayMod4Length); }
public override UInt32 SerializationLength(Object instance) { Slice <Byte> segment = (Slice <Byte>)fieldInfo.GetValue(instance); return(4 + Xdr.UpToNearestMod4(segment.length)); }
public XdrOpaqueFixedLengthReflector(Type typeThatContainsThisField, String fieldName, UInt32 dataLength) : base(typeThatContainsThisField, fieldName, typeof(Byte[])) { this.dataLength = dataLength; this.dataLengthNearestContainingMod4 = Xdr.UpToNearestMod4(dataLength); }