3 <title>Binary Serialization Format
</title>
4 <style> body { FONT-SIZE: x-small; FONT-FAMILY: arial }
5 table { FONT-SIZE: x-small; FONT-FAMILY: arial }
9 <H1>Binary Serialization Format
</H1>
10 <P>by Lluis Sanchez Gual
(
<A href=
"mailto:lluis@ideary.com">lluis@ideary.com
</A>)
</P>
13 <A href=
"#intro">Introduction
</A>
15 <A href=
"#format">Format description
</A>
18 <A href=
"#example">An example
</A></LI></UL>
20 <A href=
"#elements">Binary elements
</A>
23 <A href=
"#elem1">1 - RefTypeObject
</A>
25 <A href=
"#elem4">4 - RuntimeObject
</A>
27 <A href=
"#elem5">5 - ExternalObject
</A>
29 <A href=
"#elem6">6 - String
</A>
31 <A href=
"#elem7">7 - GenericArray
</A>
33 <A href=
"#elem8">8 - BoxedPrimitiveTypeValue
</A>
35 <A href=
"#elem9">9 - ObjectReference
</A>
37 <A href=
"#elem10">10 - NullValue
</A>
39 <A href=
"#elem11">11 - End
</A>
41 <A href=
"#elem12">12 - Assembly
</A>
43 <A href=
"#elem13">13 - ArrayFiller8b
</A>
45 <A href=
"#elem14">14 - ArrayFiller32b
</A>
47 <A href=
"#elem15">15 - ArrayOfPrimitiveType
</A>
49 <A href=
"#elem16">16 - ArrayOfObject
</A>
51 <A href=
"#elem17">17 - ArrayOfString
</A>
53 <A href=
"#elem21">21 - MethodCall
</A>
55 <A href=
"#elem22">22 - MethodResponse
</A></LI></UL>
57 <A href=
"#other">Other Elements
</A>
61 <A href=
"#string">string
</A>
63 <A href=
"#primitive-value">primitive-value
</A>
65 <A href=
"#value">value
</A>
67 <A href=
"#type-tag">type-tag
</A>
69 <A href=
"#type-spec">type-spec
</A>
71 <A href=
"#method-call-flags">method-call-flags
</A>
73 <A href=
"#method-response-flags">method-response-flags
</A>
75 <A href=
"#return-type-tag">return-type-tag
</A>
77 <A href=
"#primitive-type-code">primitive-type-code
</A></LI></UL>
81 <P>This document describes the format used by the class BinaryFormatter to
82 serialize object graphs. The document is based on the analysis of the output of
83 the BinaryFormatter
of the Microsoft .NET runtime, so it is probably not
84 complete, since I cannot be sure that I have tested all cases. In fact, there
85 are some gaps in some tables of codes, so if you find a meaning for the missing
86 codes, please contact me and I'll update the document.
</P>
88 <H2>Format description
</H2>
89 <P>An object serialization is a sequence of binary elements.
A binary element
90 coluld be for example a description of an object, an array, an assembly, etc.
91 Each binary element has a specific format, which is described in the following
93 <P>This table shows the available binary elements:
</P>
95 <TABLE id=
"Table1" style=
"WIDTH: 560px; HEIGHT: 94px" cellSpacing=
"1" cellPadding=
"1" width=
"560" border=
"1">
97 <TD width=
"40"><STRONG>Code
</STRONG></TD>
98 <TD><STRONG>Label
</STRONG></TD>
99 <TD><STRONG>Description
</STRONG></TD>
102 <TD width=
"40">0</TD>
104 <TD>Allways written at the beggining of a serialization
</TD>
107 <TD width=
"40">1</TD>
108 <TD><A href=
"#elem1">RefTypeObject
</A></TD>
109 <TD>Object with no type metadata
</TD>
112 <TD width=
"40">4</TD>
113 <TD><A href=
"#elem4">RuntimeObject
</A></TD>
114 <TD>Corlib object
</TD>
117 <TD width=
"40">5</TD>
118 <TD><A href=
"#elem5">ExternalObject
</A></TD>
122 <TD width=
"40">6</TD>
123 <TD><A href=
"#elem6">String
</A></TD>
127 <TD width=
"40">7</TD>
128 <TD><A href=
"#elem7">GenericArray
</A></TD>
132 <TD width=
"40">8</TD>
133 <TD><A href=
"#elem8">BoxedPrimitiveTypeValue
</A></TD>
134 <TD>Primitive type value
</TD>
137 <TD width=
"40">9</TD>
138 <TD><A href=
"#elem9">ObjectReference
</A></TD>
139 <TD>Object reference
</TD>
142 <TD width=
"40">10</TD>
143 <TD><A href=
"#elem10">NullValue
</A></TD>
147 <TD width=
"40">11</TD>
148 <TD><A href=
"#elem11">End
</A></TD>
149 <TD>End of stream
</TD>
152 <TD width=
"40">12</TD>
153 <TD><A href=
"#elem12">Assembly
</A></TD>
154 <TD>Assembly declaration
</TD>
157 <TD width=
"40">13</TD>
158 <TD><A href=
"#elem13">ArrayFiller8b
</A></TD>
159 <TD>Null filler (
8 bit length)
</TD>
162 <TD width=
"40">14</TD>
163 <TD><A href=
"#elem14">ArrayFiller32b
</A></TD>
164 <TD>Null filler (
16 bit length)
</TD>
167 <TD width=
"40">15</TD>
168 <TD><A href=
"#elem15">ArrayOfPrimitiveType
</A></TD>
169 <TD>Array of primitive type
</TD>
172 <TD width=
"40">16</TD>
173 <TD><A href=
"#elem16">ArrayOfObject
</A></TD>
174 <TD>Array of Object
</TD>
177 <TD width=
"40">17</TD>
178 <TD><A href=
"#elem17">ArrayOfString
</A></TD>
179 <TD>Array of string
</TD>
182 <TD width=
"40">21</TD>
183 <TD><A href=
"#elem21">MethodCall
</A></TD>
187 <TD width=
"40">22</TD>
188 <TD><A href=
"#elem22">MethodResponse
</A></TD>
189 <TD>Method response
</TD>
193 <P>All elements begin with a byte that identifies the type of element. It is shown
194 in the
"Code" column. In the implementation of the formatter I use an enum to
195 represent those codes. The
"Label" column is the name of the corresponding enum
197 <a name=
"example"></a>
199 <P>The best way to underestand the format is to look at an example. Let's see how
200 the following structure of classes would be serialized:
</P>
201 <BLOCKQUOTE dir=
"ltr" style=
"MARGIN-RIGHT: 0px">
202 <P><FONT face=
"Courier New">class A
<BR>
204 B bval = new B();
<BR>
205 C cval = new C();
<BR>
206 string msg =
"hello";
<BR>
211 string str =
"bye";
<BR>
216 string[] info = new string[] {
"hello",
"world"}
<BR>
219 <P>The serialization of an instance of class A would result in a sequence of binary
220 elements like the following:
</P>
222 <TABLE id=
"Table35" cellSpacing=
"1" cellPadding=
"1" width=
"100%" border=
"1">
224 <TD vAlign=
"top" width=
"169"><STRONG>Element
</STRONG></TD>
225 <TD vAlign=
"top" width=
"40"><STRONG>Bytes
</STRONG></TD>
226 <TD vAlign=
"top" width=
"186"><STRONG>Data
</STRONG></TD>
227 <TD vAlign=
"top"><STRONG>Comments
</STRONG></TD>
230 <TD vAlign=
"top" width=
"169">Header
</TD>
231 <TD vAlign=
"top" width=
"40">0<BR>
235 <TD vAlign=
"top" width=
"186">Element code ?
</TD>
236 <TD vAlign=
"top">This sequence of bytes is serialized at the beginning. I'm sure it
237 has a meaning, but I don't know it.
</TD>
240 <TD vAlign=
"top" width=
"169"><A href=
"#elem12">Assembly
</A></TD>
241 <TD vAlign=
"top" width=
"40">1<BR>
244 <TD vAlign=
"top" width=
"186">Element code
<BR>
245 ID of the assembly (
1)
<BR>
246 Full name of the assembly
</TD>
248 <P>Before serializing an object, the assembly where the object is implemented has
249 to be serialized. The formatter assigns an ID to the assembly (ID
1 in this
250 case). This ID will by used to refer to this assembly.
</P>
254 <TD vAlign=
"top" width=
"169"><A href=
"#elem5">ExternalObject
</A></TD>
255 <TD vAlign=
"top" width=
"40">5<BR>
259 "bval",
"cval",
"msg"<BR>
266 <TD vAlign=
"top" width=
"186">Element code
<BR>
272 Class name of field
"bval"<BR>
273 Assembly ID of field
"bval"<BR>
274 Class name of field
"cval"<BR>
275 Assembly ID of field
"cval"<BR>
276 Assembly ID of this object
</TD>
277 <TD vAlign=
"top">Serialization of the root object. Each object has an ID that is
278 used, for example, to specify object relations. The object binary element has
279 two parts. The first one is type metadata: the name and type of serialized
280 fields. The second part is the object data: field values. The data part is
281 shown in the following nested elements.
</TD>
284 <TD vAlign=
"top" width=
"169"> <A href=
"#elem9">ObjectReference
</A></TD>
285 <TD vAlign=
"top" width=
"40">9<BR>
287 <TD vAlign=
"top" width=
"186">Element code
<BR>
288 ID of the referred object (
5)
</TD>
289 <TD vAlign=
"top">Reference objects are not serialized inside the container element.
290 Instead, an ObjectReference is serialized, and the object itself queued for
291 later serialization.
</TD>
294 <TD vAlign=
"top" width=
"169"> <A href=
"#elem5">ExternalObject
</A></TD>
295 <TD vAlign=
"top" width=
"40">5<BR>
302 <TD vAlign=
"top" width=
"186">Element code
<BR>
308 Assembly ID of this object
</TD>
309 <TD vAlign=
"top">On the other hand, value type objects are serialized inside the
310 container element.
</TD>
313 <TD vAlign=
"top" width=
"169">
314 <A href=
"#elem9">ObjectReference
</A></TD>
315 <TD vAlign=
"top" width=
"40">9<BR>
317 <TD vAlign=
"top" width=
"186">Element code
<BR>
318 ID of the referred object (
7)
</TD>
319 <TD vAlign=
"top">This is again a reference object, so it is serialized later.
</TD>
322 <TD vAlign=
"top" width=
"169"> <A href=
"#elem6">String
</A></TD>
323 <TD vAlign=
"top" width=
"40">6<BR>
326 <TD vAlign=
"top" width=
"186">Element code
<BR>
329 <TD vAlign=
"top">Strings are serialized like value objects
</TD>
332 <TD vAlign=
"top" width=
"169"><A href=
"#elem5">ExternalObject
</A></TD>
333 <TD vAlign=
"top" width=
"40">5<BR>
340 <TD vAlign=
"top" width=
"186">Element code
<BR>
346 Assembly ID of this object
</TD>
348 <P>Reference objects queued for serialization are serialized after the root object.
</P>
352 <TD vAlign=
"top" width=
"169"> <A href=
"#elem6">String
</A></TD>
353 <TD vAlign=
"top" width=
"40">6<BR>
356 <TD vAlign=
"top" width=
"186">Element code
<BR>
359 <TD vAlign=
"top">A string
</TD>
362 <TD vAlign=
"top" width=
"169"><A href=
"#elem17">ArrayOfString
</A></TD>
363 <TD vAlign=
"top" width=
"40">17<BR>
366 <TD vAlign=
"top" width=
"186">Element code
<BR>
369 <TD vAlign=
"top">This could be also encoded using the binary
element Array
370 (
7), but ArrayOfString is more specific and saves bytes.
</TD>
373 <TD vAlign=
"top" width=
"169"> <A href=
"#elem9">ObjectReference
</A></TD>
374 <TD vAlign=
"top" width=
"40">9<BR>
376 <TD vAlign=
"top" width=
"186">Element code
<BR>
377 ID of the referred object (
4)
</TD>
378 <TD vAlign=
"top">This string was already serialized. Use a backwards reference.
</TD>
381 <TD vAlign=
"top" width=
"169"> <A href=
"#elem6">String
</A></TD>
382 <TD vAlign=
"top" width=
"40">6<BR>
385 <TD vAlign=
"top" width=
"186">Element code
<BR>
388 <TD vAlign=
"top">Another string
</TD>
392 <a name=
"elements"></a>
393 <H2>Binary elements
</H2>
394 <P>The following sections show the format of each binary element. The format is
395 presented in a table with two columns. The first one shows the sequence of
396 bytes and the second one a description of each element in the sequence.
</P>
397 <P>A special notation is used to represent the bytes. Here are some examples:
</P>
399 <TABLE id=
"Table36" style=
"WIDTH: 448px; HEIGHT: 129px" cellSpacing=
"1" cellPadding=
"1" width=
"448" border=
"1">
401 <TD width=
"193"><STRONG>Example of element
</STRONG></TD>
402 <TD><STRONG>Description
</STRONG></TD>
405 <TD width=
"193">(byte)
7</TD>
406 <TD>A single byte
</TD>
409 <TD width=
"193">uint
</TD>
410 <TD>Any uint value (
4 bytes)
</TD>
413 <TD width=
"193"><EM><A href=
"#type-tag">type-tag
</A></EM></TD>
414 <TD>Names
in italic are described in the section
"Other elements"</TD>
417 <TD width=
"193"><EM><A href=
"#string">string
</A></EM> *
</TD>
418 <TD>* represents a sequence of elements
</TD>
421 <TD width=
"193">object
</TD>
422 <TD>Full serialization of an object
</TD>
427 <H3>1 - RefTypeObject
429 <P>An object is serialized in two parts. The first one is type metadata, and the
430 second one is the object data. When several objects of the same type are
431 serialized, only the first one has the metadata part. The other objects are
432 serialized using the RefTypeObject element, which instead of the metadata, it
433 includes an ID of an object that is of the same type as the one being
436 <TABLE id=
"Table2" style=
"WIDTH: 568px; HEIGHT: 75px" cellSpacing=
"1" cellPadding=
"1" width=
"568" border=
"1">
438 <TD width=
"142"><STRONG>Element
</STRONG></TD>
439 <TD><STRONG>Description
</STRONG></TD>
442 <TD width=
"142">(byte)
1</TD>
443 <TD>Element code
</TD>
446 <TD width=
"142">uint
</TD>
450 <TD width=
"142">uint
</TD>
451 <TD>ID of a previously serialized object from which to take type metadata.
</TD>
454 <TD width=
"142"><EM><A href=
"#value">value
</A> </EM>*
</TD>
455 <TD>Values of the fields of the object
</TD>
460 <H3>4 - RuntimeObject
</H3>
461 <P>This element is used to serialize objects of types that are implemented in the
462 core library of the framework. The only difference from the format for other
463 objects if that it does not include assembly information, which is not needed
464 since the assembly will always be mscorlib.
</P>
466 <TABLE id=
"Table21" style=
"WIDTH: 568px; HEIGHT: 75px" cellSpacing=
"1" cellPadding=
"1" width=
"568" border=
"1">
468 <TD width=
"142"><STRONG>Element
</STRONG></TD>
469 <TD><STRONG>Description
</STRONG></TD>
472 <TD width=
"142">(byte)
4</TD>
473 <TD>Element code
</TD>
476 <TD width=
"142">uint
</TD>
480 <TD width=
"142"><EM><A href=
"#string">string
</A></EM></TD>
481 <TD>Class name, including namespace
</TD>
484 <TD width=
"142">uint
</TD>
485 <TD>Number of serialized fields
</TD>
488 <TD width=
"142"><EM><A href=
"#string">string
</A> </EM>*
</TD>
489 <TD>Names of the fields
</TD>
492 <TD width=
"142"><EM><A href=
"#type-tag">type-tag
</A> *
</EM></TD>
493 <TD>type-tag of each field
</TD>
496 <TD width=
"142"><EM><A href=
"#type-spec">type-spec
</A> *
</EM></TD>
497 <TD>type-spec of each field
</TD>
500 <TD width=
"142"><EM><A href=
"#value">value
</A> *
</EM></TD>
501 <TD>Values of the fields of the object
</TD>
506 <H3>5 - ExternalObject
</H3>
507 <P>This element can be used to serialize any object from any assembly.
</P>
509 <TABLE id=
"Table22" style=
"WIDTH: 568px; HEIGHT: 75px" cellSpacing=
"1" cellPadding=
"1" width=
"568" border=
"1">
511 <TD width=
"142"><STRONG>Element
</STRONG></TD>
512 <TD><STRONG>Description
</STRONG></TD>
515 <TD width=
"142">(byte)
5</TD>
516 <TD>Element code
</TD>
519 <TD width=
"142">uint
</TD>
523 <TD width=
"142"><EM><A href=
"#string">string
</A></EM></TD>
524 <TD>Class name, including namespace
</TD>
527 <TD width=
"142">uint
</TD>
528 <TD>Number of serialized fields
</TD>
531 <TD width=
"142"><EM><A href=
"#string">string
</A> </EM>*
</TD>
532 <TD>Names of the fields
</TD>
535 <TD width=
"142"><EM><A href=
"#type-tag">type-tag
</A> </EM>*
</TD>
536 <TD>type-tag of each field
</TD>
539 <TD width=
"142"><EM><A href=
"#type-spec">type-spec
</A> </EM>*
</TD>
540 <TD>type-spec of each field
</TD>
543 <TD width=
"142">uint
</TD>
544 <TD>ID of the assembly where the class is defined (the assembly must have been
545 serialized before the class using the binary element
12)
</TD>
548 <TD width=
"142"><EM><A href=
"#value">value
</A> </EM>*
</TD>
549 <TD>Values of the fields of the object
</TD>
555 <P>A string value.
</P>
557 <TABLE id=
"Table23" style=
"WIDTH: 568px; HEIGHT: 75px" cellSpacing=
"1" cellPadding=
"1" width=
"568" border=
"1">
559 <TD width=
"142"><STRONG>Element
</STRONG></TD>
560 <TD><STRONG>Description
</STRONG></TD>
563 <TD width=
"142">(byte)
6</TD>
564 <TD>Element code
</TD>
567 <TD width=
"142">uint
</TD>
571 <TD width=
"142"><EM><A href=
"#string">string
</A></EM></TD>
572 <TD>Value of the string
</TD>
577 <H3>7 - GenericArray
</H3>
578 <P>This element can be used to represent any array.
</P>
580 <TABLE id=
"Table24" style=
"WIDTH: 568px; HEIGHT: 75px" cellSpacing=
"1" cellPadding=
"1" width=
"568" border=
"1">
582 <TD width=
"142"><STRONG>Element
</STRONG></TD>
583 <TD><STRONG>Description
</STRONG></TD>
586 <TD width=
"142">(byte)
7</TD>
587 <TD>Element code
</TD>
590 <TD width=
"142">uint
</TD>
594 <TD width=
"142">byte
</TD>
595 <TD>Array type:
0:single dimension,
1: jagged,
2: multi-dimensional
</TD>
598 <TD width=
"142">uint
</TD>
599 <TD>Number of dimensions (rank)
</TD>
602 <TD width=
"142">uint *
</TD>
603 <TD>Number of
elements for each dimension
</TD>
606 <TD width=
"142"><EM><A href=
"#type-tag">type-tag
</A></EM></TD>
607 <TD>type-tag of array's
element type
</TD>
610 <TD width=
"142"><EM><A href=
"#type-spec">type-spec
</A></EM></TD>
611 <TD>type-spec of array's
element type
</TD>
614 <TD width=
"142"><EM><A href=
"#value">value
</A> *
</EM></TD>
615 <TD>Values of the elements, row by row
</TD>
620 <H3>8 - BoxedPrimitiveTypeValue
</H3>
621 <P>This element represents a primitive type value boxed as an object.
</P>
623 <TABLE id=
"Table25" style=
"WIDTH: 568px; HEIGHT: 75px" cellSpacing=
"1" cellPadding=
"1" width=
"568" border=
"1">
625 <TD width=
"142"><STRONG>Element
</STRONG></TD>
626 <TD><STRONG>Description
</STRONG></TD>
629 <TD width=
"142">(byte)
8</TD>
630 <TD>Element code
</TD>
633 <TD width=
"142"><EM><A href=
"#type-spec">type-spec
</A></EM></TD>
634 <TD>type-spec of the primitive type
</TD>
637 <TD width=
"142"><EM><A href=
"#primitive-value">primitive-value
</A></EM></TD>
643 <H3>9 - ObjectReference
</H3>
644 <P>This element represents a reference to an object already serialized (backwards
645 reference) or that will be serialized later (forward reference).
648 <TABLE id=
"Table26" style=
"WIDTH: 568px; HEIGHT: 16px" cellSpacing=
"1" cellPadding=
"1" width=
"568" border=
"1">
650 <TD width=
"142"><STRONG>Element
</STRONG></TD>
651 <TD><STRONG>Description
</STRONG></TD>
654 <TD width=
"142">(byte)
9</TD>
655 <TD>Element code
</TD>
658 <TD width=
"142">uint
</TD>
659 <TD>ID of the referred object
</TD>
663 <a name=
"elem10"></a>
664 <H3>10 - NullValue
</H3>
665 <P>A
null value.
</P>
666 <TABLE id=
"Table27" style=
"WIDTH: 568px; HEIGHT: 16px" cellSpacing=
"1" cellPadding=
"1" width=
"568" border=
"1">
668 <TD width=
"142"><STRONG>Element
</STRONG></TD>
669 <TD><STRONG>Description
</STRONG></TD>
672 <TD width=
"142">(byte)
10</TD>
673 <TD>Element code
</TD>
677 <a name=
"elem11"></a>
681 <P>This element marks the end of the serialized object graph.
</P>
682 <TABLE id=
"Table28" style=
"WIDTH: 568px; HEIGHT: 16px" cellSpacing=
"1" cellPadding=
"1" width=
"568" border=
"1">
684 <TD width=
"142"><STRONG>Element
</STRONG></TD>
685 <TD><STRONG>Description
</STRONG></TD>
688 <TD width=
"142">(byte)
11</TD>
689 <TD>Element code
</TD>
692 <a name=
"elem12"></a>
696 <P>Defines an assembly. Each assembly is defined only once and has an ID. This ID
697 is used when serializing an object (element
5) to specify the assembly where
698 object's type is implemented.
</P>
699 <TABLE id=
"Table29" style=
"WIDTH: 568px; HEIGHT: 16px" cellSpacing=
"1" cellPadding=
"1" width=
"568" border=
"1">
701 <TD width=
"142"><STRONG>Element
</STRONG></TD>
702 <TD><STRONG>Description
</STRONG></TD>
705 <TD width=
"142">(byte)
12</TD>
706 <TD>Element code
</TD>
709 <TD width=
"142">uint
</TD>
713 <TD width=
"142"><EM><A href=
"#string">string
</A></EM></TD>
714 <TD>Full name of the assembly
</TD>
717 <a name=
"elem13"></a>
719 <P>13 - ArrayFiller8b
</P>
721 <P>This element can be used when serializing array data to specify multiple
722 consecutive null values. It it only used in single dimension arrays of
723 reference objects (not valid for value-type objects).
</P>
724 <TABLE id=
"Table30" style=
"WIDTH: 568px; HEIGHT: 16px" cellSpacing=
"1" cellPadding=
"1" width=
"568" border=
"1">
726 <TD width=
"142"><STRONG>Element
</STRONG></TD>
727 <TD><STRONG>Description
</STRONG></TD>
730 <TD width=
"142">(byte)
13</TD>
731 <TD>Element code
</TD>
734 <TD width=
"142">byte
</TD>
735 <TD>Number of consecutive null values
</TD>
739 <a name=
"elem14"></a>
741 <P>14 - ArrayFiller32b
</P>
743 <P>The same as ArrayFiller8b, but it uses a uint to specify the length.
</P>
744 <TABLE id=
"Table31" style=
"WIDTH: 568px; HEIGHT: 16px" cellSpacing=
"1" cellPadding=
"1" width=
"568" border=
"1">
746 <TD width=
"142"><STRONG>Element
</STRONG></TD>
747 <TD><STRONG>Description
</STRONG></TD>
750 <TD width=
"142">(byte)
14</TD>
751 <TD>Element code
</TD>
754 <TD width=
"142">uint
</TD>
755 <TD>Number of consecutive null values
</TD>
759 <a name=
"elem15"></a>
761 <P>15 - ArrayOfPrimitiveType
</P>
763 <P>This element can be used to represent a single dimension array of primitive type
766 <TABLE id=
"Table32" style=
"WIDTH: 568px; HEIGHT: 75px" cellSpacing=
"1" cellPadding=
"1" width=
"568" border=
"1">
768 <TD width=
"142"><STRONG>Element
</STRONG></TD>
769 <TD><STRONG>Description
</STRONG></TD>
772 <TD width=
"142">(byte)
15</TD>
773 <TD>Element code
</TD>
776 <TD width=
"142">uint
</TD>
780 <TD width=
"142">uint
</TD>
781 <TD>Number of
elements
</TD>
784 <TD width=
"142"><EM><A href=
"#type-spec">type-spec
</A></EM></TD>
785 <TD>type-spec of array's
element type
</TD>
788 <TD width=
"142"><EM><A href=
"#primitive-value">primitie-value
</A> *
</EM></TD>
789 <TD>Values of the elements
</TD>
793 <a name=
"elem16"></a>
794 <H3>16 - ArrayOfObject
</H3>
795 <P>This element can be used to represent a single dimension array of Object (i.e.
798 <TABLE id=
"Table33" style=
"WIDTH: 568px; HEIGHT: 75px" cellSpacing=
"1" cellPadding=
"1" width=
"568" border=
"1">
800 <TD width=
"142"><STRONG>Element
</STRONG></TD>
801 <TD><STRONG>Description
</STRONG></TD>
804 <TD width=
"142">(byte)
16</TD>
805 <TD>Element code
</TD>
808 <TD width=
"142">uint
</TD>
812 <TD width=
"142">uint
</TD>
813 <TD>Number of
elements
</TD>
816 <TD width=
"142">object *
</TD>
817 <TD>Values of the elements
</TD>
821 <a name=
"elem17"></a>
822 <H3>17 - ArrayOfString
</H3>
823 <P>This element can be used to represent a single dimension array of
String
824 (i.e. an string[] ).
</P>
826 <TABLE id=
"Table34" style=
"WIDTH: 568px; HEIGHT: 75px" cellSpacing=
"1" cellPadding=
"1" width=
"568" border=
"1">
828 <TD width=
"142"><STRONG>Element
</STRONG></TD>
829 <TD><STRONG>Description
</STRONG></TD>
832 <TD width=
"142">(byte)
17</TD>
833 <TD>Element code
</TD>
836 <TD width=
"142">uint
</TD>
840 <TD width=
"142">uint
</TD>
841 <TD>Number of
elements
</TD>
844 <TD width=
"142">object *
</TD>
845 <TD>Values of the elements
</TD>
849 <a name=
"elem21"></a>
850 <H3>21 Method call
</H3>
851 <P>Represents a method call. The format of a method call can vary depending on the
852 type of the parameters.
The following
table shows the common format:
</P>
854 <TABLE id=
"Table20" style=
"WIDTH: 568px; HEIGHT: 75px" cellSpacing=
"1" cellPadding=
"1" width=
"568" border=
"1">
856 <TD width=
"142"><STRONG>Element
</STRONG></TD>
857 <TD><STRONG>Description
</STRONG></TD>
860 <TD width=
"142">(byte)
21</TD>
861 <TD>Element code
</TD>
864 <TD width=
"142"><EM><A href=
"#method-call-flags">method-call-flags
</A></EM></TD>
865 <TD>Describes wich information includes the method call
</TD>
868 <TD width=
"142">(byte)
0,
0,
0</TD>
872 <TD width=
"142"><EM><EM><A href=
"#type-spec">type-spec
</A><BR>
873 <EM><A href=
"#primitive-value">primitive-value
</A></EM></EM></EM></TD>
877 <TD width=
"142"><EM><EM><EM><A href=
"#type-spec">type-spec
</A><BR>
878 <EM><A href=
"#primitive-value">primitive-value
</A></EM></EM></EM></EM></TD>
879 <TD>Class name (including namespace and assembly)
</TD>
883 <P>The following tables describe the format of the message content depending on the
884 value of method-call-flags:
</P>
885 <H4>method-call-flags
& NoArguments
</H4>
886 <P>Used for calls to methods without parameters.
</P>
888 <TABLE id=
"Table8" style=
"WIDTH: 568px; HEIGHT: 75px" cellSpacing=
"1" cellPadding=
"1" width=
"568" border=
"1">
890 <TD width=
"119"><STRONG>Element
</STRONG></TD>
891 <TD><STRONG>Description
</STRONG></TD>
894 <TD width=
"119">Header[]
</TD>
895 <TD>Only if there are Headers and method-call-flags has the flag
<EM>IncludeLogicalCallContext.
896 </EM>Headers are serialized only if there is context info. This must be a bug
900 <TD width=
"119">object[]
</TD>
902 <P>Array with the following values:
</P>
905 Method signature, only if method-call-flags has the flag IncludesSignature. It
908 LogicalCallContext instance, only if method-call-flags has the flag
909 IncludesLogicalCallContext.
</LI></UL>
910 <P>If the array is empty, it is not serialized.
</P>
915 <H4>method-call-flags
& PrimitiveArguments
</H4>
916 <P>Used for calls to methods in which all parameters are primitive types.
</P>
918 <TABLE id=
"Table5" style=
"WIDTH: 568px; HEIGHT: 75px" cellSpacing=
"1" cellPadding=
"1" width=
"568" border=
"1">
920 <TD width=
"119"><STRONG>Element
</STRONG></TD>
921 <TD><STRONG>Description
</STRONG></TD>
924 <TD width=
"119">uint
</TD>
925 <TD>Number of parameters
</TD>
928 <TD width=
"119"><EM><EM><EM><EM>(
<A href=
"#type-spec">type-spec
</A></EM></EM></EM><BR>
929 <A href=
"#primitive-value">primitive-value
</A> ) *
</EM></TD>
930 <TD>One value for each parameter
</TD>
933 <TD width=
"119">Header[]
</TD>
934 <TD>Only if there are Headers and method-response-flags has the flag
<EM>IncludeLogicalCallContext.
935 </EM>Headers are serialized only if there is context info. This must be a bug
939 <TD width=
"119">object[]
</TD>
941 <P>Array with the following values:
</P>
944 Method signature, only if method-call-flags has the flag IncludesSignature. It
947 LogicalCallContext instance, only if method-call-flags has the flag
948 IncludesLogicalCallContext.
</LI></UL>
949 <P>If the array is empty, it is not serialized.
</P>
954 <H4>method-call-flags
& ArgumentsInSimpleArray
</H4>
955 <P>Used for calls to methods in which at least one parameter is not a primitive
956 type, and when no other info needs to be serialized (i.e. context or
959 <TABLE id=
"Table6" style=
"WIDTH: 568px; HEIGHT: 75px" cellSpacing=
"1" cellPadding=
"1" width=
"568" border=
"1">
961 <TD width=
"119"><STRONG>Element
</STRONG></TD>
962 <TD><STRONG>Description
</STRONG></TD>
965 <TD width=
"119">Header[]
</TD>
966 <TD>Only if there are Headers.
</TD>
969 <TD width=
"119">object[]
</TD>
971 <P>Array of parameters.
976 <H4>method-call-flags
& ArgumentsInMultiArray
</H4>
977 <P>Used for calls to methods in which at least one parameter is not a primitive
978 type, and when other info needs to be serialized (i.e. context or signature).
</P>
980 <TABLE id=
"Table7" style=
"WIDTH: 568px; HEIGHT: 75px" cellSpacing=
"1" cellPadding=
"1" width=
"568" border=
"1">
982 <TD width=
"119"><STRONG>Element
</STRONG></TD>
983 <TD><STRONG>Description
</STRONG></TD>
986 <TD width=
"119">Header[]
</TD>
987 <TD>Only if there are Headers.
</TD>
990 <TD width=
"119">object[]
</TD>
993 Array with the following values:
</P>
998 Method signature, only if method-call-flags has the flag IncludesSignature. It
1001 LogicalCallContext instance, only if method-call-flags has the flag
1002 IncludesLogicalCallContext.
</LI></UL>
1004 If the array is empty, it is not serialized.
</P>
1009 </TD></TR></TBODY></TABLE> <a name=
"elem22"></a>
1010 <H3>22 Method Response
</H3>
1011 <P>Represents a method response. The format of a method response can vary depending
1012 on the type of the return value and parameters.
The following
table
1013 shows the common format:
</P>
1015 <TABLE id=
"Table9" style=
"WIDTH: 568px; HEIGHT: 140px" cellSpacing=
"1" cellPadding=
"1" width=
"568" border=
"1">
1017 <TD width=
"142"><STRONG>Element
</STRONG></TD>
1018 <TD><STRONG>Description
</STRONG></TD>
1021 <TD width=
"142" height=
"25">(byte)
22</TD>
1022 <TD height=
"25">Element code
</TD>
1025 <TD width=
"142"><EM><A href=
"#method-response-flags">method-response-flags
</A></EM></TD>
1026 <TD>Describes which information includes the method call
</TD>
1029 <TD width=
"142"><EM><A href=
"#return-type-tag">return-type-tag
</A></EM></TD>
1030 <TD>Describes which kind of value is returned
</TD>
1033 <TD width=
"142">(bytes)
0,
0</TD>
1038 <P>The following tables describe the format of the message content depending on the
1039 value of method-response-flags:
</P>
1040 <H4>method-response-flags
& NoArguments
</H4>
1041 <P>Used when the method has no out arguments.
</P>
1043 <TABLE id=
"Table10" style=
"WIDTH: 568px; HEIGHT: 75px" cellSpacing=
"1" cellPadding=
"1" width=
"568" border=
"1">
1045 <TD width=
"139"><STRONG>Element
</STRONG></TD>
1046 <TD><STRONG>Description
</STRONG></TD>
1049 <TD width=
"139"><EM><EM><EM><A href=
"#type-spec">type-spec
</A><BR>
1050 <EM><A href=
"#primitive-value">primitive-value
</A></EM></EM></EM></EM></TD>
1052 <P><EM>Only if return-type-tag was PrimitiveType.
<BR>
1053 </EM>Return value.
</P>
1057 <TD width=
"139">Header[]
</TD>
1058 <TD>Only if there are Headers.
</TD>
1061 <TD width=
"139">object[]
</TD>
1063 <P>Array with the following values:
</P>
1066 Return value, only
if
<EM>return-type-tag
</EM> was
<EM>ObjectType
</EM>
1068 LogicalCallContext instance, only
if method-response-flags has the flag
1069 IncludeLogicalCallContext
</LI></UL>
1070 <P>If the array is empty, it is not serialized.
</P>
1075 <H4>method-response-flags
& PrimitiveArguments
</H4>
1076 <P>Used when all out arguments are primitive types.
</P>
1078 <TABLE id=
"Table12" style=
"WIDTH: 568px; HEIGHT: 75px" cellSpacing=
"1" cellPadding=
"1" width=
"568" border=
"1">
1080 <TD width=
"139"><STRONG>Element
</STRONG></TD>
1081 <TD><STRONG>Description
</STRONG></TD>
1084 <TD width=
"139"><EM><EM><EM><A href=
"#type-spec">type-spec
</A><BR>
1085 <EM><A href=
"#primitive-value">primitive-value
</A></EM></EM></EM></EM></TD>
1087 <P><EM>Only if return-type-tag was PrimitiveType.
<BR>
1088 </EM>Return value.
</P>
1092 <TD width=
"139">uint
</TD>
1093 <TD>Number of out arguments
</TD>
1096 <TD width=
"139"><EM><EM><EM>(
<A href=
"#type-spec">type-spec
</A>
1098 <EM><A href=
"#primitive-value">primitive-value
</A> )
</EM></EM></EM> *
</EM></TD>
1099 <TD>One value for each argument
</TD>
1102 <TD width=
"139">Header[]
</TD>
1103 <TD>Only if there are Headers. Empty otherwise.
</TD>
1106 <TD width=
"139">object[]
</TD>
1108 <P>Array with the following values:
</P>
1111 Return value, only
if
<EM>return-type-tag
</EM> was
<EM>ObjectType
</EM>
1113 LogicalCallContext instance, only
if method-response-flags has the flag
1114 IncludeLogicalCallContext
</LI></UL>
1115 <P>If the array is empty, it is not serialized.
</P>
1120 <H4>method-response-flags
& ArgumentsInSimpleArray
</H4>
1121 <P>Used when at least one out argument is not a primitive type, return type is
1122 primitive, and no other info needs to be serialized.
</P>
1124 <TABLE id=
"Table13" style=
"WIDTH: 568px; HEIGHT: 75px" cellSpacing=
"1" cellPadding=
"1" width=
"568" border=
"1">
1126 <TD width=
"140"><STRONG>Element
</STRONG></TD>
1127 <TD><STRONG>Description
</STRONG></TD>
1130 <TD width=
"140"><EM><EM><EM><A href=
"#type-spec">type-spec
</A><BR>
1131 <EM><A href=
"#primitive-value">primitive-value
</A></EM></EM></EM></EM></TD>
1133 <P><EM>Only if return-type-tag was PrimitiveType.
<BR>
1134 </EM>Return value.
</P>
1138 <TD width=
"140">Header[]
</TD>
1139 <TD>Only if there are Headers.
</TD>
1142 <TD width=
"140">object[]
</TD>
1143 <TD>Array that contains the out arguments
</TD>
1147 <H4>method-response-flags
& ArgumentsInMultiArray
</H4>
1148 <P>Used when at least one out argument is not a primitive type, return type is not
1149 primitive, and no other info needs to be serialized.
</P>
1151 <TABLE id=
"Table14" style=
"WIDTH: 568px; HEIGHT: 75px" cellSpacing=
"1" cellPadding=
"1" width=
"568" border=
"1">
1153 <TD width=
"141"><STRONG>Element
</STRONG></TD>
1154 <TD><STRONG>Description
</STRONG></TD>
1157 <TD width=
"141"><EM><EM><EM><A href=
"#type-spec">type-spec
</A><BR>
1158 <EM><A href=
"#primitive-value">primitive-value
</A></EM></EM></EM></EM></TD>
1160 <P>Only if
<EM>return-type-tag
</EM>was
<EM>PrimitiveType.
<BR>
1161 </EM>Return value.
</P>
1165 <TD width=
"141">Header[]
</TD>
1166 <TD>Only if there are Headers
</TD>
1169 <TD width=
"141">object[]
</TD>
1171 <P>Array with the following values:
</P>
1174 Array of out arguments.
1176 Return value, only
if
<EM>return-type-tag
</EM> was
<EM>ObjectType
</EM>
1178 LogicalCallContext instance, only
if method-response-flags has the flag
1179 IncludeLogicalCallContext
</LI></UL>
1184 <a name=
"other"></a>
1185 <H2>Other elements
</H2>
1186 <a name=
"string"></a>
1188 <P>A string value, serialized using BinaryWriter. It serializes the length of the
1189 string,
using a
7-bit encoded int, and then the string chars.
</P>
1190 <a name=
"primitive-value"></a>
1191 <H3>primitive-value
</H3>
1192 <P>A primitive value. It can be serialized using BinaryWriter and deserialized
1193 using BinaryReader. DateTime is serialized as a long (using the Ticks
1196 <a name=
"value"></a>
1198 <P>It can be a
<A href=
"#primitive-value">primitive-value
</A> or any of the
1199 following binary elements:
</P>
1202 <A href=
"#elem1">1 - RefTypeObject
</A>
1203 (only for value types)
1205 <A href=
"#elem4">4 - RuntimeObject
</A>
1206 (only for value types)
1208 <A href=
"#elem5">5 - ExternalObject
</A> (only for value types)
1210 <A href=
"#elem6">6 - String
</A>
1212 <A href=
"#elem8">8 - BoxedPrimitiveTypeValue
</A>
1214 <A href=
"#elem9">9 - ObjectReference
</A>
1216 <A href=
"#elem10">10 - NullValue
</A>
1218 <A href=
"#elem13">13 - ArrayFiller8b
</A> (only inside
1219 single-dimensional object arrays)
1221 <A href=
"#elem14">14 - ArrayFiller32b
</A> (only inside single-dimensional
1222 object arrays)
</LI></UL>
1223 <a name=
"type-tag"></a>
1225 <P>Together with a
<A href=
"#type-spec">type-spec
</A> value, identifies a type.
1226 Some types can be represented using several type-tags. In this case, the most
1227 specific type-tag is allways used (it will
take less bytes).
</P>
1228 <P>type-tag can be one of the following:
</P>
1230 <TABLE id=
"Table18" cellSpacing=
"1" cellPadding=
"1" width=
"600" border=
"1">
1232 <TD><STRONG>Value
</STRONG></TD>
1233 <TD><STRONG>Label
</STRONG></TD>
1234 <TD><STRONG>Description
</STRONG></TD>
1235 <TD><STRONG>type-spec needed
</STRONG></TD>
1239 <TD>PrimitiveType
</TD>
1240 <TD>A primitive type
</TD>
1241 <TD>The code of the primitive type
</TD>
1246 <TD>String class. type-spec is not needed.
</TD>
1252 <TD>Object class. type-spec is not needed.
</TD>
1256 <TD height=
"20">3</TD>
1257 <TD height=
"20">RuntimeType
</TD>
1258 <TD height=
"20">A type from the .NET runtime (including arrays of .NET types)
</TD>
1259 <TD height=
"20">The name of the class
</TD>
1263 <TD>GenericType
</TD>
1264 <TD>Any other
type (including arrays)
</TD>
1265 <TD>The name of the class and the id of the assembly
</TD>
1269 <TD>ArrayOfObject
</TD>
1270 <TD>Array of class Object
</TD>
1275 <TD>ArrayOfString
</TD>
1276 <TD>Array of class String
</TD>
1281 <TD>ArrayOfPrimitiveType
</TD>
1282 <TD>Array of primitive type
</TD>
1283 <TD>The code of the primitive type
</TD>
1287 <a name=
"type-spec"></a>
1289 <P>It is the name or the code of a type. To decode it, a
<A href=
"#type-tag">type-tag
</A>
1290 value is needed. The following tables shows the format of type-spec for each
1292 <H4>type-tag = PrimitiveType or ArrayOfPrimitiveType
</H4>
1294 <TABLE id=
"Table16" style=
"WIDTH: 560px; HEIGHT: 14px" cellSpacing=
"1" cellPadding=
"1" width=
"560" border=
"1">
1296 <TD width=
"119"><STRONG>Element
</STRONG></TD>
1297 <TD><STRONG>Description
</STRONG></TD>
1300 <TD width=
"119"><A href=
"#primitive-type-code">primitive-type-code
</A></TD>
1302 The code of the primitive type
</TD>
1306 <H4>type-tag = RuntimeType
</H4>
1308 <TABLE id=
"Table15" style=
"WIDTH: 560px; HEIGHT: 14px" cellSpacing=
"1" cellPadding=
"1" width=
"560" border=
"1">
1310 <TD><STRONG><STRONG>Element
</STRONG></STRONG></TD>
1311 <TD><STRONG><STRONG>Description
</STRONG></STRONG></TD>
1314 <TD><EM><A href=
"#string">string
</A></EM></TD>
1315 <TD>The name of the class, including the namespace
</TD>
1318 <H4>type-tag = GenericType
</H4>
1320 <TABLE id=
"Table17" style=
"WIDTH: 560px; HEIGHT: 14px" cellSpacing=
"1" cellPadding=
"1" width=
"560" border=
"1">
1322 <TD><STRONG>Element
</STRONG></TD>
1323 <TD><STRONG><STRONG>Description
</STRONG></STRONG></TD>
1326 <TD><EM><A href=
"#string">string
</A></EM></TD>
1327 <TD>The name of the class, including the namespace
</TD>
1331 <TD>Id of the assembly where the class is defined
</TD>
1335 <H4>Other type-tag
</H4>
1337 <P>For other type-tag values, no type-spec is needed.
</P>
1338 <a name=
"method-call-flags"></a>
1339 <H3>method-call-flags
</H3>
1341 <TABLE id=
"Table3" cellSpacing=
"1" cellPadding=
"1" width=
"600" border=
"1">
1343 <TD><STRONG>Value
</STRONG></TD>
1344 <TD><STRONG>Label
</STRONG></TD>
1345 <TD><STRONG>Description
</STRONG></TD>
1349 <TD>NoArguments
</TD>
1350 <TD>No arguments included
</TD>
1354 <TD>PrimitiveArguments
</TD>
1355 <TD>Primitive type arguments
</TD>
1359 <TD>ArgumentsInSimpleArray
</TD>
1360 <TD>At least one out argument is not from a primitive type
</TD>
1363 <TD height=
"20">8</TD>
1364 <TD height=
"20">ArgumentsInMultiArray
</TD>
1365 <TD height=
"20">At least one out argument is not from a primitive type and other
1366 info is included in the message (context or signature)
</TD>
1370 <TD>ExcludeLogicalCallContext
</TD>
1371 <TD>LogicalContext not included
</TD>
1380 <TD>IncludesLogicalCallContext
</TD>
1381 <TD>LogicalContext included
</TD>
1385 <TD>IncludesSignature
</TD>
1386 <TD>Signature is included in the message. It is only included when calling an
1387 overloaded method.
</TD>
1391 <a name=
"method-response-flags"></a>
1392 <H3>method-response-flags
</H3>
1394 <TABLE id=
"Table4" cellSpacing=
"1" cellPadding=
"1" width=
"600" border=
"1">
1396 <TD><STRONG>Value
</STRONG></TD>
1397 <TD width=
"190"><STRONG>Label
</STRONG></TD>
1398 <TD><STRONG>Description
</STRONG></TD>
1402 <TD width=
"190">NoArguments
</TD>
1403 <TD>Response with no out arguments
</TD>
1407 <TD width=
"190">PrimitiveArguments
</TD>
1409 Response with primitive type out arguments
</TD>
1413 <TD width=
"190">ArgumentsInSimpleArray
</TD>
1414 <TD>Response with primitive type return value, and with at least one out argument
1415 that is not a primitive type.
</TD>
1419 <TD width=
"190">ArgumentsInMultiArray
</TD>
1420 <TD>Response with at least one out argument that is not a primitive type, and other
1421 info is included in the message (context or signature)
</TD>
1425 <TD width=
"190">ExcludeLogicalCallContext
</TD>
1426 <TD>LogicalContext not included
</TD>
1430 <TD width=
"190"></TD>
1435 <TD width=
"190">IncludesLogicalCallContext
</TD>
1436 <TD>LogicalContext included
</TD>
1440 <a name=
"return-type-tag"></a>
1441 <H3>return-type-tag
</H3>
1443 <TABLE id=
"Table11" cellSpacing=
"1" cellPadding=
"1" width=
"600" border=
"1">
1445 <TD><STRONG>Value
</STRONG></TD>
1446 <TD><STRONG>Label
</STRONG></TD>
1447 <TD><STRONG>Description
</STRONG></TD>
1452 <TD>Null return value
</TD>
1456 <TD>PrimitiveType
</TD>
1457 <TD>Primitive type return value
</TD>
1462 <TD>Object instance return value
</TD>
1467 <TD>Method response is an exception
</TD>
1471 <a name=
"primitive-type-code"></a>
1472 <H3>primitive-type-code
</H3>
1474 <TABLE id=
"Table19" height=
"171" cellSpacing=
"1" cellPadding=
"1" width=
"320" border=
"1">
1476 <TD width=
"45"><STRONG>Value
</STRONG></TD>
1477 <TD width=
"190"><STRONG>Label
</STRONG></TD>
1480 <TD width=
"45">1</TD>
1481 <TD width=
"190">Boolean
1485 <TD width=
"45">2</TD>
1486 <TD width=
"190">Byte
</TD>
1489 <TD width=
"45">3</TD>
1490 <TD width=
"190">Char
</TD>
1493 <TD width=
"45">5</TD>
1494 <TD width=
"190">Decimal
</TD>
1497 <TD width=
"45">6</TD>
1498 <TD width=
"190">Double
</TD>
1501 <TD width=
"45">7</TD>
1502 <TD width=
"190">Int16
</TD>
1505 <TD width=
"45">8</TD>
1506 <TD width=
"190">Int32
</TD>
1509 <TD width=
"45">9</TD>
1510 <TD width=
"190">Int64
</TD>
1513 <TD width=
"45">10</TD>
1514 <TD width=
"190">SByte
</TD>
1517 <TD width=
"45">11</TD>
1518 <TD width=
"190">Single
</TD>
1521 <TD width=
"45">13</TD>
1522 <TD width=
"190">DateTime
</TD>
1525 <TD width=
"45">14</TD>
1526 <TD width=
"190">UInt16
</TD>
1529 <TD width=
"45">15</TD>
1530 <TD width=
"190">UInt32
</TD>
1533 <TD width=
"45">16</TD>
1534 <TD width=
"190">UInt64
</TD>
1537 <TD width=
"45">18</TD>
1538 <TD width=
"190">String
</TD>
1542 <HR width=
"100%" SIZE=
"1">
1543 <FONT size=
"1">2003 (C) Lluis Sanchez Gual
(
</FONT> <A href=
"mailto:lluis@ideary.com">
1544 <FONT size=
"1">lluis@ideary.com
</FONT></A><FONT size=
"1">)
</FONT>